update to edition 2024

This commit is contained in:
shenjack-5600u 2025-04-10 23:36:16 +08:00
parent e10dff96d2
commit 12d6254c6b
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F
19 changed files with 45 additions and 48 deletions

View File

@ -1,7 +1,7 @@
[package] [package]
name = "ica-rs" name = "ica-rs"
version = "0.9.0" version = "0.9.0"
edition = "2021" edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -3,7 +3,7 @@ use crate::data_struct::ica::{MessageId, RoomId, UserId};
use chrono::DateTime; use chrono::DateTime;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{json, Value as JsonValue}; use serde_json::{Value as JsonValue, json};
use tracing::warn; use tracing::warn;
pub mod msg_trait; pub mod msg_trait;
@ -331,7 +331,7 @@ impl SendMessage {
/// file_type: 图片类型(MIME) (image/png; image/jpeg) /// file_type: 图片类型(MIME) (image/png; image/jpeg)
pub fn set_img(&mut self, file: &Vec<u8>, file_type: &str, as_sticker: bool) { pub fn set_img(&mut self, file: &Vec<u8>, file_type: &str, as_sticker: bool) {
self.sticker = as_sticker; self.sticker = as_sticker;
use base64::{engine::general_purpose, Engine as _}; use base64::{Engine as _, engine::general_purpose};
let base64_data = general_purpose::STANDARD.encode(file); let base64_data = general_purpose::STANDARD.encode(file);
self.file_data = Some(format!("data:{};base64,{}", file_type, base64_data)); self.file_data = Some(format!("data:{};base64,{}", file_type, base64_data));
} }

View File

@ -4,9 +4,9 @@ use chrono::DateTime;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use crate::MainStatus;
use crate::data_struct::ica::messages::{At, Message, NewMessage}; use crate::data_struct::ica::messages::{At, Message, NewMessage};
use crate::data_struct::ica::{MessageId, UserId}; use crate::data_struct::ica::{MessageId, UserId};
use crate::MainStatus;
impl Serialize for At { impl Serialize for At {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>

View File

@ -1,7 +1,7 @@
use std::fmt::Display; use std::fmt::Display;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{json, Value as JsonValue}; use serde_json::{Value as JsonValue, json};
use crate::data_struct::tailchat::{ConverseId, GroupId, MessageId, UserId}; use crate::data_struct::tailchat::{ConverseId, GroupId, MessageId, UserId};

View File

@ -5,13 +5,13 @@ pub mod events;
use colored::Colorize; use colored::Colorize;
use rust_socketio::asynchronous::{Client, ClientBuilder}; use rust_socketio::asynchronous::{Client, ClientBuilder};
use rust_socketio::{async_any_callback, async_callback};
use rust_socketio::{Event, Payload, TransportType}; use rust_socketio::{Event, Payload, TransportType};
use tracing::{event, span, Level}; use rust_socketio::{async_any_callback, async_callback};
use tracing::{Level, event, span};
use crate::config::IcaConfig; use crate::config::IcaConfig;
use crate::error::{ClientResult, IcaError}; use crate::error::{ClientResult, IcaError};
use crate::{version_str, StopGetter}; use crate::{StopGetter, version_str};
/// icalingua 客户端的兼容版本号 /// icalingua 客户端的兼容版本号
pub const ICA_PROTOCOL_VERSION: &str = "2.12.28"; pub const ICA_PROTOCOL_VERSION: &str = "2.12.28";

View File

@ -1,14 +1,14 @@
use crate::MainStatus;
use crate::data_struct::ica::messages::{DeleteMessage, SendMessage}; use crate::data_struct::ica::messages::{DeleteMessage, SendMessage};
use crate::data_struct::ica::{RoomId, RoomIdTrait, UserId}; use crate::data_struct::ica::{RoomId, RoomIdTrait, UserId};
use crate::error::{ClientResult, IcaError}; use crate::error::{ClientResult, IcaError};
use crate::MainStatus;
use colored::Colorize; use colored::Colorize;
use ed25519_dalek::{Signature, Signer, SigningKey}; use ed25519_dalek::{Signature, Signer, SigningKey};
use rust_socketio::asynchronous::Client;
use rust_socketio::Payload; use rust_socketio::Payload;
use serde_json::{json, Value}; use rust_socketio::asynchronous::Client;
use tracing::{debug, event, span, warn, Level}; use serde_json::{Value, json};
use tracing::{Level, debug, event, span, warn};
/// "安全" 的 发送一条消息 /// "安全" 的 发送一条消息
pub async fn send_message(client: &Client, message: &SendMessage) -> bool { pub async fn send_message(client: &Client, message: &SendMessage) -> bool {

View File

@ -2,14 +2,14 @@ use colored::Colorize;
use rust_socketio::asynchronous::Client; use rust_socketio::asynchronous::Client;
use rust_socketio::{Event, Payload}; use rust_socketio::{Event, Payload};
use serde_json::json; use serde_json::json;
use tracing::{event, info, span, warn, Level}; use tracing::{Level, event, info, span, warn};
use crate::data_struct::ica::RoomId;
use crate::data_struct::ica::all_rooms::{JoinRequestRoom, Room}; use crate::data_struct::ica::all_rooms::{JoinRequestRoom, Room};
use crate::data_struct::ica::messages::{Message, MessageTrait, NewMessage}; use crate::data_struct::ica::messages::{Message, MessageTrait, NewMessage};
use crate::data_struct::ica::online_data::OnlineData; use crate::data_struct::ica::online_data::OnlineData;
use crate::data_struct::ica::RoomId;
use crate::ica::client::send_message; use crate::ica::client::send_message;
use crate::{client_id, help_msg, py, version_str, MainStatus, VERSION}; use crate::{MainStatus, VERSION, client_id, help_msg, py, version_str};
/// 获取在线数据 /// 获取在线数据
pub async fn get_online_data(payload: Payload, _client: Client) { pub async fn get_online_data(payload: Payload, _client: Client) {

View File

@ -19,7 +19,7 @@ mod tailchat;
use colored::Colorize; use colored::Colorize;
use config::BotConfig; use config::BotConfig;
use error::PyPluginError; use error::PyPluginError;
use tracing::{event, span, Level}; use tracing::{Level, event, span};
pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus { pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus {
config: None, config: None,
@ -233,8 +233,8 @@ async fn test_macro() {
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::RwLock; use tokio::sync::RwLock;
use rust_socketio::asynchronous::{Client, ClientBuilder};
use rust_socketio::Payload; use rust_socketio::Payload;
use rust_socketio::asynchronous::{Client, ClientBuilder};
/// 一个简单的例子 /// 一个简单的例子
#[derive(Clone)] #[derive(Clone)]

View File

@ -4,13 +4,13 @@ use std::sync::LazyLock;
use pyo3::prelude::*; use pyo3::prelude::*;
use rust_socketio::asynchronous::Client; use rust_socketio::asynchronous::Client;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tracing::{event, info, warn, Level}; use tracing::{Level, event, info, warn};
use crate::MainStatus;
use crate::data_struct::{ica, tailchat}; use crate::data_struct::{ica, tailchat};
use crate::error::PyPluginError; use crate::error::PyPluginError;
use crate::py::consts::events_func; use crate::py::consts::events_func;
use crate::py::{class, PyPlugin, PyStatus}; use crate::py::{PyPlugin, PyStatus, class};
use crate::MainStatus;
pub struct PyTasks { pub struct PyTasks {
pub ica_new_message: Vec<tokio::task::JoinHandle<()>>, pub ica_new_message: Vec<tokio::task::JoinHandle<()>>,

View File

@ -4,12 +4,11 @@ pub mod schdule;
pub mod tailchat; pub mod tailchat;
use pyo3::{ use pyo3::{
pyclass, pymethods, pymodule, Bound, IntoPyObject, PyAny, PyRef, PyResult, pyclass, pymethods, pymodule,
types::{PyBool, PyModule, PyModuleMethods, PyString}, types::{PyBool, PyModule, PyModuleMethods, PyString},
Bound, IntoPyObject, PyAny, PyRef, PyResult,
}; };
use toml::Value as TomlValue; use toml::Value as TomlValue;
use tracing::{event, Level}; use tracing::{Level, event};
#[derive(Clone)] #[derive(Clone)]
#[pyclass] #[pyclass]

View File

@ -1,14 +1,13 @@
use std::collections::HashMap; use std::collections::HashMap;
use pyo3::{ use pyo3::{
pyclass, pymethods, Bound, PyAny, PyResult, pyclass, pymethods,
types::{ types::{
PyAnyMethods, PyBool, PyBoolMethods, PyDict, PyDictMethods, PyFloat, PyInt, PyList, PyAnyMethods, PyBool, PyBoolMethods, PyDict, PyDictMethods, PyFloat, PyInt, PyList,
PyListMethods, PyString, PyStringMethods, PyTypeMethods, PyListMethods, PyString, PyStringMethods, PyTypeMethods,
}, },
Bound, PyAny, PyResult,
}; };
use tracing::{event, Level}; use tracing::{Level, event};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ConfigItem { pub enum ConfigItem {

View File

@ -3,15 +3,15 @@ use std::time::SystemTime;
use pyo3::{pyclass, pymethods}; use pyo3::{pyclass, pymethods};
use rust_socketio::asynchronous::Client; use rust_socketio::asynchronous::Client;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tracing::{event, Level}; use tracing::{Level, event};
use crate::MainStatus;
use crate::data_struct::ica::messages::{ use crate::data_struct::ica::messages::{
DeleteMessage, MessageTrait, NewMessage, ReplyMessage, SendMessage, DeleteMessage, MessageTrait, NewMessage, ReplyMessage, SendMessage,
}; };
use crate::data_struct::ica::{MessageId, RoomId, RoomIdTrait, UserId}; 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::ica::client::{delete_message, send_message, send_poke, send_room_sign_in};
use crate::py::PyStatus; use crate::py::PyStatus;
use crate::MainStatus;
#[pyclass] #[pyclass]
#[pyo3(name = "IcaStatus")] #[pyo3(name = "IcaStatus")]

View File

@ -1,5 +1,5 @@
use pyo3::{pyclass, pymethods, types::PyFunction, Bound, Py, PyAny, PyTraverseError, PyVisit}; use pyo3::{Bound, Py, PyAny, PyTraverseError, PyVisit, pyclass, pymethods, types::PyFunction};
use tracing::{event, Level}; use tracing::{Level, event};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[pyclass] #[pyclass]

View File

@ -1,11 +1,11 @@
use std::{path::Path, str::FromStr}; use std::{path::Path, str::FromStr};
use colored::Colorize; use colored::Colorize;
use toml_edit::{value, DocumentMut, Key, Table, TomlError, Value}; use toml_edit::{DocumentMut, Key, Table, TomlError, Value, value};
use tracing::{event, Level}; use tracing::{Level, event};
use crate::py::PyStatus;
use crate::MainStatus; use crate::MainStatus;
use crate::py::PyStatus;
/// ```toml /// ```toml
/// # 这个文件是由 shenbot 自动生成的, 请 **谨慎** 修改 /// # 这个文件是由 shenbot 自动生成的, 请 **谨慎** 修改

View File

@ -12,15 +12,15 @@ use std::{collections::HashMap, path::PathBuf};
use colored::Colorize; use colored::Colorize;
use pyo3::{ use pyo3::{
Bound, Py, PyErr, PyResult, Python,
exceptions::PyTypeError, exceptions::PyTypeError,
intern, intern,
types::{PyAnyMethods, PyModule, PyTracebackMethods, PyTuple}, types::{PyAnyMethods, PyModule, PyTracebackMethods, PyTuple},
Bound, Py, PyErr, PyResult, Python,
}; };
use tracing::{event, span, warn, Level}; use tracing::{Level, event, span, warn};
use crate::error::PyPluginError;
use crate::MainStatus; use crate::MainStatus;
use crate::error::PyPluginError;
use consts::config_func; use consts::config_func;
@ -36,6 +36,7 @@ pub type RawPyPlugin = (PathBuf, Option<SystemTime>, String);
#[allow(non_upper_case_globals)] #[allow(non_upper_case_globals)]
static mut PyPluginStatus: OnceLock<PyStatus> = OnceLock::new(); static mut PyPluginStatus: OnceLock<PyStatus> = OnceLock::new();
#[allow(static_mut_refs)]
impl PyStatus { impl PyStatus {
pub fn init() { pub fn init() {
let config = let config =
@ -394,9 +395,7 @@ impl TryFrom<RawPyPlugin> for PyPlugin {
"加载 Python 插件 {:?} 的配置文件信息时失败:返回的不是 [str, str]", "加载 Python 插件 {:?} 的配置文件信息时失败:返回的不是 [str, str]",
path path
); );
Err(PyTypeError::new_err( Err(PyTypeError::new_err("返回的不是 [str, str]".to_string()))
"返回的不是 [str, str]".to_string(),
))
} }
} }
Err(e) => { Err(e) => {

View File

@ -1,5 +1,5 @@
use crate::config::BotConfig;
use crate::MAIN_STATUS; use crate::MAIN_STATUS;
use crate::config::BotConfig;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BotStatus { pub struct BotStatus {

View File

@ -9,13 +9,13 @@ use reqwest::ClientBuilder as reqwest_ClientBuilder;
use rust_socketio::async_callback; use rust_socketio::async_callback;
use rust_socketio::asynchronous::{Client, ClientBuilder}; use rust_socketio::asynchronous::{Client, ClientBuilder};
use rust_socketio::{Event, Payload, TransportType}; use rust_socketio::{Event, Payload, TransportType};
use serde_json::{json, Value}; use serde_json::{Value, json};
use tracing::{event, span, Level}; use tracing::{Level, event, span};
use crate::config::TailchatConfig; use crate::config::TailchatConfig;
use crate::data_struct::tailchat::status::{BotStatus, LoginData}; use crate::data_struct::tailchat::status::{BotStatus, LoginData};
use crate::error::{ClientResult, TailchatError}; use crate::error::{ClientResult, TailchatError};
use crate::{async_any_callback_with_state, async_callback_with_state, version_str, StopGetter}; use crate::{StopGetter, async_any_callback_with_state, async_callback_with_state, version_str};
pub async fn start_tailchat( pub async fn start_tailchat(
config: TailchatConfig, config: TailchatConfig,

View File

@ -4,8 +4,8 @@ use crate::data_struct::tailchat::messages::SendingMessage;
use colored::Colorize; use colored::Colorize;
use reqwest::multipart; use reqwest::multipart;
use rust_socketio::asynchronous::Client; use rust_socketio::asynchronous::Client;
use serde_json::{json, Value}; use serde_json::{Value, json};
use tracing::{event, span, Level}; use tracing::{Level, event, span};
pub async fn send_message(client: &Client, message: &SendingMessage) -> bool { pub async fn send_message(client: &Client, message: &SendingMessage) -> bool {
let span = span!(Level::INFO, "tailchat send message"); let span = span!(Level::INFO, "tailchat send message");

View File

@ -3,14 +3,14 @@ use std::sync::Arc;
use colored::Colorize; use colored::Colorize;
use rust_socketio::asynchronous::Client; use rust_socketio::asynchronous::Client;
use rust_socketio::{Event, Payload}; use rust_socketio::{Event, Payload};
use tracing::{event, info, Level}; use tracing::{Level, event, info};
use crate::data_struct::tailchat::messages::ReceiveMessage; use crate::data_struct::tailchat::messages::ReceiveMessage;
use crate::data_struct::tailchat::status::{BotStatus, UpdateDMConverse}; use crate::data_struct::tailchat::status::{BotStatus, UpdateDMConverse};
use crate::py::call::tailchat_new_message_py;
use crate::py::PyStatus; use crate::py::PyStatus;
use crate::py::call::tailchat_new_message_py;
use crate::tailchat::client::{emit_join_room, send_message}; use crate::tailchat::client::{emit_join_room, send_message};
use crate::{client_id, help_msg, version_str, MainStatus, VERSION}; use crate::{MainStatus, VERSION, client_id, help_msg, version_str};
/// 所有 /// 所有
pub async fn any_event(event: Event, payload: Payload, _client: Client, _status: Arc<BotStatus>) { pub async fn any_event(event: Event, payload: Payload, _client: Client, _status: Arc<BotStatus>) {