-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.py
49 lines (40 loc) · 1.4 KB
/
example.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
47
48
49
from pydouyu.client import Client
import time
import sys
otype_to_str = {
"0": "普通用户",
"1": "房管",
"2": "主播",
"3": "超管"
}
def chatmsg_handler(msg):
try:
output = time.strftime("[%Y-%m-%d %H:%M:%S] ", time.localtime()) + msg['nn'] + ": " + msg['txt']
print(output)
sys.stdout.flush()
except Exception as e:
print("chatmsg_handler failed. Exception: %s" % e)
def uenter_handler(msg):
try:
output = time.strftime("[%Y-%m-%d %H:%M:%S] ", time.localtime()) + msg['nn'] + " 进入了直播间"
print(output)
sys.stdout.flush()
except Exception as e:
print("uenter_handler failed. Exception: %s" % e)
def newblackres_handler(msg):
try:
time_stamp = msg['endtime']
time_local = time.localtime(int(time_stamp))
time_str = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
output = time.strftime("[%Y-%m-%d %H:%M:%S] ", time.localtime()) + \
"[" + otype_to_str[msg['otype']] + "] " + \
msg['snic'] + " 封禁了 " + msg['dnic'] + " 到 " + time_str
print(output)
sys.stdout.flush()
except Exception as e:
print("newblackres_handler failed. Exception: %s" % e)
c = Client(room_id=562590)
c.add_handler('chatmsg', chatmsg_handler)
c.add_handler('uenter', uenter_handler)
c.add_handler('newblackres', newblackres_handler)
c.start()