byby safe eval

This commit is contained in:
shenjack 2023-10-15 12:33:01 +08:00
parent 6200a18b82
commit 8dfbf1d7ab
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -175,7 +175,7 @@ def safe_eval(code: str) -> str:
async def add_message(data: Dict[str, Any]):
print(f"{Fore.MAGENTA}add_message: {data}{Style.RESET_ALL}")
is_self = data['message']['senderId'] == SELF_ID or data['message']['senderId'] == 2524423915
is_self = data['message']['senderId'] == SELF_ID
sender_name = data['message']['username']
sender_id = data['message']['senderId']
content = data['message']['content']
@ -190,18 +190,28 @@ async def add_message(data: Dict[str, Any]):
evals: str = data.get('message').get('content')[2:]
quene = multiprocessing.Queue()
def run(quene, evals):
go = safe_eval(evals)
quene.put(go)
process = multiprocessing.Process(target=run, args=(quene, evals))
process.start()
process.join(1)
if quene.empty():
result = '超时'
# quene = multiprocessing.Queue()
# def run(quene, evals):
# go = safe_eval(evals)
# quene.put(go)
# process = multiprocessing.Process(target=run, args=(quene, evals))
# process.start()
# process.join(1)
# if quene.empty():
# result = '超时'
# else:
# result = quene.get()
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 = quene.get()
result = str(eval(express))
reply = ReplyMessage(id=data['message']['_id'])
message = Message(content=result,