-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrshell.py
More file actions
416 lines (356 loc) · 12.3 KB
/
Copy pathwrshell.py
File metadata and controls
416 lines (356 loc) · 12.3 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
"""
小型shell模块,使用文件传输助手作为shell
解析输入命令行,提供函数供调用
命令行包含
添加好友到活动列表中
wr addf <friend_name>
-添加好友到活动列表中,添加到活动列表中的好友提供图片查询和其他功能
-非活动列表中的好友不提供任何功能
删除活动列表中好友
wr rmf <friend_name>
-从活动列表中删除好友,不再提供相关功能
显示活动列表中好友
wr lf
- 显示活动列表中好友
添加群组到活动列表中
wr addg <group_name>
-添加群组到活动列表中,群组中的所有人可以使用账号的图片查询和其他功能
删除活动列表中的群组
wr rmg <group_name>
-删除群组,不再提供相关功能
显示活动列表中的群组
wr lg
- 显示活动列表中群组
添加图片到图片缓存中
wr addimg
-添加图片到图片缓存中,使用者可以发出相关指令查询图片缓存中的图片
-输入添加图片命令后,5分钟内发往文件助手的图片都存入图片缓存中
添加好友或群组到广播列表中
wr addb <friend_name or group_name>
-添加好友或群组到广播列表中,每天收到广播
删除广播列表中好友或群组
wr rmb <friend_name or group_name>
-将好友或群组从广播列表中移除
显示广播列表中的好友或群组
wr lb
- 显示活动列表中好友或群组
设置广播开始时间
wr bst <year> <month> <day> <hour> <minute> <second>
开始广播,指定间隔秒,分,时,天,空格分开,可以选择填写
wr onb <second> <minute> <hour> <day>
关闭广播
wr offb
显示帮助
wr h
"""
from wxpy import *
from threading import Thread
import time
import constant
import broadcast
import os
def inner_func(command):
"""
判断是否是内置命令,内置命令以wr开头
:param command: 命令行
:return: 无
"""
args = command.strip().split(' ')
if args[0] == 'wr':
execute_func(args)
def add_img(args=None):
"""
添加图片缓存
:return:
"""
print('Start receving...')
constant.bot.file_helper.send('开始接收图片,5分钟内有效')
thread = Thread(target=receive_cache)
thread.start()
# set timer in 5 min
def stop_cache():
"""
停止图片缓存
:return:
"""
print('Start timer...')
time.sleep(300)
global isReceive
isReceive = False
constant.bot.file_helper.send('5分钟已到,停止接收图片')
print('Stop timer...')
def receive_cache():
"""
添加图片到图片缓存文件夹中,5分钟内有效
:return: 无
"""
global isReceive
isReceive = True
print('Start caching...')
@constant.bot.register(None, PICTURE, except_self=False)
def filehelper_img_cache(msg):
if not isReceive:
return
if msg.receiver != constant.bot.file_helper:
return
# 检测文件夹是否存在
if not os.path.exists('img'):
os.makedirs('img')
msg.get_file(constant.img_path + msg.file_name)
constant.bot.file_helper.send('收到图片:' + msg.file_name)
thread_02 = Thread(target=stop_cache) # start timer
thread_02.start()
def add_friend(args=None):
"""
向活动列表中添加好友,仅向处于活动列表中的好友提供自动回复
:param args: 命令行参数
:return: 无
"""
friend_name = args[2]
if not constant.bot.friends().search(friend_name):
constant.bot.file_helper.send('未找到 ' + friend_name)
return
friend = constant.bot.friends().search(friend_name)[0]
if friend is None:
constant.bot.file_helper.send('未找到 ' + friend_name)
constant.contact_friend_list.update({friend.puid: friend})
constant.bot.file_helper.send('添加 ' + friend.name)
def remove_friend(args=None):
"""
移除活动列表中的好友
:param args: 命令行参数,包含移除好友名称
:return: 无
"""
friend_name = args[2]
if not constant.bot.friends().search(friend_name):
constant.bot.file_helper.send('未找到 ' + friend_name)
return
friend = constant.bot.friends().search(friend_name)[0]
if friend is None:
constant.bot.file_helper.send('未找到 ' + friend_name)
if friend.puid in constant.contact_friend_list.keys():
constant.contact_friend_list.pop(friend.puid)
constant.bot.file_helper.send('已删除 ' + friend.name)
def show_friends(args=None):
"""
展示活动列表中好友
:param args: 命令行参数
:return: 无
"""
name_list = []
for i in constant.contact_friend_list.keys():
name_list.append(constant.contact_friend_list.get(i).name)
if name_list:
constant.bot.file_helper.send('\n'.join(name_list))
else:
constant.bot.file_helper.send('列表为空')
def add_group(args=None):
"""
向活动列表中添加群组,仅向处于活动列表中的群组提供自动回复
:param args: 命令行参数,包含群组名称
:return: 无
"""
group_name = args[2]
if not constant.bot.groups().search(group_name):
constant.bot.file_helper.send('未找到 ' + group_name)
group = constant.bot.groups().search(group_name)[0]
if group is None:
constant.bot.file_helper.send('未找到 ' + group_name)
constant.contact_group_list.update({group.puid: group})
constant.bot.file_helper.send('添加 ' + group.name)
def remove_group(args=None):
"""
移除活动列表中的群组
:param args: 命令行参数,包含群组名称
:return: 无
"""
group_name = args[2]
if constant.bot.friends().search(group_name):
group = constant.bot.friends().search(group_name)[0]
if group.puid in constant.contact_group_list.keys():
constant.contact_group_list.pop(group.puid)
constant.bot.file_helper.send('已删除 ' + group.name)
return
constant.bot.file_helper.send('未找到 ' + group_name)
def show_groups(args=None):
"""
展示活动列表中的群组
:param args: 命令行参数
:return: 无
"""
name_list = []
for i in constant.contact_group_list.keys():
name_list.append(constant.contact_group_list.get(i).name)
if name_list:
constant.bot.file_helper.send('\n'.join(name_list))
else:
constant.bot.file_helper.send('列表为空')
def add_broadcast(args=None):
"""
向广播列表中添加好友群组,仅向处于广播列表中的群组提供广播
:param args: 命令行参数,包含名称
:return: 无
"""
name = args[2]
if name == 'file_helper':
constant.deliver_list.update({constant.bot.file_helper.puid: constant.bot.file_helper})
constant.bot.file_helper.send('添加 文件传输助手')
return
if constant.bot.friends().search(name):
friend = constant.bot.friends().search(name)[0]
if friend is not None:
constant.deliver_list.update({friend.puid: friend})
constant.bot.file_helper.send('添加 ' + friend.name)
return
constant.bot.file_helper.send('未找到好友 ' + name)
if constant.bot.groups().search(name):
group = constant.bot.groups().search(name)[0]
if group is not None:
constant.deliver_list.update({group.puid: group})
constant.bot.file_helper.send('添加 ' + group.name)
return
constant.bot.file_helper.send('未找到群组 ' + name)
def remove_broadcast(args=None):
"""
移除广播列表中的好友群组
:param args: 命令行参数,包含名称
:return: 无
"""
friend_name = args[2]
if constant.bot.friends().search(friend_name):
friend = constant.bot.friends().search(friend_name)[0]
if friend.puid in constant.deliver_list.keys():
constant.deliver_list.pop(friend.puid)
constant.bot.file_helper.send('已删除 ' + friend.name)
return
constant.bot.file_helper.send('未找到 ' + friend_name)
group_name = args[2]
if constant.bot.groups().search(group_name):
group = constant.bot.groups().search(group_name)[0]
if group.puid in constant.deliver_list.keys():
constant.deliver_list.pop(group.puid)
constant.bot.file_helper.send('已删除 ' + group.name)
return
constant.bot.file_helper.send('未找到 ' + group_name)
def show_broadcast(args=None):
"""
展示广播列表中的好友群组
:param args: 命令行参数
:return: 无
"""
name_list = []
for i in constant.deliver_list.keys():
name_list.append(constant.deliver_list.get(i).name)
if name_list:
constant.bot.file_helper.send('\n'.join(name_list))
else:
constant.bot.file_helper.send('列表为空')
def set_broadcast_start_time(args=None):
if len(args) == 2:
constant.bot.file_helper.send('设置失败,间隔不能为空')
return
year = 0
month = 0
day = 0
hour = 0
minute = 0
second = 0
try:
if len(args) <= 4:
constant.bot.file_helper.send('必须设置年月日')
return
elif len(args) == 5:
year = int(args[2])
month = int(args[3])
day = int(args[4])
elif len(args) == 6:
year = int(args[2])
month = int(args[3])
day = int(args[4])
hour = int(args[5])
elif len(args) == 7:
year = int(args[2])
month = int(args[3])
day = int(args[4])
hour = int(args[5])
minute = int(args[6])
elif len(args) == 8:
year = int(args[2])
month = int(args[3])
day = int(args[4])
hour = int(args[5])
minute = int(args[6])
second = int(args[7])
except Exception:
constant.bot.file_helper.send('格式错误,请重新输入')
broadcast.module_set_timer(year, month, day, hour, minute, second)
def turn_on_broadcast(args=None):
if len(args) == 2:
constant.bot.file_helper.send('设置失败,间隔不能为空')
return
second = 0
minute = 0
hour = 0
day = 0
if len(args) == 3:
second = int(args[2])
elif len(args) == 4:
second = int(args[2])
minute = int(args[3])
elif len(args) <= 5:
second = int(args[2])
minute = int(args[3])
hour = int(args[4])
elif len(args) <= 6:
second = int(args[2])
minute = int(args[3])
hour = int(args[4])
day = int(args[5])
constant.isRepeat = True
constant.bot.file_helper.send('广播已开启,广播对象为')
show_broadcast()
broadcast.module_broadcast(True, True, second, minute, hour, day)
def turn_off_broadcast(args=None):
constant.bot.file_helper.send('广播已关闭')
broadcast.stop_repeat()
def show_help(args=None):
"""
显示帮助
:param args: 命令行参数
:return:
"""
help_info = 'wr <option> <**args> \n addf <friend_name> 添加好友 \n'\
' rmf <friend_name> 删除好友 \n lf 显示名单好友 \n'\
' addg <group_name> 添加群组 \n rmg 删除群组\n'\
' lg 显示名单群组\n addimg 添加图片缓存\n h 显示帮助\n'\
' addb <friend_name | group_name> 添加广播对象\n rmb <friend_name | group_name> 移除广播对象\n'\
' lb 显示广播列表\n onb <second> <minute> <hour> <day> 开启广播,设置间隔\n'\
' offb 关闭广播\n bst <year> <month> <day> <hour> <minute> <second> 设置广播开始时间'
constant.bot.file_helper.send(help_info)
func_dict = {
'h': show_help,
'addimg': add_img,
'addf': add_friend,
'rmf': remove_friend,
'lf': show_friends,
'addg': add_group,
'rmg': remove_group,
'lg': show_groups,
'addb': add_broadcast,
'rmb': remove_broadcast,
'lb': show_broadcast,
'onb': turn_on_broadcast,
'offb': turn_off_broadcast,
'bst': set_broadcast_start_time
}
def execute_func(args):
"""
执行内置命令功能
:param args: 命令行参数
:return: 无
"""
func = func_dict.get(args[1])
if func is None:
return
print(args)
func(args)