main #1
|
@ -1,5 +1,4 @@
|
|||
|
||||
private_key = "d76a25fea1d5c3c8ccfdb31179798f31f87a2afc7e8feda3f67d515790ee9ee5" # 与 icalingua 客户端使用的 private_key 一致
|
||||
host = "http://192.168.1.6:6789" # docker 版 icalingua 服务的地址
|
||||
self_id = 2163534756 # 机器人的 qq 号
|
||||
|
||||
private_key = "" # 与 icalingua 客户端使用的 private_key 一致
|
||||
host = "" # docker 版 icalingua 服务的地址
|
||||
self_id = 0 # 机器人的 qq 号
|
||||
|
|
14
connect.py
14
connect.py
|
@ -18,7 +18,7 @@ from module import hitokoto
|
|||
# 功能包结束引用
|
||||
|
||||
def get_config() -> Tuple[str, str, int]:
|
||||
with open('config-temp.toml', 'r', encoding='utf-8') as f:
|
||||
with open('config.toml', 'r', encoding='utf-8') as f:
|
||||
config = qtoml.load(f)
|
||||
return config['host'], config['private_key'], config['self_id']
|
||||
|
||||
|
@ -220,16 +220,20 @@ async def add_message(data: Dict[str, Any]):
|
|||
|
||||
await sio.emit('sendMessage', message.to_json())
|
||||
|
||||
elif content.startswith("!!hitokoto "):
|
||||
elif content.startswith("!!hitokoto"):
|
||||
|
||||
ctypet = content[len("!!hitokoto "):]
|
||||
|
||||
result_code, result_data = hitokoto.hitokoto(ctypet)
|
||||
if content == "!!hitokoto":
|
||||
result_code, result_data = hitokoto.hitokoto("没有")
|
||||
else:
|
||||
result_code, result_data = hitokoto.hitokoto(ctypet)
|
||||
|
||||
if result_code == 3:
|
||||
message = Message(content=f"参数不对哦!",room_id=data['roomId'])
|
||||
elif result_code == 2:
|
||||
message = Message(content=f"发生了不可描述的错误X_X", room_id=data['roomId'])
|
||||
elif result_code == 0:
|
||||
message = Message(f"Hitokoto: {result_data['hitokoto']}")
|
||||
message = Message(content=f"Hitokoto: {result_data['hitokoto']}", room_id=data['roomId'])
|
||||
else:
|
||||
message = Message(content=f"但你看到这条消息就代表有bug出炉", room_id=data['roomId'])
|
||||
|
||||
|
|
|
@ -3,41 +3,50 @@ import random
|
|||
|
||||
|
||||
def hitokoto(ctypet):
|
||||
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'
|
||||
elif ctypet == '网络' or ctypet == 'f':
|
||||
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'
|
||||
else:
|
||||
ctype = random.choice('abcdefghijkl')
|
||||
return 3, None
|
||||
try:
|
||||
|
||||
params_value = {'c': ctype}
|
||||
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
||||
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'
|
||||
elif ctypet == '网络' or ctypet == 'f':
|
||||
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'
|
||||
|
||||
return 0, hitokoto.json()
|
||||
elif ctypet == '没有':
|
||||
ctype = random.choice('abcdefghijkl')
|
||||
params_value = {'c': ctype}
|
||||
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
||||
|
||||
return 0, hitokoto.json()
|
||||
else:
|
||||
return 3, None
|
||||
|
||||
params_value = {'c': ctype}
|
||||
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
||||
|
||||
return 0, hitokoto.json()
|
||||
|
||||
except IOError:
|
||||
return 2, None
|
||||
|
||||
# except Exception as e:
|
||||
# return 2, None
|
||||
|
||||
|
||||
|
||||
|
|
BIN
module/hitokoto/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
module/hitokoto/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
module/hitokoto/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
module/hitokoto/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user