From 7c0016c4be893fdbbc12ef7a8ed0b26363ebb17c Mon Sep 17 00:00:00 2001 From: SharwOrange Date: Sat, 30 Dec 2023 18:23:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E4=B8=80=E8=A8=80?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect.py | 14 ++--- module/hitokoto/__init__.py | 50 +++++++++++++----- .../__pycache__/__init__.cpython-311.pyc | Bin 470 -> 2304 bytes 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/connect.py b/connect.py index 1455675..e5bbabe 100644 --- a/connect.py +++ b/connect.py @@ -224,18 +224,20 @@ async def add_message(data: Dict[str, Any]): ctypet = content[len("!!hitokoto "):] if content == "!!hitokoto": - result_code, result_data = hitokoto.hitokoto("没有") + result_code, result_data, result_type= hitokoto.hitokoto(None) else: - result_code, result_data = hitokoto.hitokoto(ctypet) + result_code, result_data, result_type= hitokoto.hitokoto(ctypet) 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: - 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: - 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: - 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()) diff --git a/module/hitokoto/__init__.py b/module/hitokoto/__init__.py index 69316d5..a37f290 100644 --- a/module/hitokoto/__init__.py +++ b/module/hitokoto/__init__.py @@ -1,8 +1,10 @@ import requests import random - def hitokoto(ctypet): + + result_type = None + try: if ctypet == '动画' or ctypet == 'a': @@ -15,7 +17,7 @@ def hitokoto(ctypet): ctype = 'd' elif ctypet == '原创' or ctypet == 'e': ctype = 'e' - elif ctypet == '网络' or ctypet == 'f': + elif ctypet == '来自网络' or ctypet == 'f': ctype = 'f' elif ctypet == '其他' or ctypet == 'g': ctype = 'g' @@ -29,24 +31,48 @@ def hitokoto(ctypet): ctype = 'k' elif ctypet == '抖机灵' or ctypet == 'l': ctype = 'l' - - elif ctypet == '没有': + elif ctypet == None: ctype = random.choice('abcdefghijkl') - params_value = {'c': ctype} - hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value) - - return 0, hitokoto.json() + elif ctypet == 'help': + return 1, None, result_type else: - return 3, None + return 3, None, result_type params_value = {'c': ctype} 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: - return 2, None - + return 2, None, result_type diff --git a/module/hitokoto/__pycache__/__init__.cpython-311.pyc b/module/hitokoto/__pycache__/__init__.cpython-311.pyc index 2ae9f3e3ea77a5aa6ffe2fd3ce7ab2e76d740840..551b3d868fa6fe90ac3df9f7341a951c82617be1 100644 GIT binary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