看起来行了?

This commit is contained in:
shenjack 2024-10-01 19:13:28 +08:00
parent b286765213
commit 9ba8cfaba3
Signed by: shenjack
GPG Key ID: 7B1134A979775551
10 changed files with 69 additions and 23 deletions

View File

@ -51,11 +51,13 @@ pub struct UpdateDMConverse {
#[allow(unused)] #[allow(unused)]
pub type Writeable<T> = Arc<RwLock<T>>; pub type Writeable<T> = Arc<RwLock<T>>;
#[allow(unused)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BotStatus { pub struct BotStatus {
user_id: UserId, user_id: UserId,
} }
#[allow(unused)]
impl BotStatus { impl BotStatus {
pub fn new(user_id: UserId) -> Self { Self { user_id } } pub fn new(user_id: UserId) -> Self { Self { user_id } }

View File

@ -11,7 +11,7 @@ use crate::error::{ClientResult, IcaError};
use crate::{version_str, StopGetter}; use crate::{version_str, StopGetter};
/// icalingua 客户端的兼容版本号 /// icalingua 客户端的兼容版本号
pub const ICA_PROTOCOL_VERSION: &str = "2.12.20"; pub const ICA_PROTOCOL_VERSION: &str = "2.12.21";
pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> { pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> {
let span = span!(Level::INFO, "Icalingua Client"); let span = span!(Level::INFO, "Icalingua Client");

View File

@ -43,7 +43,6 @@ pub async fn delete_message(client: &Client, message: &DeleteMessage) -> bool {
/// ``` /// ```
// #[allow(dead_code)] // #[allow(dead_code)]
// pub async fn fetch_history(client: &Client, roomd_id: RoomId) -> bool { false } // pub async fn fetch_history(client: &Client, roomd_id: RoomId) -> bool { false }
async fn inner_sign(payload: Payload, client: Client) -> ClientResult<(), IcaError> { async fn inner_sign(payload: Payload, client: Client) -> ClientResult<(), IcaError> {
let span = span!(Level::INFO, "signing icalingua"); let span = span!(Level::INFO, "signing icalingua");
let _guard = span.enter(); let _guard = span.enter();

View File

@ -187,7 +187,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
"closeLoading", // 发送消息/加载新聊天 有一个 loading "closeLoading", // 发送消息/加载新聊天 有一个 loading
"renewMessage", // 我也不确定到底是啥事件 "renewMessage", // 我也不确定到底是啥事件
"requestSetup", // 需要登录 "requestSetup", // 需要登录
"updateRoom", "updateRoom", // 更新房间
]; ];
match &event { match &event {
Event::Custom(event_name) => { Event::Custom(event_name) => {

View File

@ -95,8 +95,15 @@ macro_rules! async_any_callback_with_state {
}}; }};
} }
#[tokio::main] fn main() -> anyhow::Result<()> {
async fn main() -> anyhow::Result<()> { inner_main().await } tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_name("shenbot-rs")
.worker_threads(4)
.build()
.unwrap()
.block_on(inner_main())
}
async fn inner_main() -> anyhow::Result<()> { async fn inner_main() -> anyhow::Result<()> {
// -d -> debug // -d -> debug

View File

@ -64,6 +64,14 @@ pub fn verify_and_reload_plugins() {
let mut need_reload_files: Vec<PathBuf> = Vec::new(); let mut need_reload_files: Vec<PathBuf> = Vec::new();
let plugin_path = MainStatus::global_config().py().plugin_path.clone(); let plugin_path = MainStatus::global_config().py().plugin_path.clone();
// 先检查是否有插件被删除
for path in PyStatus::get_map_mut().keys() {
if !path.exists() {
event!(Level::INFO, "Python 插件: {:?} 已被删除", path);
PyStatus::delete_file(path);
}
}
for entry in std::fs::read_dir(plugin_path).unwrap().flatten() { for entry in std::fs::read_dir(plugin_path).unwrap().flatten() {
let path = entry.path(); let path = entry.path();
if let Some(ext) = path.extension() { if let Some(ext) = path.extension() {
@ -76,7 +84,7 @@ pub fn verify_and_reload_plugins() {
if need_reload_files.is_empty() { if need_reload_files.is_empty() {
return; return;
} }
info!("file change list: {:?}", need_reload_files); event!(Level::INFO, "更改列表: {:?}", need_reload_files);
let exist_plugins = PyStatus::get_map_mut(); let exist_plugins = PyStatus::get_map_mut();
for reload_file in need_reload_files { for reload_file in need_reload_files {
if let Some(plugin) = exist_plugins.get_mut(&reload_file) { if let Some(plugin) = exist_plugins.get_mut(&reload_file) {

View File

@ -73,7 +73,12 @@ impl TailchatClientPy {
#[getter] #[getter]
pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() } pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() }
#[pyo3(signature = (content, converse_id, group_id = None))] #[pyo3(signature = (content, converse_id, group_id = None))]
pub fn new_message(&self, content: String, converse_id: ConverseId, group_id: Option<GroupId>) -> TailchatSendingMessagePy { pub fn new_message(
&self,
content: String,
converse_id: ConverseId,
group_id: Option<GroupId>,
) -> TailchatSendingMessagePy {
TailchatSendingMessagePy { TailchatSendingMessagePy {
message: SendingMessage::new(content, converse_id, group_id, None), message: SendingMessage::new(content, converse_id, group_id, None),
} }

View File

@ -42,9 +42,7 @@ impl PyStatus {
pub fn add_file(path: PathBuf, plugin: PyPlugin) { Self::get_map_mut().insert(path, plugin); } pub fn add_file(path: PathBuf, plugin: PyPlugin) { Self::get_map_mut().insert(path, plugin); }
/// 删除一个插件 /// 删除一个插件
pub fn delete_file(path: &PathBuf) -> Option<PyPlugin> { pub fn delete_file(path: &PathBuf) -> Option<PyPlugin> { Self::get_map_mut().remove(path) }
Self::get_map_mut().remove(path)
}
pub fn verify_file(path: &PathBuf) -> bool { pub fn verify_file(path: &PathBuf) -> bool {
Self::get_map().get(path).map_or(false, |plugin| plugin.verifiy()) Self::get_map().get(path).map_or(false, |plugin| plugin.verifiy())
@ -52,11 +50,13 @@ impl PyStatus {
pub fn get_map() -> &'static PyPlugins { pub fn get_map() -> &'static PyPlugins {
unsafe { unsafe {
match PYSTATUS.files.as_ref() { let ptr = &raw const PYSTATUS.files;
let ptr = &*ptr;
match ptr.as_ref() {
Some(files) => files, Some(files) => files,
None => { None => {
Self::init(); Self::init();
PYSTATUS.files.as_ref().unwrap() ptr.as_ref().unwrap()
} }
} }
} }
@ -64,11 +64,13 @@ impl PyStatus {
pub fn get_map_mut() -> &'static mut PyPlugins { pub fn get_map_mut() -> &'static mut PyPlugins {
unsafe { unsafe {
match PYSTATUS.files.as_mut() { let ptr = &raw mut PYSTATUS.files;
let ptr = &mut *ptr;
match ptr {
Some(files) => files, Some(files) => files,
None => { None => {
Self::init(); Self::init();
PYSTATUS.files.as_mut().unwrap() ptr.as_mut().unwrap()
} }
} }
} }
@ -76,11 +78,13 @@ impl PyStatus {
pub fn get_config() -> &'static config::PluginConfigFile { pub fn get_config() -> &'static config::PluginConfigFile {
unsafe { unsafe {
match PYSTATUS.config.as_ref() { let ptr = &raw const PYSTATUS.config;
let ptr = &*ptr;
match ptr {
Some(config) => config, Some(config) => config,
None => { None => {
Self::init(); Self::init();
PYSTATUS.config.as_ref().unwrap() ptr.as_ref().unwrap()
} }
} }
} }
@ -88,11 +92,13 @@ impl PyStatus {
pub fn get_config_mut() -> &'static mut config::PluginConfigFile { pub fn get_config_mut() -> &'static mut config::PluginConfigFile {
unsafe { unsafe {
match PYSTATUS.config.as_mut() { let ptr = &raw mut PYSTATUS.config;
let ptr = &mut *ptr;
match ptr {
Some(config) => config, Some(config) => config,
None => { None => {
Self::init(); Self::init();
PYSTATUS.config.as_mut().unwrap() ptr.as_mut().unwrap()
} }
} }
} }

View File

@ -44,20 +44,37 @@ impl BotStatus {
unsafe { MAIN_STATUS.startup_time.unwrap() } unsafe { MAIN_STATUS.startup_time.unwrap() }
} }
pub fn global_config() -> &'static BotConfig { unsafe { MAIN_STATUS.config.as_ref().unwrap() } } pub fn global_config() -> &'static BotConfig {
unsafe {
let ptr = &raw const MAIN_STATUS.config;
(*ptr).as_ref().unwrap()
}
}
pub fn global_ica_status() -> &'static ica::MainStatus { pub fn global_ica_status() -> &'static ica::MainStatus {
unsafe { MAIN_STATUS.ica_status.as_ref().unwrap() } unsafe {
let ptr = &raw const MAIN_STATUS.ica_status;
(*ptr).as_ref().unwrap()
}
} }
pub fn global_tailchat_status() -> &'static tailchat::MainStatus { pub fn global_tailchat_status() -> &'static tailchat::MainStatus {
unsafe { MAIN_STATUS.tailchat_status.as_ref().unwrap() } unsafe {
let ptr = &raw const MAIN_STATUS.tailchat_status;
(*ptr).as_ref().unwrap()
}
} }
pub fn global_ica_status_mut() -> &'static mut ica::MainStatus { pub fn global_ica_status_mut() -> &'static mut ica::MainStatus {
unsafe { MAIN_STATUS.ica_status.as_mut().unwrap() } unsafe {
let ptr = &raw mut MAIN_STATUS.ica_status;
(*ptr).as_mut().unwrap()
}
} }
pub fn global_tailchat_status_mut() -> &'static mut tailchat::MainStatus { pub fn global_tailchat_status_mut() -> &'static mut tailchat::MainStatus {
unsafe { MAIN_STATUS.tailchat_status.as_mut().unwrap() } unsafe {
let ptr = &raw mut MAIN_STATUS.tailchat_status;
(*ptr).as_mut().unwrap()
}
} }
} }

View File

@ -2,6 +2,8 @@
## 0.7.3 ## 0.7.3
- 也许修复了删除插件不会立即生效的问题
- ica 兼容版本号更新到 `2.12.21`
添加了一些新的 api 添加了一些新的 api
### ica 1.6.4 ### ica 1.6.4