-
Notifications
You must be signed in to change notification settings - Fork 0
/
rafflehandler.py
47 lines (39 loc) · 1.47 KB
/
rafflehandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import asyncio
import bilibiliCilent
class Rafflehandler:
instance = None
def __new__(cls, *args, **kw):
if not cls.instance:
cls.instance = super(Rafflehandler, cls).__new__(cls, *args, **kw)
cls.instance.list_activity = []
cls.instance.list_TV = []
return cls.instance
async def run(self):
while True:
len_list_activity = len(self.list_activity)
len_list_TV = len(self.list_TV)
set_activity = set(self.list_activity)
set_TV = set(self.list_TV)
tasklist = []
for i in set_TV:
task = asyncio.ensure_future(bilibiliCilent.handle_1_room_TV(i))
tasklist.append(task)
for i in set_activity:
task = asyncio.ensure_future(bilibiliCilent.handle_1_room_activity(i))
tasklist.append(task)
if tasklist:
await asyncio.wait(tasklist, return_when=asyncio.ALL_COMPLETED)
else:
pass
del self.list_activity[:len_list_activity]
del self.list_TV[:len_list_TV]
if len_list_activity == 0 and len_list_TV == 0:
await asyncio.sleep(0.1)
else:
await asyncio.sleep(0.1)
def append2list_TV(self, real_roomid):
self.list_TV.append(real_roomid)
return
def append2list_activity(self, text1):
self.list_activity.append(text1)
return