完善了一言功能
This commit is contained in:
parent
88260597b9
commit
7c0016c4be
14
connect.py
14
connect.py
|
@ -224,18 +224,20 @@ async def add_message(data: Dict[str, Any]):
|
||||||
|
|
||||||
ctypet = content[len("!!hitokoto "):]
|
ctypet = content[len("!!hitokoto "):]
|
||||||
if content == "!!hitokoto":
|
if content == "!!hitokoto":
|
||||||
result_code, result_data = hitokoto.hitokoto("没有")
|
result_code, result_data, result_type= hitokoto.hitokoto(None)
|
||||||
else:
|
else:
|
||||||
result_code, result_data = hitokoto.hitokoto(ctypet)
|
result_code, result_data, result_type= hitokoto.hitokoto(ctypet)
|
||||||
|
|
||||||
if result_code == 3:
|
if result_code == 3:
|
||||||
message = Message(content=f"参数不对哦!",room_id=data['roomId'])
|
message = Message(content=f"参数不对哦!你可以输入!!hitokoto help查看帮助",room_id=data['roomId'])
|
||||||
elif result_code == 2:
|
elif result_code == 2:
|
||||||
message = Message(content=f"发生了不可描述的错误X_X", room_id=data['roomId'])
|
message = Message(content=f"发生了不可描述的错误X_X,但可以肯定的是模块炸了(", room_id=data['roomId'])
|
||||||
|
elif result_code == 1:
|
||||||
|
message = Message(content=f"(参数)句子类型如下\na 动画\nb 漫画\nc 游戏\nd 文学\ne 原创\nf 来自网络\ng 其他\nh 影视\ni 诗词\nj 网易云\nk 哲学\nl 抖机灵", room_id=data['roomId'])
|
||||||
elif result_code == 0:
|
elif result_code == 0:
|
||||||
message = Message(content=f"Hitokoto: {result_data['hitokoto']}", room_id=data['roomId'])
|
message = Message(content=f"“{result_data['hitokoto']}”\n类型:{result_type}", room_id=data['roomId'])
|
||||||
else:
|
else:
|
||||||
message = Message(content=f"但你看到这条消息就代表有bug出炉", room_id=data['roomId'])
|
message = Message(content=f"你看到这条消息就代表有bug出炉,但肯定不是模块炸了(", room_id=data['roomId'])
|
||||||
|
|
||||||
await sio.emit('sendMessage', message.to_json())
|
await sio.emit('sendMessage', message.to_json())
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import requests
|
import requests
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
def hitokoto(ctypet):
|
def hitokoto(ctypet):
|
||||||
|
|
||||||
|
result_type = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
if ctypet == '动画' or ctypet == 'a':
|
if ctypet == '动画' or ctypet == 'a':
|
||||||
|
@ -15,7 +17,7 @@ def hitokoto(ctypet):
|
||||||
ctype = 'd'
|
ctype = 'd'
|
||||||
elif ctypet == '原创' or ctypet == 'e':
|
elif ctypet == '原创' or ctypet == 'e':
|
||||||
ctype = 'e'
|
ctype = 'e'
|
||||||
elif ctypet == '网络' or ctypet == 'f':
|
elif ctypet == '来自网络' or ctypet == 'f':
|
||||||
ctype = 'f'
|
ctype = 'f'
|
||||||
elif ctypet == '其他' or ctypet == 'g':
|
elif ctypet == '其他' or ctypet == 'g':
|
||||||
ctype = 'g'
|
ctype = 'g'
|
||||||
|
@ -29,24 +31,48 @@ def hitokoto(ctypet):
|
||||||
ctype = 'k'
|
ctype = 'k'
|
||||||
elif ctypet == '抖机灵' or ctypet == 'l':
|
elif ctypet == '抖机灵' or ctypet == 'l':
|
||||||
ctype = 'l'
|
ctype = 'l'
|
||||||
|
elif ctypet == None:
|
||||||
elif ctypet == '没有':
|
|
||||||
ctype = random.choice('abcdefghijkl')
|
ctype = random.choice('abcdefghijkl')
|
||||||
params_value = {'c': ctype}
|
elif ctypet == 'help':
|
||||||
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
return 1, None, result_type
|
||||||
|
|
||||||
return 0, hitokoto.json()
|
|
||||||
else:
|
else:
|
||||||
return 3, None
|
return 3, None, result_type
|
||||||
|
|
||||||
params_value = {'c': ctype}
|
params_value = {'c': ctype}
|
||||||
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
||||||
|
|
||||||
return 0, hitokoto.json()
|
htype=hitokoto.json()['type']
|
||||||
|
if htype=='a':
|
||||||
|
result_type = '动画'
|
||||||
|
elif htype=='b':
|
||||||
|
result_type = '动漫'
|
||||||
|
elif htype=='c':
|
||||||
|
result_type = '游戏'
|
||||||
|
elif htype=='d':
|
||||||
|
result_type = '文学'
|
||||||
|
elif htype=='e':
|
||||||
|
result_type = '原创'
|
||||||
|
elif htype=='f':
|
||||||
|
result_type = '来自网络'
|
||||||
|
elif htype=='g':
|
||||||
|
result_type = '其他'
|
||||||
|
elif htype=='h':
|
||||||
|
result_type = '影视'
|
||||||
|
elif htype=='i':
|
||||||
|
result_type = '诗词'
|
||||||
|
elif htype=='j':
|
||||||
|
result_type = '网易云'
|
||||||
|
elif htype=='k':
|
||||||
|
result_type = '哲学'
|
||||||
|
elif htype=='l':
|
||||||
|
result_type = '抖机灵'
|
||||||
|
else:
|
||||||
|
result_type = '无法获取'
|
||||||
|
|
||||||
|
return 0, hitokoto.json(), result_type
|
||||||
|
|
||||||
except IOError:
|
except IOError:
|
||||||
return 2, None
|
return 2, None, result_type
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user