wxBot

itchat

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
# -*- encoding:utf-8 -*-
import requests
import itchat

KEY = '334c99571f96486683dde04cc998ac56'

def get_response(msg):
question = msg.replace("@毛毛球", "")
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
'key' : KEY,
'info' : question,
'userid' : 'wechat-robot',
}
try:
r = requests.post(apiUrl, data=data).json()
return r.get('text')
except:
return ""

@itchat.msg_register(itchat.content.TEXT, isGroupChat=True)
def group_reply(msg):
if msg['isAt']:
itchat.send(u'@%s\u2005 %s' % (msg['ActualNickName'], get_response(msg['Content'])), msg['FromUserName'])

itchat.auto_login(hotReload=True)
itchat.run()
Contents
,