From b6d58cf9fce591ca8fea9637936ddb2d69eb11e9 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Tue, 3 Oct 2023 21:30:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A1=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 +++++- connect.py | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 239a4858..d85c83b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ /venv -config.toml \ No newline at end of file +config.toml + +# Added by cargo + +/target diff --git a/connect.py b/connect.py index a42f135d..35582b2d 100644 --- a/connect.py +++ b/connect.py @@ -1,3 +1,4 @@ +import time import random import asyncio import traceback @@ -127,12 +128,13 @@ async def safe_eval(code: str) -> str: code = code.replace('exit', '好坏!\n') code = code.replace('eval', '啊哈!\n') code = code.replace('exec', '抓住!\n') + start_time = time.time() try: import os import math - import random import decimal - global_val = {'math': math, + global_val = {'time': time, + 'math': math, 'decimal': decimal, 'random': random, '__import__': '', @@ -151,6 +153,7 @@ async def safe_eval(code: str) -> str: result = result[:limit] except: result = traceback.format_exc() + end_time = time.time() result = result.replace(KEY, '***') result = result.replace(HOST, '***') @@ -159,7 +162,7 @@ async def safe_eval(code: str) -> str: if result == '6' or result == 6: result = '他确实等于 6' - result = f'{code}\neval result:\n{result}' + result = f'{code}\neval result:\n{result}\n耗时: {end_time - start_time} s' return result except: error = traceback.format_exc()