From 43a79b3f1c04178c7034a6abbd2ef4b2f7b2283d Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 4 Oct 2023 16:24:45 +0800 Subject: [PATCH] =?UTF-8?q?F=20|=20=E9=98=B2=E6=AD=A2=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/types.py | 17 +++++++++++++++++ connect.py | 5 ++++- main.py | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 bot/types.py create mode 100644 main.py diff --git a/bot/types.py b/bot/types.py new file mode 100644 index 0000000..33cd801 --- /dev/null +++ b/bot/types.py @@ -0,0 +1,17 @@ + +from lib_not_dr.types import Options + + +class SocketData(Options): + name = 'SocketData' + + def to_json(self) -> dict: + return self.option() + + +class AddMessage(SocketData): + name = 'icalingua socket add message event' + + roomId: int + + diff --git a/connect.py b/connect.py index 9f46361..c631182 100644 --- a/connect.py +++ b/connect.py @@ -188,7 +188,10 @@ async def add_message(data: Dict[str, Any]): elif data.get('message').get('content').startswith('=='): evals: str = data.get('message').get('content')[2:] - result = await safe_eval(evals) + try: + result = await asyncio.wait_for(safe_eval(evals), 5) + except asyncio.TimeoutError: + result = f'{evals}\n超时' reply = ReplyMessage(id=data['message']['_id']) message = Message(content=result, reply_to=reply, diff --git a/main.py b/main.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/main.py @@ -0,0 +1 @@ +