From 8d40f9f9e5132f47d5a92e20343d63398c4b00ab Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 12 Jan 2020 23:02:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/layout/index.vue | 2 +- update.py | 2 +- views/chat.py | 102 ++++++++++++++++------------------ 3 files changed, 51 insertions(+), 55 deletions(-) diff --git a/frontend/src/layout/index.vue b/frontend/src/layout/index.vue index d1dda11..42a7801 100644 --- a/frontend/src/layout/index.vue +++ b/frontend/src/layout/index.vue @@ -9,7 +9,7 @@
- v1.2.3 + v1.2.4
diff --git a/update.py b/update.py index 6bcb63e..192175f 100644 --- a/update.py +++ b/update.py @@ -2,7 +2,7 @@ import aiohttp -VERSION = 'v1.2.3' +VERSION = 'v1.2.4' async def check_update(): diff --git a/views/chat.py b/views/chat.py index 6583c87..e767f77 100644 --- a/views/chat.py +++ b/views/chat.py @@ -96,62 +96,58 @@ async def _fetch_avatar_loop(): asyncio.ensure_future(_fetch_avatar_loop()) -# 重新定义parse_XXX是为了减少对字段名的依赖,防止B站改字段名 -def _parse_danmaku(client: blivedm.BLiveClient, command): - info = command['info'] - if info[3]: - room_id = info[3][3] - medal_level = info[3][0] - else: - room_id = medal_level = 0 - return client._on_receive_danmaku(blivedm.DanmakuMessage( - None, None, None, info[0][4], None, None, info[0][9], None, - info[1], - info[2][0], info[2][1], info[2][2], None, None, info[2][5], info[2][6], None, - medal_level, None, None, room_id, None, None, - info[4][0], None, None, - None, None, - info[7] - )) - - -def _parse_gift(client: blivedm.BLiveClient, command): - data = command['data'] - return client._on_receive_gift(blivedm.GiftMessage( - data['giftName'], data['num'], data['uname'], data['face'], None, - None, data['timestamp'], None, None, - None, None, None, data['coin_type'], data['total_coin'] - )) - - -def _parse_buy_guard(client: blivedm.BLiveClient, command): - data = command['data'] - return client._on_buy_guard(blivedm.GuardBuyMessage( - data['uid'], data['username'], None, None, None, - None, None, data['start_time'], None - )) - - -def _parse_super_chat(client: blivedm.BLiveClient, command): - data = command['data'] - return client._on_super_chat(blivedm.SuperChatMessage( - data['price'], data['message'], None, data['start_time'], - None, None, data['id'], None, - None, None, data['user_info']['uname'], - data['user_info']['face'], None, - None, None, - None, None, None, - None - )) - - class Room(blivedm.BLiveClient): + # 重新定义parse_XXX是为了减少对字段名的依赖,防止B站改字段名 + def __parse_danmaku(self, command): + info = command['info'] + if info[3]: + room_id = info[3][3] + medal_level = info[3][0] + else: + room_id = medal_level = 0 + return self._on_receive_danmaku(blivedm.DanmakuMessage( + None, None, None, info[0][4], None, None, info[0][9], None, + info[1], + info[2][0], info[2][1], info[2][2], None, None, info[2][5], info[2][6], None, + medal_level, None, None, room_id, None, None, + info[4][0], None, None, + None, None, + info[7] + )) + + def __parse_gift(self, command): + data = command['data'] + return self._on_receive_gift(blivedm.GiftMessage( + data['giftName'], data['num'], data['uname'], data['face'], None, + None, data['timestamp'], None, None, + None, None, None, data['coin_type'], data['total_coin'] + )) + + def __parse_buy_guard(self, command): + data = command['data'] + return self._on_buy_guard(blivedm.GuardBuyMessage( + data['uid'], data['username'], None, None, None, + None, None, data['start_time'], None + )) + + def __parse_super_chat(self, command): + data = command['data'] + return self._on_super_chat(blivedm.SuperChatMessage( + data['price'], data['message'], None, data['start_time'], + None, None, data['id'], None, + None, None, data['user_info']['uname'], + data['user_info']['face'], None, + None, None, + None, None, None, + None + )) + _COMMAND_HANDLERS = { **blivedm.BLiveClient._COMMAND_HANDLERS, - 'DANMU_MSG': _parse_danmaku, - 'SEND_GIFT': _parse_gift, - 'GUARD_BUY': _parse_buy_guard, - 'SUPER_CHAT_MESSAGE': _parse_super_chat + 'DANMU_MSG': __parse_danmaku, + 'SEND_GIFT': __parse_gift, + 'GUARD_BUY': __parse_buy_guard, + 'SUPER_CHAT_MESSAGE': __parse_super_chat } def __init__(self, room_id):