#-*-coding:utf8-*-
import json,urllib,urllib2
from qqbot import QQBotSlot as qqbotslot, RunBotdef talk(content,userid):url = 'http://www.tuling123.com/openapi/api's = urllib2.Request(url)da = {"key":"你的Api key","info":content,"userid":userid}da = urllib.urlencode(da)opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())j = eval(opener.open(s,da).read())
# r = s.post(url,data = data)
# j = eval(r.text)code = j['code']if code == 100000:recontent = j['text']elif code == 200000:recontent = j['text']+j['url']elif code == 302000 or code ==308000:recontent = j['text']+j['list'][0]['info']+j['list'][0]['detailurl']elif code == 40004:recontent = '小爱很累了,小爱要去休息了哦'elif code == 40002:recontent = '您有什么想对小爱说的吗?'elif code == 40007:recontent = '输入数据格式异常!'else:recontent = '有问题请找小爱!'return recontent@qqbotslotdef onQQMessage(bot, contact, member, content):if content == '--stop':bot.SendTo(contact,'小爱轻轻地走了!')bot.Stop()else:if getattr(member, 'uin', None) == bot.conf.qq:return()else:if member == None:bot.SendTo(contact,talk(content,contact.qq))elif '@ME' in content:bot.SendTo(contact, '@'+member.name+' '+talk(content,contact.qq))else:return()
RunBot()
#在cmd里运行即可