diff --git a/.gitignore b/.gitignore index dda4377..87efd52 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,7 @@ config.toml *.pyc *__pycache__/ - +make.ps1 # Added by cargo - /target diff --git a/ica-rs/src/ica.rs b/ica-rs/src/ica.rs index ef54192..0fb90e0 100644 --- a/ica-rs/src/ica.rs +++ b/ica-rs/src/ica.rs @@ -1,14 +1,14 @@ pub mod client; pub mod events; -use futures_util::FutureExt; use rust_socketio::asynchronous::{Client, ClientBuilder}; +use rust_socketio::{async_any_callback, async_callback}; use rust_socketio::{Event, Payload, TransportType}; use tracing::{event, span, Level}; use crate::config::IcaConfig; use crate::error::{ClientResult, IcaError}; -use crate::{wrap_any_callback, wrap_callback, StopGetter}; +use crate::StopGetter; const ICA_PROTOCOL_VERSION: &str = "2.12.6"; @@ -20,18 +20,18 @@ pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientRe let socket = match ClientBuilder::new(config.host.clone()) .transport_type(TransportType::Websocket) - .on_any(wrap_any_callback!(events::any_event)) - .on("requireAuth", wrap_callback!(client::sign_callback)) - .on("message", wrap_callback!(events::connect_callback)) - .on("authSucceed", wrap_callback!(events::connect_callback)) - .on("authFailed", wrap_callback!(events::connect_callback)) - .on("messageSuccess", wrap_callback!(events::succes_message)) - .on("messageFailed", wrap_callback!(events::failed_message)) - .on("onlineData", wrap_callback!(events::get_online_data)) - .on("setAllRooms", wrap_callback!(events::update_all_room)) - .on("setMessages", wrap_callback!(events::set_messages)) - .on("addMessage", wrap_callback!(events::add_message)) - .on("deleteMessage", wrap_callback!(events::delete_message)) + .on_any(async_any_callback!(events::any_event)) + .on("requireAuth", async_callback!(client::sign_callback)) + .on("message", async_callback!(events::connect_callback)) + .on("authSucceed", async_callback!(events::connect_callback)) + .on("authFailed", async_callback!(events::connect_callback)) + .on("messageSuccess", async_callback!(events::succes_message)) + .on("messageFailed", async_callback!(events::failed_message)) + .on("onlineData", async_callback!(events::get_online_data)) + .on("setAllRooms", async_callback!(events::update_all_room)) + .on("setMessages", async_callback!(events::set_messages)) + .on("addMessage", async_callback!(events::add_message)) + .on("deleteMessage", async_callback!(events::delete_message)) .connect() .await { diff --git a/ica-rs/src/ica/events.rs b/ica-rs/src/ica/events.rs index 9183efc..f573636 100644 --- a/ica-rs/src/ica/events.rs +++ b/ica-rs/src/ica/events.rs @@ -20,6 +20,7 @@ pub async fn get_online_data(payload: Payload, _client: Client) { } } +#[allow(clippy::collapsible_if)] /// 接收消息 pub async fn add_message(payload: Payload, client: Client) { if let Payload::Text(values) = payload { diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index 4c5db5d..ce630cf 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -28,19 +28,16 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const ICA_VERSION: &str = "1.6.0"; pub const TAILCHAT_VERSION: &str = "1.1.0"; -#[macro_export] -macro_rules! wrap_callback { - ($f:expr) => { - |payload: Payload, client: Client| $f(payload, client).boxed() - }; -} - -#[macro_export] -macro_rules! wrap_any_callback { - ($f:expr) => { - |event: Event, payload: Payload, client: Client| $f(event, payload, client).boxed() - }; -} +/// usage: +/// #[derive(Clone)] +/// struct BotState(String); +/// +/// async fn some_event_with_state(payload: Payload, client: Client, state: Arc) { +/// // do something +/// +// macro_rules! wrap_callback_with_state { +// ($f:expr, $state:tt) => {}; +// } #[tokio::main] async fn main() { diff --git a/ica-rs/src/tailchat.rs b/ica-rs/src/tailchat.rs index e60d12d..532a632 100644 --- a/ica-rs/src/tailchat.rs +++ b/ica-rs/src/tailchat.rs @@ -2,10 +2,10 @@ pub mod client; pub mod events; use colored::Colorize; -use futures_util::FutureExt; use md5::{Digest, Md5}; use reqwest::ClientBuilder as reqwest_ClientBuilder; use rust_socketio::asynchronous::{Client, ClientBuilder}; +use rust_socketio::{async_any_callback, async_callback}; use rust_socketio::{Event, Payload, TransportType}; use serde_json::{json, Value}; use tracing::{event, span, Level}; @@ -13,7 +13,7 @@ use tracing::{event, span, Level}; use crate::config::TailchatConfig; use crate::data_struct::tailchat::status::LoginData; use crate::error::{ClientResult, TailchatError}; -use crate::{wrap_any_callback, wrap_callback, StopGetter}; +use crate::StopGetter; pub async fn start_tailchat( config: TailchatConfig, @@ -63,12 +63,12 @@ pub async fn start_tailchat( let socket = ClientBuilder::new(config.host) .auth(json!({"token": status.jwt.clone()})) .transport_type(TransportType::Websocket) - .on_any(wrap_any_callback!(events::any_event)) - .on("notify:chat.message.add", wrap_callback!(events::on_message)) - .on("notify:chat.message.delete", wrap_callback!(events::on_msg_delete)) + .on_any(async_any_callback!(events::any_event)) + .on("notify:chat.message.add", async_callback!(events::on_message)) + .on("notify:chat.message.delete", async_callback!(events::on_msg_delete)) .on( "notify:chat.converse.updateDMConverse", - wrap_callback!(events::on_converse_update), + async_callback!(events::on_converse_update), ) // .on("notify:chat.message.update", wrap_callback!(events::on_message)) // .on("notify:chat.message.addReaction", wrap_callback!(events::on_msg_update)) diff --git a/ica-rs/src/tailchat/events.rs b/ica-rs/src/tailchat/events.rs index 85647c6..f10b886 100644 --- a/ica-rs/src/tailchat/events.rs +++ b/ica-rs/src/tailchat/events.rs @@ -59,6 +59,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) { } } +#[allow(clippy::collapsible_if)] pub async fn on_message(payload: Payload, client: Client) { if let Payload::Text(values) = payload { if let Some(value) = values.first() {