This commit is contained in:
shenjack-5600u 2024-05-05 22:27:41 +08:00
parent a47c66202b
commit 69da7f4f00
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F

View File

@ -8,19 +8,25 @@ from typing import TYPE_CHECKING, TypeVar
if TYPE_CHECKING: if TYPE_CHECKING:
from ica_typing import IcaNewMessage, IcaClient, ConfigData from ica_typing import IcaNewMessage, IcaClient, ConfigData
CONFIG_DATA: ConfigData CONFIG_DATA: ConfigData
else: else:
CONFIG_DATA = None # type: ignore CONFIG_DATA = None # type: ignore
IcaNewMessage = TypeVar("NewMessage") IcaNewMessage = TypeVar("NewMessage")
IcaClient = TypeVar("IcaClient") IcaClient = TypeVar("IcaClient")
_version_ = "0.0.1" _version_ = "0.0.1"
def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None: def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
if not msg.content.startswith("/name"): if not msg.content.startswith("/name"):
return return
if msg.content.find("\n") == -1: if msg.content.find("\n") == -1:
client.send_message(msg.reply_with("请使用 /name 命令,然后换行输入名字,例如:\n/name\n张三\n李四\n王五\n")) client.send_message(
msg.reply_with(
"请使用 /name 命令,然后换行输入名字,例如:\n/name\n张三\n李四\n王五\n"
)
)
return return
# 去掉 /name # 去掉 /name
names = msg.content.split("/name")[1] names = msg.content.split("/name")[1]
@ -36,13 +42,19 @@ def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
# 执行 node md5.js # 执行 node md5.js
runner_path = root_path / "md5" / "md5.js" runner_path = root_path / "md5" / "md5.js"
input_path = root_path / "md5" / "input.txt" input_path = root_path / "md5" / "input.txt"
result = subprocess.run(["node", runner_path.absolute(), input_path.absolute()], stdout=subprocess.PIPE) result = subprocess.run(
["node", runner_path.absolute(), input_path.absolute()],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
# 获取结果 # 获取结果
out_result = result.stdout.decode("utf-8") out_result = result.stdout.decode("utf-8")
err_result = result.stderr.decode("utf-8") err_result = result.stderr.decode("utf-8")
# 发送结果 # 发送结果
end_time = time.time() end_time = time.time()
reply = msg.reply_with(f"{out_result}\n{err_result}\n耗时:{end_time - start_time:.2f}s\n版本:{_version_}") reply = msg.reply_with(
f"{out_result}\n{err_result}\n耗时:{end_time - start_time:.2f}s\n版本:{_version_}"
)
client.send_message(reply) client.send_message(reply)
except Exception as e: except Exception as e:
# 发送错误 # 发送错误