def handle_text_msg(msg): username = msg['ActualNickName'] # 发言者 content = msg['Text'] if '[疑问]' in content: #发帖 clean_content = re.split(r'\[疑问\]', content)[-1] #todo :之后重构到插件里 目前本末倒置了 try: plugin.msg_input(msg=clean_content) except Exception as e: logger.error(str(e)) # 此处对接论坛的webhook # 类似 forum_client.post_thread(username,clean_content) # 其中username为微信用户昵称,clean_content为发帖内容 response = "发帖成功:)" return {'type': 'q', 'response': response} #if '/bot/t' in content: if content.startswith('[得意]'): #回帖 #判断下正则是够合格 thread_id, clean_content = re.split(r'\[得意\].*?(?P<id>\d+)', content)[-2:] response = "回帖成功:)" return {'type': 't', 'response': response} #if '/bot/h' in content: if '[闭嘴]' in content: #help #response='Hi @{} 使用说明如下:\n帮助:[闭嘴]\n发帖:[疑问] 帖子内容\n回帖:[得意](id) 回复内容\n搜索:[惊讶] 问题内容'.format(msg['ActualNickName']) response = 'Hi @{} 使用说明如下:\n帮助:[闭嘴]\n发帖:[疑问] 帖子内容\n回帖:[得意](id) 回复内容'.format( msg['ActualNickName']) return {'type': 'h', 'response': response} return {'type': None, 'response': None}
def handle_text_msg(msg): global IN_ACTION # todo 改变调度机制 目前非常不自然 username = msg['ActualNickName'] # 发言者,昵称 content = msg['Text'] userlogo = msg["UserImg"] # 触发 if username in setting.ACTION_ADMIN and setting.ACTION_KEYWORD in content: begin_action() response = "活动开始! 2小时后结束:)" return {'type': 'b', 'response': response} #活动开始 群发 if '[咖啡]' in content and IN_ACTION: #发帖 正则匹配 clean_content = re.split(r'\[咖啡\]', content)[-1] if clean_content: #todo :之后重构到插件里 目前本末倒置了 clean_content = "<span class='api_icon'>![](" + userlogo + ")</span><span class='api_nickname'>" + username + "</span>" + clean_content try: # 丢到线程里 timeout plugin.msg_input(msg=clean_content) except Exception as e: logger.error(str(e)) # 此处对接论坛的webhook # 类似 forum_client.post_thread(username,clean_content) # 其中username为微信用户昵称,clean_content为发帖内容 response = "@{} 提问成功:)".format(username) return {'type': 'q', 'response': response} if content == "论坛机器人说明": broadcasting = "论坛机器人说明:论坛机器人自动转发来自其他群的消息,\ 实现了多个微信群间的即时通讯,作者wwj718,具体设计及技术细节请参考作者文章 \ http://mp.weixin.qq.com/s/QbO2TN_K4gW6l4_nE-cLqw ,\ 以及作者的GitHub:https://github.com/wwj718 \ 在任意群内发送命令“论坛机器人说明”即可将此说明广播到所有群内" return {'type': 'Bot help', 'broadcasting': broadcasting} #if '/bot/t' in content: ''' if content.startswith('[得意]'): #回帖 #判断下正则是够合格 thread_id,clean_content = re.split(r'\[得意\].*?(?P<id>\d+)', content)[-2:] response = "回帖成功:)" return {'type':'t','response':response} ''' #if '/bot/h' in content: if '[疑问]' in content: #help #response='Hi @{} 使用说明如下:\n帮助:[闭嘴]\n发帖:[疑问] 帖子内容\n回帖:[得意](id) 回复内容\n搜索:[惊讶] 问题内容'.format(msg['ActualNickName']) response = 'Hi @{} 使用说明如下:\n帮助:[疑问]\n提问:[咖啡] 问题内容'.format( msg['ActualNickName']) return {'type': 'h', 'response': response} return {'type': None, 'response': None} #无标记
def handle_text_msg(msg): global IN_ACTION # todo 改变调度机制 目前非常不自然 username = msg['ActualNickName'] # 发言者,昵称 content = msg['Text'] userlogo = msg["UserImg"] # 触发 if username in setting.ACTION_ADMIN and setting.ACTION_KEYWORD in content: begin_action() response = "活动开始! 2小时后结束:)" return {'type': 'b', 'response': response} # 活动开始 群发 if '[咖啡]' in content and IN_ACTION: # 发帖 正则匹配 clean_content = re.split(r'\[咖啡\]', content)[-1] if clean_content: # todo :之后重构到插件里 目前本末倒置了 clean_content = "<span class='api_icon'>![](" + userlogo + \ ")</span><span class='api_nickname'>" + username + "</span>" + clean_content try: # 丢到线程里 timeout plugin.msg_input(msg=clean_content) except Exception as e: logger.error(str(e)) # 此处对接论坛的webhook # 类似 forum_client.post_thread(username,clean_content) # 其中username为微信用户昵称,clean_content为发帖内容 response = "@{} 提问成功:)".format(username) return {'type': 'q', 'response': response} # if '/bot/t' in content: ''' if content.startswith('[得意]'): #回帖 #判断下正则是够合格 thread_id,clean_content = re.split(r'\[得意\].*?(?P<id>\d+)', content)[-2:] response = "回帖成功:)" return {'type':'t','response':response} ''' # if '/bot/h' in content: if '[疑问]' in content: # help #response='Hi @{} 使用说明如下:\n帮助:[闭嘴]\n发帖:[疑问] 帖子内容\n回帖:[得意](id) 回复内容\n搜索:[惊讶] 问题内容'.format(msg['ActualNickName']) response = 'Hi @{} 使用说明如下:\n帮助:[疑问]\n提问:[咖啡] 问题内容'.format( msg['ActualNickName']) return {'type': 'h', 'response': response} return {'type': None, 'response': None} # 无标记