Skip to content
This repository was archived by the owner on Jun 6, 2023. It is now read-only.

Commit 64f4cde

Browse files
authored
Merge pull request #224 from yawwwwwn/master
Draw lottery result
2 parents 8cebb02 + 8991654 commit 64f4cde

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

OnlineHeart.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import datetime
77
import asyncio
88
import queue
9+
from statistics import Statistics
910
from printer import Printer
1011

1112

@@ -71,8 +72,18 @@ async def guard_lottery(self):
7172
"Error", "red")
7273
await asyncio.sleep(0.2)
7374

75+
async def check_winner(self, i, g, start_time):
76+
# 开奖5s后检查是否中奖
77+
await asyncio.sleep(time.mktime(time.strptime(start_time, '%Y-%m-%d %H:%M:%S')) - time.time() + 5)
78+
response2 = await bilibili().get_winner_info(i, g)
79+
json_response2 = await response2.json(content_type=None)
80+
for winner in json_response2["data"]["winnerList"]:
81+
if winner["uid"] == bilibili().dic_bilibili['uid']:
82+
Printer().printer(f'实物抽奖中中奖: {winner["giftTitle"]}', "Lottery", "cyan")
83+
Statistics().add_to_result(winner["giftTitle"], 1)
84+
7485
async def draw_lottery(self):
75-
black_list = ["123", "1111", "测试", "測試", "测一测", "ce-shi", "test", "T-E-S-T", "lala", # 已经出现
86+
black_list = ["123", "1111", "测试", "測試", "测一测", "ce-shi", "test", "T-E-S-T", "lala", "我是抽奖标题", # 已经出现
7687
"測一測", "TEST", "Test", "t-e-s-t"] # 合理猜想
7788
former_lottery = queue.Queue(maxsize=4)
7889
[former_lottery.put(True) for _ in range(4)]
@@ -100,10 +111,13 @@ async def draw_lottery(self):
100111
response1 = await bilibili().get_gift_of_lottery(i, g)
101112
json_response1 = await response1.json(content_type=None)
102113
Printer().printer(f"参与『{title}>>>{jp_list}』抽奖回显: {json_response1}", "Lottery", "cyan")
114+
start_time = json_response['data']['typeB'][g]["startTime"]
115+
asyncio.ensure_future(self.check_winner(i, g, start_time))
103116
else:
104117
if not any(former_lottery.queue): # 检查最近4个活动id是否都-400
105118
break
106119
await asyncio.sleep(0.2)
120+
del former_lottery
107121

108122
async def run(self):
109123
while 1:

bilibili.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ async def get_gift_of_lottery(self, i, g):
434434
response1 = await self.bili_section_get(url1, headers=self.dic_bilibili['pcheaders'])
435435
return response1
436436

437+
async def get_winner_info(self, i, g):
438+
url2 = 'https://api.live.bilibili.com/lottery/v1/box/getWinnerGroupInfo?aid=' + \
439+
str(i) + '&number=' + str(g + 1)
440+
response2 = await self.bili_section_get(url2, headers=self.dic_bilibili['pcheaders'])
441+
return response2
442+
437443
async def get_time_about_silver(self):
438444
time = CurrentTime()
439445
temp_params = 'access_key=' + self.dic_bilibili['access_key'] + '&actionKey=' + self.dic_bilibili[

bilibiliCilent.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,24 @@ async def parseDanMu(self, messages):
222222
# Printer().printer(f"出现了远古的SYS_GIFT,请尽快联系开发者{dic}", "Warning", "red")
223223
pass
224224
elif cmd == 'NOTICE_MSG':
225-
# msg_type: 2 抽奖 (TV, 大楼, etc)
226-
# 3 总督
227-
# 6 风暴?
225+
# msg_type: 1 小时榜首绘马大奖等通报
226+
# 2 抽奖 (TV, 大楼, etc.)
227+
# 3 舰队
228+
# 4 总督进入直播间
229+
# 5 当前房间高能大奖
230+
# 6 风暴
228231
# 8 任意门
229-
if dic.get('msg_type') in [2,3,6,8]:
230-
try:
232+
# 9 活动中主播达成星级通报
233+
try:
234+
if dic.get('msg_type') in [2, 8]:
231235
real_roomid = dic.get('real_roomid')
232236
Printer().printer(f"检测到房间 {real_roomid} 的广播抽奖 @[{self.area}分区]{self._roomId}", "Lottery", "cyan")
233237
Rafflehandler().append2list_TV(real_roomid)
234238
Statistics().append2pushed_TVlist(real_roomid, self.area[0])
235-
except:
236-
Printer().printer(f"NOTICE_MSG出错,请联系开发者 {dic}", "Warning", "red")
237-
else:
238-
Printer().printer(f"{dic['msg_common']} @[{self.area}分区]{self._roomId}", "Info", "green")
239+
else:
240+
Printer().printer(f"{dic['msg_common']} @[{self.area}分区]{self._roomId}", "Info", "green")
241+
except Exception:
242+
Printer().printer(f"NOTICE_MSG出错,请联系开发者 {dic}", "Warning", "red")
239243
elif cmd == 'SYS_MSG':
240244
if set(dic) in [set(self.dic_bulletin), {'cmd', 'msg', 'msg_text'}, {'cmd', 'msg', 'url'}]:
241245
Printer().printer(f"{dic['msg']} @[{self.area}分区]{self._roomId}", "Info", "green")

0 commit comments

Comments
 (0)