2023-12-30 16:51:39 +08:00
|
|
|
import requests
|
|
|
|
import random
|
|
|
|
|
|
|
|
def hitokoto(ctypet):
|
2023-12-31 08:40:06 +08:00
|
|
|
|
|
|
|
result_type = None
|
|
|
|
|
2023-12-30 17:27:02 +08:00
|
|
|
try:
|
|
|
|
|
|
|
|
if ctypet == '动画' or ctypet == 'a':
|
|
|
|
ctype = 'a'
|
|
|
|
elif ctypet == '漫画' or ctypet == 'b':
|
|
|
|
ctype = 'b'
|
|
|
|
elif ctypet == '游戏' or ctypet == 'c':
|
|
|
|
ctype = 'c'
|
|
|
|
elif ctypet == '文学' or ctypet == 'd':
|
|
|
|
ctype = 'd'
|
|
|
|
elif ctypet == '原创' or ctypet == 'e':
|
|
|
|
ctype = 'e'
|
2023-12-31 08:40:06 +08:00
|
|
|
elif ctypet == '来自网络' or ctypet == 'f':
|
2023-12-30 17:27:02 +08:00
|
|
|
ctype = 'f'
|
|
|
|
elif ctypet == '其他' or ctypet == 'g':
|
|
|
|
ctype = 'g'
|
|
|
|
elif ctypet == '影视' or ctypet == 'h':
|
|
|
|
ctype = 'h'
|
|
|
|
elif ctypet == '诗词' or ctypet == 'i':
|
|
|
|
ctype = 'i'
|
|
|
|
elif ctypet == '网易云' or ctypet == 'j':
|
|
|
|
ctype = 'j'
|
|
|
|
elif ctypet == '哲学' or ctypet == 'k':
|
|
|
|
ctype = 'k'
|
|
|
|
elif ctypet == '抖机灵' or ctypet == 'l':
|
|
|
|
ctype = 'l'
|
2023-12-31 08:40:06 +08:00
|
|
|
elif ctypet == None:
|
2023-12-30 17:27:02 +08:00
|
|
|
ctype = random.choice('abcdefghijkl')
|
2023-12-31 08:40:06 +08:00
|
|
|
elif ctypet == 'help':
|
|
|
|
return 1, None, result_type
|
2023-12-30 17:27:02 +08:00
|
|
|
else:
|
2023-12-31 08:40:06 +08:00
|
|
|
return 3, None, result_type
|
2023-12-30 17:27:02 +08:00
|
|
|
|
|
|
|
params_value = {'c': ctype}
|
|
|
|
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
|
|
|
|
2023-12-31 08:40:06 +08:00
|
|
|
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 = '无法获取'
|
2023-12-30 17:27:02 +08:00
|
|
|
|
2023-12-31 08:40:06 +08:00
|
|
|
return 0, hitokoto.json(), result_type
|
|
|
|
|
2023-12-30 17:27:02 +08:00
|
|
|
except IOError:
|
2023-12-31 08:40:06 +08:00
|
|
|
return 2, None, result_type
|
2023-12-30 16:51:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|