添加简单聊天功能

This commit is contained in:
xmengnet 2021-04-22 10:13:00 +08:00 committed by GitHub
parent 78618a282d
commit 64cd37d01e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

20
worker/hello.py Normal file
View file

@ -0,0 +1,20 @@
from zzcore import StdAns
import requests
class Ans(StdAns):
def GETMSG(self):
if len(self.parms) < 2:
return '你好啊!我是小智障机器人,你现在可以使用/hello 你想说的话 跟我聊天!'
question=self.raw_msg['raw_message'][6:]
# print(question)
quest=self.raw_msg['sender']['nickname']
# print(quest)
key='9c0f6f69aa395bad36a0e797ed44189f'
url=f'http://api.tianapi.com/txapi/robot/index?key={key}&question={question}&uniqueid={quest}&mode=1'
reply=requests.get(url).json()
msg=''
if(reply['code']==200):
msg+=reply['newslist'][0]['reply']
else:
msg+='不想和你说话!'
return msg