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("=" * 4, "System Message", "\n\n") if re.search(r"(.*?)文件\[(.*?)\]", command): action, filename = re.search(r"(.*?)文件\[(.*?)\]", command).group(1, 2) self.ViewDeleteFile(action, filename) elif re.match(r"^添加关键词\[.*\]", command): msg_send += "添加关键词" keyword = re.search(r"^添加关键词\[(.*?)\]", command).group(1) added, msg = self.keyword.SetKeyword(keyword) msg_send = msg_send + msg itchat.send(msg_send, toUserName='******') elif re.match(r"^删除关键词\[.*\]", command): msg_send += "删除关键词" keyword = re.search(r"^删除关键词\[(.*?)\]", command).group(1) removed, msg = self.keyword.RemoveKeyword(keyword) msg_send = msg_send + msg itchat.send(msg_send, toUserName='******') 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='******') elif re.match("^清空关键词$", command): cleared, msg = self.keyword.ClearKeyword() msg_send += msg itchat.send(msg_send, toUserName='******') elif re.match("^查看签到口令$", command): msg_send += self.snin.ShowComd() itchat.send(msg_send, toUserName='******') elif re.match("^清空签到口令$", command): self.snin.ClearComd() msg_send += "清空签到口令成功" itchat.send(msg_send, toUserName='******') 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='******') elif re.match("^删除签到口令#.*#$", command): mps = re.search("^删除签到口令#(.*?)#$", command).group(1) if self.snin.DeleteComd(mps): msg_send += "口令【{}】删除成功".format(mps) else: msg_send += "口令【{}】删除失败".format(mps) itchat.send(msg_send, toUserName='******') elif re.match("^截图$", command): screenshoot.SC() 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"其他指令暂不支持,请期待最新版本。".format("\n", "\n\n"), toUserName="******")
msg_send += self.snin.ClearComd() itchat.send(msg_send, toUserName='******') elif re.match(u"^添加签到口令\[.*?\]$", command): mps, cmd = re.search(u"^添加签到口令\[(.*?):(.*?)\]$", command).group(1, 2) self.snin.AddComd(mps, cmd) msg_send += u"添加签到口令[{}:{}]成功".format(mps, cmd) itchat.send(msg_send, toUserName='******') elif re.match(u"^删除签到口令\[.*?\]$", command): mps = re.search(u"^删除签到口令\[(.*?)\]$", command).group(1) msg_send += self.snin.DeleteComd(mps) itchat.send(msg_send, toUserName='******') elif re.match(u"^截图$", command): screenshoot.SC() elif re.match(u"^添加自动回复\[.*?\]$", command): keyword, content = re.search(u"^添加自动回复\[(.*?):(.*?)\]$", command).group(1, 2) msg_send += self.reply.AddRule(keyword, content) itchat.send(msg_send, toUserName="******") elif re.match(u"^删除自动回复\[.*\]$", command): keyword = re.search(u"^删除自动回复\[(.*?)\]$", command).group(1) msg_send += self.reply.DeleteRule(keyword) itchat.send(msg_send, toUserName='******') elif re.match(u"^清空自动回复$", command): msg_send += self.reply.ClearRule() itchat.send(msg_send, toUserName='******') elif re.match(u"^查看自动回复$", command): msg_send += self.reply.ShowRule() itchat.send(msg_send, toUserName='******') elif re.match(u"^关闭自动回复$", command):
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='******') elif re.match(r"^删除文件\[.*\]", command): filename = re.search(r"^删除文件\[(.*?)\]$", command).group(1) msg_send += self.DeleteFile(filename) itchat.send(msg_send, toUserName='******') elif re.match(r"^添加关键词\[.*\]", command): keyword = re.search(r"^添加关键词\[(.*?)\]", command).group(1) msg_send += self.keyword.AddKeyword(keyword) itchat.send(msg_send, toUserName='******') elif re.match(r"^删除关键词\[.*\]", command): keyword = re.search(r"^删除关键词\[(.*?)\]", command).group(1) msg_send += self.keyword.DeleteKeyword(keyword) itchat.send(msg_send, toUserName='******') 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='******') elif re.match("^清空关键词$", command): msg_send += self.keyword.ClearKeyword() itchat.send(msg_send, toUserName='******') elif re.match("^查看签到口令$", command): msg_send += self.snin.ShowComd() itchat.send(msg_send, toUserName='******') elif re.match("^清空签到口令$", command): msg_send += self.snin.ClearComd() itchat.send(msg_send, toUserName='******') 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='******') elif re.match("^删除签到口令\[.*?\]$", command): mps = re.search("^删除签到口令\[(.*?)\]$", command).group(1) msg_send += self.snin.DeleteComd(mps) itchat.send(msg_send, toUserName='******') 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="******") elif re.match("^删除自动回复\[.*\]$", command): keyword = re.search("^删除自动回复\[(.*?)\]$", command).group(1) msg_send += self.reply.DeleteRule(keyword) itchat.send(msg_send, toUserName='******') elif re.match("^清空自动回复$", command): msg_send += self.reply.ClearRule() itchat.send(msg_send, toUserName='******') elif re.match("^查看自动回复$", command): msg_send += self.reply.ShowRule() itchat.send(msg_send, toUserName='******') elif re.match("^关闭自动回复$", command): msg_send += self.reply.CloseAutoReply() itchat.send(msg_send, toUserName='******') elif re.match("^打开自动回复$", command): msg_send += self.reply.OpenAutoReply() itchat.send(msg_send, toUserName='******') elif re.match("^拍照$", command): msg_send += "功能未开发,敬请期待" itchat.send(msg_send, toUserName='******') """ img_name = TakePhoto() if img_name: itchat.send("@img@{}".format(img_name), toUserName='******') else: msg_send += "拍照失败,请重试" itchat.send(msg_send, toUserName='******') """ elif re.match("^拍动图\d{0,2}$", command): msg_send += "功能未开发,敬请期待" itchat.send(msg_send, toUserName='******') """ 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='******') return else: seconds = 5 img_name = TakeGIF(seconds) if img_name: itchat.send("@img@{}".format(img_name), toUserName='******') else: msg_send += "拍照失败,请重试" itchat.send(msg_send, toUserName='******') """ 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='******') elif re.match("^退出程序$", command): itchat.send("退出程序成功", toUserName='******') 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="******")
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("=" * 6, "助手消息", "\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='******') elif re.match(r"^删除文件\[.*\]", command): filename = re.search(r"^查看文件\[(.*?)\]$", command).group(1) msg_send += self.DeleteFile(filename) itchat.send(msg_send, toUserName='******') elif re.match(r"^添加关键词\[.*\]", command): keyword = re.search(r"^添加关键词\[(.*?)\]", command).group(1) msg_send += self.keyword.AddKeyword(keyword) itchat.send(msg_send, toUserName='******') elif re.match(r"^删除关键词\[.*\]", command): keyword = re.search(r"^删除关键词\[(.*?)\]", command).group(1) msg_send += self.keyword.DeleteKeyword(keyword) itchat.send(msg_send, toUserName='******') 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='******') elif re.match("^清空关键词$", command): msg_send += self.keyword.ClearKeyword() itchat.send(msg_send, toUserName='******') elif re.match("^查看签到口令$", command): msg_send += self.snin.ShowComd() itchat.send(msg_send, toUserName='******') elif re.match("^清空签到口令$", command): msg_send += self.snin.ClearComd() itchat.send(msg_send, toUserName='******') 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='******') elif re.match("^删除签到口令#.*#$", command): mps = re.search("^删除签到口令#(.*?)#$", command).group(1) msg_send += self.snin.DeleteComd(mps) itchat.send(msg_send, toUserName='******') 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="******") elif re.match("^删除自动回复#.*#$", command): keyword = re.search("^添加自动回复#(.*?)#$", command).group(1) msg_send += self.reply.DeleteRule(keyword) itchat.send(msg_send, toUserName='******') elif re.match("^清空自动回复$", command): msg_send += self.reply.ClearRule() itchat.send(msg_send, toUserName='******') elif re.match("^查看自动回复$", command): msg_send += self.reply.ShowRule() itchat.send(msg_send, toUserName='******') elif re.match("^关闭自动回复$", command): msg_send += self.reply.CloseAutoReply() itchat.send(msg_send, toUserName='******') elif re.match("^打开自动回复$", command): msg_send += self.reply.OpenAutoReply() itchat.send(msg_send, toUserName='******') elif re.match("^退出程序$", command): itchat.send("退出程序成功", toUserName='******') 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"其他指令暂不支持,请期待最新版本。".format("\n", "\n\n"), toUserName="******")