mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 12:41:05 +08:00
F | 防止超时
This commit is contained in:
parent
8584c6c6fd
commit
43a79b3f1c
17
bot/types.py
Normal file
17
bot/types.py
Normal 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
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user