forked from ZKeeer/WeChatAssistant
-
Notifications
You must be signed in to change notification settings - Fork 1
/
execution.py
227 lines (199 loc) · 10.2 KB
/
execution.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
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
import os
import random
import re
import itchat
import config
import screenshoot
from autoreply import MsgAutoReply
from keywordlistener import KeywordListener as Keyword
from signin import SignInMPS
# from takephoto import TakeGIF
class Execution:
REVOCATIONPATH = "./Revocation/"
def __init__(self):
self.keyword = Keyword()
self.snin = SignInMPS()
self.reply = MsgAutoReply()
def Execution(self, message):
"""
执行命令
:param message: 微信消息中提取的命令
:return: 无
"""
# "%s%s%s%s%s关键词" % ("="*4, "Command Message", "="*4, "\n\n", action)
command = message['Text']
msg_send = "{0}{1}{0}{2}".format("=" * 8, "助手消息", "\n\n")
if re.match(r"^查看文件\[.*\]", command):
filename = re.search(r"^查看文件\[(.*?)\]$", command).group(1)
result = self.ShowFile(filename)
if result == True:
pass
else:
msg_send += result
itchat.send(msg_send, toUserName='filehelper')
elif re.match(r"^删除文件\[.*\]", command):
filename = re.search(r"^删除文件\[(.*?)\]$", command).group(1)
msg_send += self.DeleteFile(filename)
itchat.send(msg_send, toUserName='filehelper')
elif re.match(r"^添加关键词\[.*\]", command):
keyword = re.search(r"^添加关键词\[(.*?)\]", command).group(1)
msg_send += self.keyword.AddKeyword(keyword)
itchat.send(msg_send, toUserName='filehelper')
elif re.match(r"^删除关键词\[.*\]", command):
keyword = re.search(r"^删除关键词\[(.*?)\]", command).group(1)
msg_send += self.keyword.DeleteKeyword(keyword)
itchat.send(msg_send, toUserName='filehelper')
elif re.match(r"^撤回附件列表$", command):
self.ReturnAttachmentList()
elif re.match(r"^清空附件列表$", command):
self.ClearAttachmentList()
elif re.match("^查看关键词$", command):
msg_send += self.keyword.ShowKeyword()
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^清空关键词$", command):
msg_send += self.keyword.ClearKeyword()
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^查看签到口令$", command):
msg_send += self.snin.ShowComd()
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^清空签到口令$", command):
msg_send += self.snin.ClearComd()
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^添加签到口令\[.*?\]$", command):
mps, cmd = re.search("^添加签到口令\[(.*?):(.*?)\]$", command).group(1, 2)
self.snin.AddComd(mps, cmd)
msg_send += "添加签到口令[{}:{}]成功".format(mps, cmd)
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^删除签到口令\[.*?\]$", command):
mps = re.search("^删除签到口令\[(.*?)\]$", command).group(1)
msg_send += self.snin.DeleteComd(mps)
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^截图$", command):
screenshoot.SC()
elif re.match("^添加自动回复\[.*?\]$", command):
keyword, content = re.search("^添加自动回复\[(.*?):(.*?)\]$", command).group(1, 2)
msg_send += self.reply.AddRule(keyword, content)
itchat.send(msg_send, toUserName="filehelper")
elif re.match("^删除自动回复\[.*\]$", command):
keyword = re.search("^删除自动回复\[(.*?)\]$", command).group(1)
msg_send += self.reply.DeleteRule(keyword)
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^清空自动回复$", command):
msg_send += self.reply.ClearRule()
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^查看自动回复$", command):
msg_send += self.reply.ShowRule()
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^关闭自动回复$", command):
msg_send += self.reply.CloseAutoReply()
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^打开自动回复$", command):
msg_send += self.reply.OpenAutoReply()
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^拍照$", command):
msg_send+="功能未开发,敬请期待"
itchat.send(msg_send, toUserName='filehelper')
"""
img_name = TakePhoto()
if img_name:
itchat.send("@img@{}".format(img_name), toUserName='filehelper')
else:
msg_send += "拍照失败,请重试"
itchat.send(msg_send, toUserName='filehelper')
"""
elif re.match("^拍动图\d{0,2}$", command):
msg_send+="功能未开发,敬请期待"
itchat.send(msg_send, toUserName='filehelper')
"""
seconds = re.findall("^拍动图(\d+)", command)
if seconds:
seconds = int(seconds[0])
if seconds not in range(1, 61):
msg_send += "时间输入错误,请重试"
itchat.send(msg_send, toUserName='filehelper')
return
else:
seconds = 5
img_name = TakeGIF(seconds)
if img_name:
itchat.send("@img@{}".format(img_name), toUserName='filehelper')
else:
msg_send += "拍照失败,请重试"
itchat.send(msg_send, toUserName='filehelper')
"""
elif re.match("^今天吃什么$", command):
today_choice = random.choice(config.today_menu)
emotion = random.choice(config.emoticons)
msg_send += "今天就吃 {} 吧{}{}".format(today_choice, '\n', emotion)
itchat.send(msg_send, toUserName='filehelper')
elif re.match("^退出程序$", command):
itchat.send("退出程序成功", toUserName='filehelper')
itchat.logout()
os._exit(0)
else:
itchat.send(r"暂时支持以下指令:{1}"
r"查看/删除文件[文件名]{0}e.g.查看[123345234.mp3]{1}"
r"撤回附件列表(查看都有哪些保存在电脑中的已撤回附件){1}"
r"清空附件列表(清空已经保存在电脑中的附件){1}"
r"添加关键词[关键词]{0}e.g.设置关键词[在不在]{1}"
r"删除关键词[关键词]{0}e.g.删除关键词[在不在]{1}"
r"清空关键词 清空已经设置的所有关键词{1}"
r"查看关键词 查看目前设置的关键词{1}"
r"添加签到口令[公众号:签到口令]{0}e.g.添加签到口令[招商银行信用卡:签到]{1}"
r"删除签到口令[公众号]{0}e.g.删除签到口令[招商银行信用卡]{1}"
r"查看签到口令 查看已经存在的公众和和对应的签到口令{1}"
r"清空签到口令 清空所有签到口令{1}"
r"截图 截取运行本程序的机器当前界面{1}"
r"添加自动回复[针对的关键词:回复内容]{0}e.g.添加自动回复[在不在:我现在有事情,待会儿回复你]{1}"
r"删除自动回复[针对的关键词]{0}e.g.删除自动回复[在不在]{1}"
r"清空自动回复{1}"
r"关闭自动回复{1}"
r"打开自动回复{1}"
r"今天吃什么{1}"
r"退出程序{1}"
r"其他指令暂不支持,请期待最新版本。".format("\n", "\n\n"),
toUserName="filehelper")
def ShowFile(self, filename):
if not os.path.exists(r"./Revocation/" + filename):
return "文件:{} 不存在".format(filename)
if re.search(r"png|jpg|bmp|jpeg|gif|webp", filename):
msg_type = "img"
elif re.search(r"avi|rm|mp4|wmv", filename):
msg_type = "vid"
else:
msg_type = "fil"
itchat.send("@{}@{}".format(msg_type, r"./Revocation/" + filename),
toUserName="filehelper")
return True
def DeleteFile(self, filename):
if not os.path.exists(r"./Revocation/" + filename):
return "文件:{} 不存在".format(filename)
else:
os.remove(r"./Revocation/" + filename)
return "文件:{} 删除成功".format(filename)
def ClearAttachmentList(self):
if self.REVOCATIONPATH:
try:
for item in os.listdir(self.REVOCATIONPATH):
os.remove(self.REVOCATIONPATH + item)
msg = "{0}{1}{0}{2}撤回助手:清空附件成功".format(
"=" * 6, "助手消息", "\n\n")
itchat.send(msg, toUserName='filehelper')
except:
msg = "{0}{1}{0}{2}撤回助手:清空附件失败,请重试".format(
"=" * 6, "助手消息", "\n\n")
itchat.send(msg, toUserName='filehelper')
else:
msg = "{0}{1}{0}{2}撤回助手:暂时没有附件".format(
"=" * 6, "助手消息", "\n\n")
itchat.send(msg, toUserName='filehelper')
# 返回撤回附件所有文件名
def ReturnAttachmentList(self):
if os.listdir(self.REVOCATIONPATH):
msg_send = r"{0}{1}{0}{2}助手消息:所有储存的附件如下:{3}".format("=" * 6, "助手消息", "\n\n", "\n")
for item in os.listdir(self.REVOCATIONPATH):
msg_send += "{} {}".format(item, "\n")
itchat.send(msg_send, toUserName="filehelper")
else:
msg = r"{0}{1}{0}{2}助手消息:暂时没有撤回的附件".format("=" * 6, "助手消息", "\n\n")
itchat.send(msg, toUserName="filehelper")