import requests
import itchat
KEY = 'ca098ebe818b49df98af997bef29b3b3'
def get_response(msg):
Url = 'http://www.tuling123.com/openapi/api'
data = {
'key' : KEY,
'info' : msg,
'userid' : 'pth-robot',
}
try:
r = requests.post(Url, data=data).json()
return r.get('text')
except:
return
@itchat.msg_register(itchat.content.TEXT)
def tuling_reply(msg):
defaultReply = '不想理你了'
reply = get_response(msg['Text'])
return reply or defaultReply
@itchat.msg_register(itchat.content.TEXT, isGroupChat=True)
def text_reply(msg):
if msg['isAt']:
defaultReply='机器人故障中...'
reply = get_response(msg['Text'])
if reply==None:
reply=defaultReply
reply="@%s\u2005"%(msg['ActualNickName'])+reply
return reply
itchat.auto_login(hotReload=True)
itchat.run()