方便自定义命令处理

This commit is contained in:
John Smith
2019-03-23 23:58:02 +08:00
parent 79e7406e07
commit 3933226485
2 changed files with 56 additions and 26 deletions

View File

@@ -6,12 +6,21 @@ from blivedm import BLiveClient
class MyBLiveClient(BLiveClient):
# 演示如何自定义handler
_COMMAND_HANDLERS = BLiveClient._COMMAND_HANDLERS.copy()
_COMMAND_HANDLERS['SEND_GIFT'] = lambda client, command: client._my_on_gift(
command['data']['giftName'], command['data']['num'], command['data']['uname'],
command['data']['coin_type'], command['data']['total_coin']
)
async def _on_get_popularity(self, popularity):
print('当前人气值:', popularity)
print(f'当前人气值:{popularity}')
async def _on_get_danmaku(self, content, user_name):
print(user_name, '', content)
print(f'{user_name}{content}')
async def _my_on_gift(self, gift_name, gift_num, user_name, coin_type, total_coin):
print(f'{user_name} 赠送{gift_name}x{gift_num} {coin_type}币x{total_coin}')
async def async_main():