-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
executable file
·43 lines (36 loc) · 1.33 KB
/
bot.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
# --coding:utf-8--
import commands
import message_xml
def do_specialText(userInfo):
"""
检查用户的消息内容,如果出现关键词,则回复关键词对应的内容。
:param userInfo: 用户的信息,为微信发送过来的xml信息,dict类型
:return: 如果关键词被执行,返回需要发送的xml内容, 否则返回空字符串
"""
# 提取出用户需要的信息
specialText = userInfo.find("Content").text
# 用户信息按空格分割
specialText_list = specialText.split()
# 处理需要发送的微信内容头部
article = message_xml.Message(userInfo)
print(specialText)
# 检查关键词是否被执行成功
check = commands.process_input_info(specialText_list, article)
if check:
# 执行成功,返回xml文本
return article.generateMessage()
else:
# 否则,返回空字符串
return ""
# info = '''<xml>
# <ToUserName><![CDATA[toUser]]></ToUserName>
# <FromUserName><![CDATA[fromUser]]></FromUserName>
# <CreateTime>1348831860</CreateTime>
# <MsgType><![CDATA[text]]></MsgType>
# <Content><![CDATA[bq 动漫]]></Content>
# <MsgId>1234567890123456</MsgId>
# </xml>'''
#
# from lxml import etree
# userInfo = etree.XML(info)
# print(do_specialText(userInfo))