mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-02-22 14:59:55 +08:00
理论上这还是0.8.0?
This commit is contained in:
parent
32958031d2
commit
c80e938a78
|
@ -30,7 +30,7 @@ pub type StopGetter = tokio::sync::oneshot::Receiver<()>;
|
|||
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const ICA_VERSION: &str = "1.6.5";
|
||||
pub const TAILCHAT_VERSION: &str = "1.2.4";
|
||||
pub const TAILCHAT_VERSION: &str = "1.2.5";
|
||||
|
||||
const HELP_MSG: &str = r#"/bot-rs
|
||||
展示 rust 侧信息
|
||||
|
@ -46,7 +46,9 @@ const HELP_MSG: &str = r#"/bot-rs
|
|||
by shenjackyuanjie"#;
|
||||
|
||||
/// 获取帮助信息
|
||||
pub fn help_msg() -> String { format!("{}\n{}", version_str(), HELP_MSG) }
|
||||
pub fn help_msg() -> String {
|
||||
format!("{}\n{}", version_str(), HELP_MSG).replace("<client-id>", client_id().as_str())
|
||||
}
|
||||
|
||||
static STARTUP_TIME: OnceLock<SystemTime> = OnceLock::new();
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use crate::data_struct::ica::messages::{
|
|||
};
|
||||
use crate::data_struct::ica::{MessageId, RoomId, RoomIdTrait, UserId};
|
||||
use crate::ica::client::{delete_message, send_message, send_poke, send_room_sign_in};
|
||||
use crate::py::PyStatus;
|
||||
use crate::MainStatus;
|
||||
|
||||
#[pyclass]
|
||||
|
@ -250,6 +251,10 @@ impl IcaClientPy {
|
|||
#[getter]
|
||||
pub fn get_startup_time(&self) -> SystemTime { crate::start_up_time() }
|
||||
|
||||
/// 重新加载插件状态
|
||||
/// 返回是否成功
|
||||
pub fn reload_plugin_status(&self) -> bool { PyStatus::get_mut().config.reload_from_default() }
|
||||
|
||||
pub fn debug(&self, content: String) {
|
||||
event!(Level::DEBUG, "{}", content);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use tracing::{debug, info, warn};
|
|||
|
||||
use crate::data_struct::tailchat::messages::{ReceiveMessage, SendingFile, SendingMessage};
|
||||
use crate::data_struct::tailchat::{ConverseId, GroupId, MessageId, UserId};
|
||||
use crate::py::PyStatus;
|
||||
use crate::tailchat::client::send_message;
|
||||
|
||||
#[pyclass]
|
||||
|
@ -72,6 +73,9 @@ impl TailchatClientPy {
|
|||
pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() }
|
||||
#[getter]
|
||||
pub fn get_startup_time(&self) -> SystemTime { crate::start_up_time() }
|
||||
/// 重新加载插件状态
|
||||
/// 返回是否成功
|
||||
pub fn reload_plugin_status(&self) -> bool { PyStatus::get_mut().config.reload_from_default() }
|
||||
|
||||
#[pyo3(signature = (content, converse_id, group_id = None))]
|
||||
pub fn new_message(
|
||||
|
|
|
@ -49,14 +49,15 @@ impl PluginConfigFile {
|
|||
Self::from_config_path(&path)
|
||||
}
|
||||
|
||||
pub fn reload_from_default(&mut self) {
|
||||
pub fn reload_from_default(&mut self) -> bool {
|
||||
let new_config = Self::default_init();
|
||||
if let Err(e) = new_config {
|
||||
event!(Level::ERROR, "从配置文件重加载时遇到错误: {}", e);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
let new_config = new_config.unwrap();
|
||||
self.data = new_config.data;
|
||||
true
|
||||
}
|
||||
|
||||
pub fn from_config_path(path: &Path) -> anyhow::Result<Self> {
|
||||
|
@ -127,8 +128,13 @@ impl PluginConfigFile {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_status_from_file(&mut self) {
|
||||
self.reload_from_default();
|
||||
/// 从默认文件读取状态
|
||||
///
|
||||
/// 返回是否成功
|
||||
pub fn read_status_from_default(&mut self) -> bool {
|
||||
if !self.reload_from_default() {
|
||||
return false;
|
||||
}
|
||||
event!(Level::INFO, "同步插件状态");
|
||||
let plugins = PyStatus::get_mut();
|
||||
plugins.files.iter_mut().for_each(|(path, status)| {
|
||||
|
@ -144,6 +150,7 @@ impl PluginConfigFile {
|
|||
);
|
||||
status.enabled = config_status;
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn sync_status_to_config(&mut self) {
|
||||
|
|
|
@ -3,6 +3,7 @@ pub mod class;
|
|||
pub mod config;
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::fmt::Display;
|
||||
use std::path::Path;
|
||||
use std::sync::OnceLock;
|
||||
use std::time::SystemTime;
|
||||
|
@ -11,7 +12,7 @@ use std::{collections::HashMap, path::PathBuf};
|
|||
use colored::Colorize;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyTuple;
|
||||
use tracing::{event, info, span, warn, Level};
|
||||
use tracing::{event, span, warn, Level};
|
||||
|
||||
use crate::MainStatus;
|
||||
|
||||
|
@ -74,8 +75,8 @@ impl PyStatus {
|
|||
"Python 插件 {{ {} }}",
|
||||
Self::get()
|
||||
.files
|
||||
.iter()
|
||||
.map(|(_, v)| v.to_string())
|
||||
.values()
|
||||
.map(|v| v.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
)
|
||||
|
@ -169,9 +170,9 @@ impl PyPlugin {
|
|||
pub fn get_id(&self) -> String { plugin_path_as_id(&self.file_path) }
|
||||
}
|
||||
|
||||
impl ToString for PyPlugin {
|
||||
fn to_string(&self) -> String {
|
||||
format!("{}({:?})-{}", self.get_id(), self.file_path, self.enabled)
|
||||
impl Display for PyPlugin {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}({:?})-{}", self.get_id(), self.file_path, self.enabled)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,17 +201,26 @@ impl TryFrom<RawPyPlugin> for PyPlugin {
|
|||
let mut base_path: PathBuf = PathBuf::from(base_path);
|
||||
|
||||
if !base_path.exists() {
|
||||
warn!("python 插件路径不存在, 创建: {:?}", base_path);
|
||||
event!(Level::WARN, "python 插件路径不存在, 创建: {:?}", base_path);
|
||||
std::fs::create_dir_all(&base_path)?;
|
||||
}
|
||||
base_path.push(&config);
|
||||
|
||||
let config_value = if base_path.exists() {
|
||||
info!("加载 {:?} 的配置文件 {:?} 中", path, base_path);
|
||||
event!(
|
||||
Level::INFO,
|
||||
"加载 {:?} 的配置文件 {:?} 中",
|
||||
path,
|
||||
base_path
|
||||
);
|
||||
let content = std::fs::read_to_string(&base_path)?;
|
||||
toml::from_str(&content)
|
||||
} else {
|
||||
warn!("配置文件 {:?} 不存在, 创建默认配置", base_path);
|
||||
event!(
|
||||
Level::WARN,
|
||||
"配置文件 {:?} 不存在, 创建默认配置",
|
||||
base_path
|
||||
);
|
||||
// 写入默认配置
|
||||
std::fs::write(base_path, &default)?;
|
||||
toml::from_str(&default)
|
||||
|
@ -220,7 +230,7 @@ impl TryFrom<RawPyPlugin> for PyPlugin {
|
|||
let py_config =
|
||||
Bound::new(py, class::ConfigDataPy::new(config));
|
||||
if let Err(e) = py_config {
|
||||
warn!("添加配置文件信息失败: {:?}", e);
|
||||
event!(Level::WARN, "添加配置文件信息失败: {:?}", e);
|
||||
return Err(e);
|
||||
}
|
||||
let py_config = py_config.unwrap();
|
||||
|
@ -348,7 +358,8 @@ pub fn load_py_plugins(path: &PathBuf) {
|
|||
} else {
|
||||
event!(Level::WARN, "插件加载目录不存在: {:?}", path);
|
||||
}
|
||||
plugins.config.read_status_from_file();
|
||||
plugins.config.read_status_from_default();
|
||||
plugins.config.sync_status_to_config();
|
||||
event!(
|
||||
Level::INFO,
|
||||
"python 插件目录: {:?} 加载完成, 加载到 {} 个插件",
|
||||
|
@ -399,7 +410,7 @@ pub fn init_py() {
|
|||
load_py_plugins(&plugin_path);
|
||||
event!(Level::DEBUG, "python 插件列表: {}", PyStatus::display());
|
||||
|
||||
info!("python inited")
|
||||
event!(Level::INFO, "python 初始化完成")
|
||||
}
|
||||
|
||||
pub fn post_py() -> anyhow::Result<()> {
|
||||
|
|
|
@ -97,16 +97,6 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc<BotStatus
|
|||
let reply = message.reply_with(&help_msg());
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
// else if message.content == "/bot-uptime" {
|
||||
// let duration = match start_up_time().elapsed() {
|
||||
// Ok(d) => format!("{:?}", d),
|
||||
// Err(e) => format!("出问题啦 {:?}", e),
|
||||
// };
|
||||
// let reply = message.reply_with(&format!(
|
||||
// "shenbot 已运行: {}", duration
|
||||
// ));
|
||||
// send_message(&client, &reply).await;
|
||||
// }
|
||||
if MainStatus::global_config().tailchat().admin_list.contains(&message.sender_id) {
|
||||
// admin 区
|
||||
let client_id = client_id();
|
||||
|
|
8
news.md
8
news.md
|
@ -6,6 +6,7 @@
|
|||
- 从 `py::PyStatus` 开始进行一个 `static mut` -> `static mut OnceLock` 的改造
|
||||
- 用于看着更舒服(逃)
|
||||
- 部分重构了一下 读取插件启用状态 的配置文件的代码
|
||||
- 现在 `/bot-help` 会直接输出实际的 client id, 而不是给你一个默认的 `<client-id>`
|
||||
|
||||
### ica 1.6.5
|
||||
|
||||
|
@ -18,6 +19,13 @@
|
|||
- 或者指定好友
|
||||
- 目前还是有点问题
|
||||
- socketio event: `sendGroupPoke`
|
||||
- 添加了 `reload_plugin_status` api
|
||||
- 用于重新加载插件状态
|
||||
|
||||
### tailchat 1.2.5
|
||||
|
||||
- 添加了 `reload_plugin_status` api
|
||||
- 用于重新加载插件状态
|
||||
|
||||
## 0.7.4
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user