mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-20 21:39:54 +08:00
Compare commits
No commits in common. "28ec8d316dbe264aaaf93c04d948ed9e91d44950" and "1f7ffcb2d4d1ecaf662e43cc7ed70848713db061" have entirely different histories.
28ec8d316d
...
1f7ffcb2d4
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ica-rs"
|
name = "ica-rs"
|
||||||
version = "0.4.9"
|
version = "0.4.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -136,12 +136,7 @@ def bmcl_rank(msg: NewMessage, client: IcaClient, name: Optional[str]) -> None:
|
||||||
else:
|
else:
|
||||||
# 搜索是否有这个名字的节点
|
# 搜索是否有这个名字的节点
|
||||||
names = [r["name"].lower() for r in ranks]
|
names = [r["name"].lower() for r in ranks]
|
||||||
try:
|
|
||||||
finds = [re.search(name.lower(), n) for n in names]
|
finds = [re.search(name.lower(), n) for n in names]
|
||||||
except re.error as e:
|
|
||||||
reply = msg.reply_with(f"正则表达式错误: {e}, 请检查输入")
|
|
||||||
client.send_message(reply)
|
|
||||||
return
|
|
||||||
if not any(finds):
|
if not any(finds):
|
||||||
reply = msg.reply_with(f"未找到名为{name}的节点")
|
reply = msg.reply_with(f"未找到名为{name}的节点")
|
||||||
client.send_message(reply)
|
client.send_message(reply)
|
||||||
|
@ -183,13 +178,7 @@ def bmcl_rank(msg: NewMessage, client: IcaClient, name: Optional[str]) -> None:
|
||||||
|
|
||||||
help = """/bmcl -> dashboard
|
help = """/bmcl -> dashboard
|
||||||
/bmcl rank -> all rank
|
/bmcl rank -> all rank
|
||||||
/bmcl rank <name> -> rank of <name>
|
/bmcl rank <name> -> rank of <name>"""
|
||||||
/brrs <name> -> rank of <name>
|
|
||||||
搜索限制:
|
|
||||||
1- 3 显示全部信息
|
|
||||||
4-10 显示状态、名称
|
|
||||||
11+ 不显示
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def on_message(msg: NewMessage, client: IcaClient) -> None:
|
def on_message(msg: NewMessage, client: IcaClient) -> None:
|
||||||
|
@ -205,12 +194,3 @@ def on_message(msg: NewMessage, client: IcaClient) -> None:
|
||||||
else:
|
else:
|
||||||
reply = msg.reply_with(help)
|
reply = msg.reply_with(help)
|
||||||
client.send_message(reply)
|
client.send_message(reply)
|
||||||
elif msg.content.startswith("/brrs"):
|
|
||||||
if msg.content == "/brrs":
|
|
||||||
reply = msg.reply_with(help)
|
|
||||||
client.send_message(reply)
|
|
||||||
else:
|
|
||||||
name = msg.content.split(" ")
|
|
||||||
if len(name) > 1:
|
|
||||||
name = name[1]
|
|
||||||
bmcl_rank(msg, client, name)
|
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
import time
|
|
||||||
import random
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, TypeVar
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ica_typing import NewMessage, IcaClient
|
|
||||||
else:
|
|
||||||
NewMessage = TypeVar("NewMessage")
|
|
||||||
IcaClient = TypeVar("IcaClient")
|
|
||||||
|
|
||||||
def safe_eval(code: str) -> str:
|
|
||||||
try:
|
|
||||||
# code = code.replace('help', '坏东西!\n')
|
|
||||||
# code = code.replace('bytes', '坏东西!\n')
|
|
||||||
# code = code.replace('encode', '坏东西!\n')
|
|
||||||
# code = code.replace('decode', '坏东西!\n')
|
|
||||||
# code = code.replace('compile', '屑的!\n')
|
|
||||||
# code = code.replace('globals', '拿不到!\n')
|
|
||||||
code = code.replace("os", "坏东西!\n")
|
|
||||||
code = code.replace("sys", "坏东西!\n")
|
|
||||||
# code = code.replace('input', '坏东西!\n')
|
|
||||||
# code = code.replace('__', '啊哈!\n')
|
|
||||||
# code = code.replace('import', '很坏!\n')
|
|
||||||
code = code.replace(" kill", "别跑!\n")
|
|
||||||
code = code.replace(" rm ", "别跑!\n")
|
|
||||||
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 decimal
|
|
||||||
|
|
||||||
global_val = {
|
|
||||||
"time": time,
|
|
||||||
"math": math,
|
|
||||||
"decimal": decimal,
|
|
||||||
"random": random,
|
|
||||||
"__import__": "<built-in function __import__>",
|
|
||||||
"globals": "<built-in function globals>",
|
|
||||||
"compile": "<built-in function compile>",
|
|
||||||
"help": "<built-in function help>",
|
|
||||||
"exit": "<built-in function exit>",
|
|
||||||
"input": "<built-in function input>",
|
|
||||||
"return": "别惦记你那个 return 了",
|
|
||||||
"getattr": "<built-in function getattr>",
|
|
||||||
"setattr": "<built-in function setattr>",
|
|
||||||
}
|
|
||||||
os.system = "不许"
|
|
||||||
result = str(eval(code, global_val, {}))
|
|
||||||
limit = 500
|
|
||||||
if len(result) > limit:
|
|
||||||
result = result[:limit]
|
|
||||||
except:
|
|
||||||
result = traceback.format_exc()
|
|
||||||
end_time = time.time()
|
|
||||||
|
|
||||||
if result == "6" or result == 6:
|
|
||||||
result = "他确实等于 6"
|
|
||||||
|
|
||||||
result = f"{code}\neval result:\n{result}\n耗时: {end_time - start_time} s"
|
|
||||||
return result
|
|
||||||
except:
|
|
||||||
error = traceback.format_exc()
|
|
||||||
result = f"error:\n{error}"
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def on_message(message: NewMessage, client: IcaClient) -> None:
|
|
||||||
if not (message.is_from_self or message.is_reply):
|
|
||||||
if message.content.startswith("/="):
|
|
||||||
code = message.content[2:]
|
|
||||||
result = safe_eval(code)
|
|
||||||
reply = message.reply_with(result)
|
|
||||||
client.send_message(reply)
|
|
|
@ -214,12 +214,7 @@ pub async fn new_message_py(message: &NewMessage, client: &Client) {
|
||||||
let async_py_func = py_module.getattr(py, "on_message");
|
let async_py_func = py_module.getattr(py, "on_message");
|
||||||
match async_py_func {
|
match async_py_func {
|
||||||
Ok(async_py_func) => {
|
Ok(async_py_func) => {
|
||||||
match async_py_func.as_ref(py).call1(args) {
|
async_py_func.as_ref(py).call1(args).unwrap();
|
||||||
Err(e) => {
|
|
||||||
warn!("get a PyErr when call on_message from {:?}: {:?}", path, e);
|
|
||||||
},
|
|
||||||
_ => ()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("failed to get on_message function: {:?}", e);
|
warn!("failed to get on_message function: {:?}", e);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user