summaryrefslogtreecommitdiff
path: root/ATRI/plugins/code_runner/data_source.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-07-31 16:16:47 +0800
committerKyomotoi <[email protected]>2021-07-31 16:16:47 +0800
commit336eb9d9e98b0bee952c27a50820dbdb350bcc03 (patch)
tree718d5349232bce0d06cc901707bdd8f478c43314 /ATRI/plugins/code_runner/data_source.py
parentc485985d3be687d17168512de44ea7b744fea7cc (diff)
downloadATRI-336eb9d9e98b0bee952c27a50820dbdb350bcc03.tar.gz
ATRI-336eb9d9e98b0bee952c27a50820dbdb350bcc03.tar.bz2
ATRI-336eb9d9e98b0bee952c27a50820dbdb350bcc03.zip
🔥🚚✨
- 移除:laugh.txt,需要时再拉取 - 移动控制台文件至plugins/console目录下 - 新增: - 和管理贴贴w - 正式的可视化前端单页
Diffstat (limited to 'ATRI/plugins/code_runner/data_source.py')
-rw-r--r--ATRI/plugins/code_runner/data_source.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/ATRI/plugins/code_runner/data_source.py b/ATRI/plugins/code_runner/data_source.py
index 4338697..bbe0d2e 100644
--- a/ATRI/plugins/code_runner/data_source.py
+++ b/ATRI/plugins/code_runner/data_source.py
@@ -40,9 +40,10 @@ __doc__ = """
class CodeRunner(Service):
+
def __init__(self):
Service.__init__(self, "在线跑代码", __doc__, rule=is_in_service("在线跑代码"))
-
+
@staticmethod
def help() -> str:
return (
@@ -52,23 +53,23 @@ class CodeRunner(Service):
"/code python\n"
"print('hello world')"
)
-
+
@staticmethod
def list_supp_lang() -> str:
msg0 = "咱现在支持的语言如下:\n"
msg0 += ", ".join(map(str, SUPPORTED_LANGUAGES.keys()))
return msg0
-
+
@staticmethod
async def runner(msg: str):
args = msg.split("\n")
if not args:
return "请检查键入内容..."
-
+
lang = args[0].replace("\r", "")
if lang not in SUPPORTED_LANGUAGES:
return "该语言暂不支持..."
-
+
del args[0]
code = "\n".join(map(str, args))
url = RUN_API_URL_FORMAT.format(lang)
@@ -83,14 +84,14 @@ class CodeRunner(Service):
}
],
"stdin": "",
- "command": "",
+ "command": ""
}
-
+
try:
res = await request.post(url, json=js)
except RequestError:
raise RequestError("Request failed!")
-
+
payload = await res.json()
sent = False
for k in ["stdout", "stderr", "error"]:
@@ -99,12 +100,12 @@ class CodeRunner(Service):
lines, remained_lines = lines[:10], lines[10:]
out = "\n".join(lines)
out, remained_out = out[: 60 * 10], out[60 * 10 :]
-
+
if remained_lines or remained_out:
out += f"\n(太多了太多了...)"
-
+
if out:
return f"\n{k}:\n{out}"
-
+
if not sent:
- return "\n运行完成,没任何输出呢..."
+ return "\n运行完成,没任何输出呢..." \ No newline at end of file