From 6b7a6481a29dc633b29137bad21f66a933dab392 Mon Sep 17 00:00:00 2001 From: BadHappy <1196554262@qq.com> Date: Sat, 30 Dec 2023 17:27:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-temp.toml | 7 +- connect.py | 14 ++-- module/hitokoto/__init__.py | 73 ++++++++++-------- .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 470 bytes .../__pycache__/__init__.cpython-39.pyc | Bin 0 -> 1025 bytes 5 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 module/hitokoto/__pycache__/__init__.cpython-311.pyc create mode 100644 module/hitokoto/__pycache__/__init__.cpython-39.pyc diff --git a/config-temp.toml b/config-temp.toml index 911b78b..5ff2239 100644 --- a/config-temp.toml +++ b/config-temp.toml @@ -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 号 diff --git a/connect.py b/connect.py index 82e04a4..1455675 100644 --- a/connect.py +++ b/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']) diff --git a/module/hitokoto/__init__.py b/module/hitokoto/__init__.py index d27294a..69316d5 100644 --- a/module/hitokoto/__init__.py +++ b/module/hitokoto/__init__.py @@ -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 diff --git a/module/hitokoto/__pycache__/__init__.cpython-311.pyc b/module/hitokoto/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2ae9f3e3ea77a5aa6ffe2fd3ce7ab2e76d740840 GIT binary patch literal 470 zcmZ3^%ge<81fMterxpY0#~=<2FhLogMSzUy3@HpLj5!QZ3@J=43{i|JjKK_=%r8Mo z{F0#x!4xx)1mVwNKw>&W2_sk(Ok}~?DU8d2?A367Ekg+_LR}3*7RUrJKvl;GbOq2} zCci4NjFOUqVk>?9GDE$L%#!@<{E~dVB(RziETVT^7y`jUL^L zED~2(Brd?vXP{c3ABtFj6xf873`L+=DB=VXzc_3lw%Qf(0J$JX7OMk^56p~=j5iqg S8^G`b3lpQ{2L?<6Y!Co)17*Sh literal 0 HcmV?d00001 diff --git a/module/hitokoto/__pycache__/__init__.cpython-39.pyc b/module/hitokoto/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..68862f7ae56d61b9c00a7062d715a63e559111ae GIT binary patch literal 1025 zcma)*%TE(g6vpqlGmHfbRz&2bu4@F;r7?#1h`PZAiI1kS4!wmAEi-jyN&=w^4Jttq z2nLB_1Q$MHd`Due#*K01UvQ%?R9e^>6BCzyGb0I0@8sNXzTdg$-07XEUR_PY@LK$H(E~tw|)fKE@ok{ZK-#|weLL5XmXOWqt zp##I{lHpDrlxMizB6xu&$<*K#@SRWhT&@kwj2!qbTRfFDy)_~578qf=H8$h2yBcO{S0-A-}2>KCP z3;Idaf}Vie1o|0T2l`Fafp)-c2K@!C2mK@JL3hAy$?!>X!nkYj?(AC8fK0??^CTJ< zs6Z!~XzIeR943Pb+~s|WXddRGWtteg` zR`3?Kcjh%5_R`pc^7W!5-FKz8k9^l1xYw^sqZ5*nft$I!^!T165!79~vov~3Qp$Jb zcT?r!oTQ#0cX9DYaYj;a;NCr7zJEzl+IP!OZ!A9@mt^ECu{-KYv(rD`OiAhs7EizM zH_7X%wFZ5hdw4B4r3`IO^2Qt3^(QtfjrQ?5I9 z{IG3Xc2vbWcQA)Ug|D%2&^0ljXY(jt-SQ!`o3O#}BbW~Djh9~*%f&lOSKi}zVVH)SNVMe!?MC#fKsX(k7^yr$ zA&QXpUr|RIuR?^VhT|f?TU4<(p_RSSo4oe^L$8^d!DMJ(@KpP~lXLukCWVy0citpJ literal 0 HcmV?d00001