F | 防止超时

This commit is contained in:
shenjack 2023-10-04 16:24:45 +08:00
parent 8584c6c6fd
commit 43a79b3f1c
Signed by: shenjack
GPG Key ID: 7B1134A979775551
3 changed files with 22 additions and 1 deletions

17
bot/types.py Normal file
View File

@ -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

View File

@ -188,7 +188,10 @@ async def add_message(data: Dict[str, Any]):
elif data.get('message').get('content').startswith('=='): elif data.get('message').get('content').startswith('=='):
evals: str = data.get('message').get('content')[2:] 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']) reply = ReplyMessage(id=data['message']['_id'])
message = Message(content=result, message = Message(content=result,
reply_to=reply, reply_to=reply,

1
main.py Normal file
View File

@ -0,0 +1 @@