From 89916549aca3a7497d4852e70f22e82b28514d19 Mon Sep 17 00:00:00 2001 From: yawwwwwn <40122222+yawwwwwn@users.noreply.github.com> Date: Fri, 20 Sep 2019 00:34:07 +0800 Subject: [PATCH] Draw lottery result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加实物抽奖后的中奖查询 及时释放queue资源 NOTICE_MSG部分整理 --- OnlineHeart.py | 16 +++++++++++++++- bilibili.py | 6 ++++++ bilibiliCilent.py | 22 +++++++++++++--------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/OnlineHeart.py b/OnlineHeart.py index 76a32bc..1607ea4 100644 --- a/OnlineHeart.py +++ b/OnlineHeart.py @@ -6,6 +6,7 @@ import datetime import asyncio import queue +from statistics import Statistics from printer import Printer @@ -71,8 +72,18 @@ async def guard_lottery(self): "Error", "red") await asyncio.sleep(0.2) + async def check_winner(self, i, g, start_time): + # 开奖5s后检查是否中奖 + await asyncio.sleep(time.mktime(time.strptime(start_time, '%Y-%m-%d %H:%M:%S')) - time.time() + 5) + response2 = await bilibili().get_winner_info(i, g) + json_response2 = await response2.json(content_type=None) + for winner in json_response2["data"]["winnerList"]: + if winner["uid"] == bilibili().dic_bilibili['uid']: + Printer().printer(f'实物抽奖中中奖: {winner["giftTitle"]}', "Lottery", "cyan") + Statistics().add_to_result(winner["giftTitle"], 1) + async def draw_lottery(self): - black_list = ["123", "1111", "测试", "測試", "测一测", "ce-shi", "test", "T-E-S-T", "lala", # 已经出现 + black_list = ["123", "1111", "测试", "測試", "测一测", "ce-shi", "test", "T-E-S-T", "lala", "我是抽奖标题", # 已经出现 "測一測", "TEST", "Test", "t-e-s-t"] # 合理猜想 former_lottery = queue.Queue(maxsize=4) [former_lottery.put(True) for _ in range(4)] @@ -100,10 +111,13 @@ async def draw_lottery(self): response1 = await bilibili().get_gift_of_lottery(i, g) json_response1 = await response1.json(content_type=None) Printer().printer(f"参与『{title}>>>{jp_list}』抽奖回显: {json_response1}", "Lottery", "cyan") + start_time = json_response['data']['typeB'][g]["startTime"] + asyncio.ensure_future(self.check_winner(i, g, start_time)) else: if not any(former_lottery.queue): # 检查最近4个活动id是否都-400 break await asyncio.sleep(0.2) + del former_lottery async def run(self): while 1: diff --git a/bilibili.py b/bilibili.py index 2ba7bcb..f5941db 100644 --- a/bilibili.py +++ b/bilibili.py @@ -434,6 +434,12 @@ async def get_gift_of_lottery(self, i, g): response1 = await self.bili_section_get(url1, headers=self.dic_bilibili['pcheaders']) return response1 + async def get_winner_info(self, i, g): + url2 = 'https://api.live.bilibili.com/lottery/v1/box/getWinnerGroupInfo?aid=' + \ + str(i) + '&number=' + str(g + 1) + response2 = await self.bili_section_get(url2, headers=self.dic_bilibili['pcheaders']) + return response2 + async def get_time_about_silver(self): time = CurrentTime() temp_params = 'access_key=' + self.dic_bilibili['access_key'] + '&actionKey=' + self.dic_bilibili[ diff --git a/bilibiliCilent.py b/bilibiliCilent.py index 98a0283..4674cff 100644 --- a/bilibiliCilent.py +++ b/bilibiliCilent.py @@ -222,20 +222,24 @@ async def parseDanMu(self, messages): # Printer().printer(f"出现了远古的SYS_GIFT,请尽快联系开发者{dic}", "Warning", "red") pass elif cmd == 'NOTICE_MSG': - # msg_type: 2 抽奖 (TV, 大楼, etc) - # 3 总督 - # 6 风暴? + # msg_type: 1 小时榜首绘马大奖等通报 + # 2 抽奖 (TV, 大楼, etc.) + # 3 舰队 + # 4 总督进入直播间 + # 5 当前房间高能大奖 + # 6 风暴 # 8 任意门 - if dic.get('msg_type') in [2,3,6,8]: - try: + # 9 活动中主播达成星级通报 + try: + if dic.get('msg_type') in [2, 8]: real_roomid = dic.get('real_roomid') Printer().printer(f"检测到房间 {real_roomid} 的广播抽奖 @[{self.area}分区]{self._roomId}", "Lottery", "cyan") Rafflehandler().append2list_TV(real_roomid) Statistics().append2pushed_TVlist(real_roomid, self.area[0]) - except: - Printer().printer(f"NOTICE_MSG出错,请联系开发者 {dic}", "Warning", "red") - else: - Printer().printer(f"{dic['msg_common']} @[{self.area}分区]{self._roomId}", "Info", "green") + else: + Printer().printer(f"{dic['msg_common']} @[{self.area}分区]{self._roomId}", "Info", "green") + except Exception: + Printer().printer(f"NOTICE_MSG出错,请联系开发者 {dic}", "Warning", "red") elif cmd == 'SYS_MSG': if set(dic) in [set(self.dic_bulletin), {'cmd', 'msg', 'msg_text'}, {'cmd', 'msg', 'url'}]: Printer().printer(f"{dic['msg']} @[{self.area}分区]{self._roomId}", "Info", "green")