还是0.8.0……

This commit is contained in:
shenjack 2025-01-06 21:02:52 +08:00
parent c80e938a78
commit 974c2577c3
Signed by: shenjack
GPG Key ID: 7B1134A979775551
4 changed files with 39 additions and 1 deletions

View File

@ -255,6 +255,13 @@ impl IcaClientPy {
/// 返回是否成功
pub fn reload_plugin_status(&self) -> bool { PyStatus::get_mut().config.reload_from_default() }
/// 重新加载插件
///
/// 返回是否成功
pub fn reload_plugin(&self, plugin_name: String) -> bool {
PyStatus::get_mut().reload_plugin(&plugin_name)
}
pub fn debug(&self, content: String) {
event!(Level::DEBUG, "{}", content);
}

View File

@ -77,6 +77,13 @@ impl TailchatClientPy {
/// 返回是否成功
pub fn reload_plugin_status(&self) -> bool { PyStatus::get_mut().config.reload_from_default() }
/// 重新加载插件
///
/// 返回是否成功
pub fn reload_plugin(&self, plugin_name: String) -> bool {
PyStatus::get_mut().reload_plugin(&plugin_name)
}
#[pyo3(signature = (content, converse_id, group_id = None))]
pub fn new_message(
&self,

View File

@ -46,6 +46,23 @@ impl PyStatus {
/// 添加一个插件
pub fn add_file(&mut self, path: PathBuf, plugin: PyPlugin) { self.files.insert(path, plugin); }
/// 重新加载一个插件
pub fn reload_plugin(&mut self, plugin_name: &str) -> bool {
let plugin = self.files.iter_mut().find_map(|(_, plugin)| {
if plugin.get_id() == plugin_name {
Some(plugin)
} else {
None
}
});
if let Some(plugin) = plugin {
plugin.reload_from_file()
} else {
event!(Level::WARN, "没有找到插件: {}", plugin_name);
false
}
}
/// 删除一个插件
pub fn delete_file(&mut self, path: &PathBuf) -> Option<PyPlugin> { self.files.remove(path) }
@ -128,7 +145,7 @@ impl PyPlugin {
}
/// 从文件更新
pub fn reload_from_file(&mut self) {
pub fn reload_from_file(&mut self) -> bool {
let raw_file = load_py_file(&self.file_path);
match raw_file {
Ok(raw_file) => match Self::try_from(raw_file) {
@ -137,6 +154,7 @@ impl PyPlugin {
self.changed_time = plugin.changed_time;
self.enabled = PyStatus::get().config.get_status(&self.get_id());
event!(Level::INFO, "更新 Python 插件文件 {:?} 完成", self.file_path);
true
}
Err(e) => {
warn!(
@ -145,10 +163,12 @@ impl PyPlugin {
e,
get_py_err_traceback(&e)
);
false
}
},
Err(e) => {
warn!("更新插件 {:?}: {:?} 失败", self.file_path, e);
false
}
}
}

View File

@ -21,11 +21,15 @@
- socketio event: `sendGroupPoke`
- 添加了 `reload_plugin_status` api
- 用于重新加载插件状态
- 添加了 `reload_plugin(plugin_name: str)` api
- 用于重新加载指定插件
### tailchat 1.2.5
- 添加了 `reload_plugin_status` api
- 用于重新加载插件状态
- 添加了 `reload_plugin(plugin_name: str)` api
- 用于重新加载指定插件
## 0.7.4