先更新一部分能跑的

This commit is contained in:
shenjack 2024-02-23 16:48:34 +08:00
parent 28ec8d316d
commit d6443f27bb
Signed by: shenjack
GPG Key ID: 7B1134A979775551
4 changed files with 21 additions and 20 deletions

View File

@ -2,10 +2,10 @@ use crate::client::IcalinguaStatus;
use crate::data_struct::files::MessageFile; use crate::data_struct::files::MessageFile;
use crate::data_struct::{MessageId, RoomId, UserId}; use crate::data_struct::{MessageId, RoomId, UserId};
use tracing::warn;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{json, Value as JsonValue}; use serde_json::{json, Value as JsonValue};
use tracing::warn;
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum At { pub enum At {
@ -139,13 +139,11 @@ impl NewMessage {
} }
// 回复的消息 // 回复的消息
let reply: Option<ReplyMessage> = match message.get("replyMessage") { let reply: Option<ReplyMessage> = match message.get("replyMessage") {
Some(value) => { Some(value) => match serde_json::from_value::<ReplyMessage>(value.clone()) {
match serde_json::from_value::<ReplyMessage>(value.clone()) { Ok(reply) => Some(reply),
Ok(reply) => Some(reply), Err(e) => {
Err(e) => { warn!("Failed to parse reply message: {}", e);
warn!("Failed to parse reply message: {}", e); None
None
}
} }
}, },
None => None, None => None,

View File

@ -14,10 +14,7 @@ pub async fn get_online_data(payload: Payload, _client: Client) {
if let Payload::Text(values) = payload { if let Payload::Text(values) = payload {
if let Some(value) = values.first() { if let Some(value) = values.first() {
let online_data = OnlineData::new_from_json(value); let online_data = OnlineData::new_from_json(value);
info!( info!("update_online_data {}", format!("{:?}", online_data).cyan());
"update_online_data {}",
format!("{:?}", online_data).cyan()
);
unsafe { unsafe {
crate::ClientStatus.update_online_data(online_data); crate::ClientStatus.update_online_data(online_data);
} }
@ -31,7 +28,10 @@ pub async fn add_message(payload: Payload, client: Client) {
if let Some(value) = values.first() { if let Some(value) = values.first() {
let message = NewMessage::new_from_json(value); let message = NewMessage::new_from_json(value);
// 检测是否在过滤列表内 // 检测是否在过滤列表内
if IcalinguaStatus::get_config().filter_list.contains(&message.sender_id) { if IcalinguaStatus::get_config()
.filter_list
.contains(&message.sender_id)
{
return; return;
} }
info!("add_message {}", message.output().cyan()); info!("add_message {}", message.output().cyan());

View File

@ -1,7 +1,7 @@
use pyo3::prelude::*; use pyo3::prelude::*;
use tracing::{debug, info, warn};
use rust_socketio::asynchronous::Client; use rust_socketio::asynchronous::Client;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tracing::{debug, info, warn};
use crate::client::send_message; use crate::client::send_message;
use crate::data_struct::messages::{NewMessage, ReplyMessage, SendMessage}; use crate::data_struct::messages::{NewMessage, ReplyMessage, SendMessage};

View File

@ -57,7 +57,7 @@ impl PyStatus {
} }
} }
true true
}, }
None => false, None => false,
}, },
None => false, None => false,
@ -108,7 +108,11 @@ pub fn load_py_plugins(path: &PathBuf) {
pub fn verify_plugins() { pub fn verify_plugins() {
let mut need_reload_files: Vec<PathBuf> = Vec::new(); let mut need_reload_files: Vec<PathBuf> = Vec::new();
let plugin_path = IcalinguaStatus::get_config().py_plugin_path.as_ref().unwrap().to_owned(); let plugin_path = IcalinguaStatus::get_config()
.py_plugin_path
.as_ref()
.unwrap()
.to_owned();
for entry in std::fs::read_dir(&plugin_path).unwrap() { for entry in std::fs::read_dir(&plugin_path).unwrap() {
if let Ok(entry) = entry { if let Ok(entry) = entry {
let path = entry.path(); let path = entry.path();
@ -165,13 +169,12 @@ pub fn load_py_module(path: &PathBuf) -> Option<(Option<SystemTime>, Py<PyAny>)>
&path.to_string_lossy(), &path.to_string_lossy(),
&path.to_string_lossy(), &path.to_string_lossy(),
// !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的 // !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的
).map(|module| module.into()); )
.map(|module| module.into());
module module
}); });
match py_module { match py_module {
Ok(py_module) => { Ok(py_module) => Some((changed_time, py_module)),
Some((changed_time, py_module))
}
Err(e) => { Err(e) => {
warn!("failed to load file: {:?} | e: {:?}", path, e); warn!("failed to load file: {:?} | e: {:?}", path, e);
None None