换回safe eval
This commit is contained in:
parent
56adb6628c
commit
bc5d233e31
37
main.py
37
main.py
@ -163,35 +163,26 @@ async def add_message(data: Dict[str, Any]):
|
|||||||
|
|
||||||
if not is_self:
|
if not is_self:
|
||||||
if content == '/bot':
|
if content == '/bot':
|
||||||
message = Message(content='icalingua bot test',
|
message = Message(content=f'icalingua bot test v{_version_}',
|
||||||
room_id=data['roomId'])
|
room_id=data['roomId'],
|
||||||
|
reply_to=ReplyMessage(id=data['message']['_id']))
|
||||||
await sio.emit('sendMessage', message.to_json())
|
await sio.emit('sendMessage', message.to_json())
|
||||||
elif content.startswith('=='):
|
elif content.startswith('=='):
|
||||||
|
|
||||||
evals: str = content[2:]
|
evals: str = content[2:]
|
||||||
|
|
||||||
# quene = multiprocessing.Queue()
|
result = safe_eval(evals)
|
||||||
# def run(quene, evals):
|
# whitelist = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', '.', '+', '-', '*', '/', '(', ')', '<',
|
||||||
# go = safe_eval(evals)
|
# '>', '=']
|
||||||
# quene.put(go)
|
# evals = evals.replace('**', '')
|
||||||
# process = multiprocessing.Process(target=run, args=(quene, evals))
|
# express = ''
|
||||||
# process.start()
|
# for text in evals:
|
||||||
# process.join(1)
|
# if text in whitelist:
|
||||||
# if quene.empty():
|
# express += text
|
||||||
# result = '超时'
|
# if express == '':
|
||||||
|
# result = '你在干嘛'
|
||||||
# else:
|
# else:
|
||||||
# result = quene.get()
|
# result = str(eval(express))
|
||||||
whitelist = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', '.', '+', '-', '*', '/', '(', ')', '<',
|
|
||||||
'>', '=']
|
|
||||||
evals = evals.replace('**', '')
|
|
||||||
express = ''
|
|
||||||
for text in evals:
|
|
||||||
if text in whitelist:
|
|
||||||
express += text
|
|
||||||
if express == '':
|
|
||||||
result = '你在干嘛'
|
|
||||||
else:
|
|
||||||
result = str(eval(express))
|
|
||||||
|
|
||||||
reply = ReplyMessage(id=data['message']['_id'])
|
reply = ReplyMessage(id=data['message']['_id'])
|
||||||
message = Message(content=result,
|
message = Message(content=result,
|
||||||
|
Loading…
Reference in New Issue
Block a user