-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
118 lines (96 loc) · 2 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
import chat
import control
import parse
import time
import sys
# the max length of danmu on douyu.tv is 20..
DEFAULT_CHAT_ROOM = 6032
NO_EXEC = False
command_map = {
#
'8' : 'UPARROW',
'2' : 'DOWNARROW',
'4' : 'LEFTARROW',
'6' : 'RIGHTARROW',
#
'SPACE' : 'SPACE',
'CTRL' : 'LEFTCTRL',
'SHIFT' : 'LEFTSHIFT',
#
'Z' : 'Z',
'A' : 'A',
'B' : 'B',
'M' : 'M',
'X' : 'X',
'C' : 'C',
'V' : 'V'
}
#
def print_strings(*strs):
for s in strs:
try:
print s.decode('utf-8'),
except:
print "!@#$%^&*",
print ''
def get_user(uname):
if uname not in users:
users[uname] = User
return users[uname]
def check_command(umsg):
# check string message
if umsg in command_map:
return True
# check single-char message
for c in umsg:
if c not in command_map:
return False
# check message length
if len(umsg) > MAX_MSG_LEN:
print '指令长度限制为'.decode('utf-8'), MAX_MSG_LEN
return False;
return True
def print_log(uname,ucmd,cnt,ftime):
if ftime:
print "#", time.strftime('%H:%M:%S')
try:
print uname.decode('utf-8'), ':', ucmd, cnt
except:
print "!@#$%^&*", ':', ucmd, cnt
def do_send_key(cmd):
if not NO_EXEC:
control.sendkey(cmd)
def run_command(uname,ucmd):
if ucmd in command_map:
do_send_key(command_map[ucmd])
print_log(uname,ucmd,1,True)
return
cnt = 0
for c in ucmd:
cnt = cnt + 1
do_send_key(command_map[c])
print_log(uname,c,cnt,cnt==1)
def new_query(raw_msg):
try:
#
msg = parse.getinfo(raw_msg)
cmd_str = msg[0]
user_name = msg[1]
#
if not check_command(cmd_str):
return
#
run_command(user_name,cmd_str)
except:
print sys.exc_info()[0]
print sys.exc_info()[1]
return
#
if __name__ == '__main__':
control.control_init('空之轨迹 FC')
#control.control_init('搶曽怱鉟極')
while True:
control.sendkey('Z')
time.sleep(1)
#chat.start_chat(DEFAULT_CHAT_ROOM, new_query)