mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 12:41:05 +08:00
加点料(
This commit is contained in:
parent
ae181425e0
commit
d362e7c155
|
@ -15,3 +15,4 @@ filter_list = [0]
|
|||
|
||||
# python 插件路径
|
||||
py_plugin_path = "/path/to/your/plugin"
|
||||
py_config_path = "/path/to/your/config"
|
||||
|
|
|
@ -19,7 +19,7 @@ colored = "2.1.0"
|
|||
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
futures-util = "0.3.30"
|
||||
pyo3 = "0.20.2"
|
||||
pyo3 = "0.20.3"
|
||||
# pyo3-async = "0.3.2"
|
||||
pyo3-asyncio = { version = "0.20.0", features = ["attributes", "tokio-runtime"] }
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Python 兼容版本 3.8+
|
||||
|
||||
from typing import Callable
|
||||
from typing import Callable, Tuple
|
||||
|
||||
"""
|
||||
pub type RoomId = i64;
|
||||
|
@ -120,11 +120,6 @@ class IcaClient:
|
|||
"""向日志中输出警告信息"""
|
||||
|
||||
|
||||
class ConfigRequest:
|
||||
def __init__(self, path: str, ) -> None:
|
||||
...
|
||||
|
||||
|
||||
class ConfigData:
|
||||
def __getitem__(self, key: str):
|
||||
...
|
||||
|
@ -144,6 +139,6 @@ on_delete_message = Callable[[MessageId, IcaClient], None]
|
|||
# def on_delete_message(msg_id: MessageId, client: IcaClient) -> None:
|
||||
# ...
|
||||
|
||||
config = Callable[[None], ConfigRequest]
|
||||
on_config = Callable[[None], Tuple[str, str]]
|
||||
|
||||
CONFIG_DATA: ConfigData = ConfigData()
|
||||
|
|
|
@ -2,11 +2,13 @@ import re
|
|||
import time
|
||||
import requests
|
||||
|
||||
from typing import TYPE_CHECKING, TypeVar, Optional
|
||||
from typing import TYPE_CHECKING, TypeVar, Optional, Tuple
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ica_typing import NewMessage, IcaClient
|
||||
from ica_typing import NewMessage, IcaClient, ConfigData
|
||||
CONFIG_DATA: ConfigData
|
||||
else:
|
||||
CONFIG_DATA = None
|
||||
NewMessage = TypeVar("NewMessage")
|
||||
IcaClient = TypeVar("IcaClient")
|
||||
|
||||
|
@ -207,6 +209,7 @@ help = """/bmcl -> dashboard
|
|||
|
||||
|
||||
def on_message(msg: NewMessage, client: IcaClient) -> None:
|
||||
print(CONFIG_DATA)
|
||||
if not (msg.is_from_self or msg.is_reply):
|
||||
if msg.content.startswith("/bmcl"):
|
||||
if msg.content == "/bmcl":
|
||||
|
@ -228,3 +231,10 @@ def on_message(msg: NewMessage, client: IcaClient) -> None:
|
|||
if len(name) > 1:
|
||||
name = name[1]
|
||||
bmcl_rank(msg, client, name)
|
||||
|
||||
|
||||
def on_config() -> Tuple[str, str]:
|
||||
return (
|
||||
"bmcl.toml",
|
||||
""
|
||||
)
|
||||
|
|
|
@ -10,7 +10,7 @@ else:
|
|||
NewMessage = TypeVar("NewMessage")
|
||||
IcaClient = TypeVar("IcaClient")
|
||||
|
||||
def safe_eval(code: str) -> str:
|
||||
def safe_eval(code: str, msg: NewMessage) -> str:
|
||||
try:
|
||||
# code = code.replace('help', '坏东西!\n')
|
||||
# code = code.replace('bytes', '坏东西!\n')
|
||||
|
@ -48,6 +48,7 @@ def safe_eval(code: str) -> str:
|
|||
"return": "别惦记你那个 return 了",
|
||||
"getattr": "<built-in function getattr>",
|
||||
"setattr": "<built-in function setattr>",
|
||||
"msg": msg,
|
||||
}
|
||||
os.system = "不许"
|
||||
result = str(eval(code, global_val, {}))
|
||||
|
@ -73,6 +74,6 @@ 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)
|
||||
result = safe_eval(code, message)
|
||||
reply = message.reply_with(result)
|
||||
client.send_message(reply)
|
||||
|
|
|
@ -72,7 +72,7 @@ async fn main() {
|
|||
room.clone(),
|
||||
None,
|
||||
);
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
info!("发送启动消息到房间: {}", room);
|
||||
if let Err(e) =
|
||||
socket.emit("sendMessage", serde_json::to_value(startup_msg).unwrap()).await
|
||||
|
@ -82,7 +82,7 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
std::thread::sleep(Duration::from_secs(3));
|
||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||
// 等待一个输入
|
||||
info!("Press any key to exit");
|
||||
let mut input = String::new();
|
||||
|
|
Loading…
Reference in New Issue
Block a user