From ec3962306e5ccc17f89f87e2640afa420b696d93 Mon Sep 17 00:00:00 2001 From: BadHappy <1196554262@qq.com> Date: Sat, 30 Dec 2023 09:38:34 +0000 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/connect.py b/connect.py index a9d2428..1455675 100644 --- a/connect.py +++ b/connect.py @@ -14,6 +14,7 @@ from mcstatus import JavaServer # 功能包引用处 from module import hitokoto + # 功能包结束引用 def get_config() -> Tuple[str, str, int]: @@ -218,14 +219,25 @@ async def add_message(data: Dict[str, Any]): message = Message(content=f"此服务器当前在线玩家有 {players}",room_id=data['roomId']) await sio.emit('sendMessage', message.to_json()) - - elif content == f'!!hitokoto {ctypet}': - hitokoto.hitokoto(ctypet) - result_code, result_data = hitokoto.hitokoto() + + elif content.startswith("!!hitokoto"): + + ctypet = content[len("!!hitokoto "):] + 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']) - if result_code == 0: - message = Message(f"Hitokoto: {result_data['hitokoto']}") + 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(content=f"Hitokoto: {result_data['hitokoto']}", room_id=data['roomId']) + else: + message = Message(content=f"但你看到这条消息就代表有bug出炉", room_id=data['roomId']) + + await sio.emit('sendMessage', message.to_json()) elif data.get('message').get('content').startswith('=='):