From de12c495f01b1b030a3977d52a8c1e4909c96d38 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 15 Jun 2024 00:35:35 +0800 Subject: [PATCH] p2 --- ica-rs/src/data_struct/tailchat/messages.rs | 6 +++--- ica-rs/src/main.rs | 11 +++++++++++ ica-rs/src/tailchat.rs | 6 +++--- ica-rs/src/tailchat/client.rs | 1 - ica-rs/src/tailchat/events.rs | 2 +- news.md | 6 +++++- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ica-rs/src/data_struct/tailchat/messages.rs b/ica-rs/src/data_struct/tailchat/messages.rs index 284d5f8..deb200f 100644 --- a/ica-rs/src/data_struct/tailchat/messages.rs +++ b/ica-rs/src/data_struct/tailchat/messages.rs @@ -141,9 +141,9 @@ impl SendingMessage { } } pub fn contain_file(&self) -> bool { self.file.is_some() } - - pub fn add_img(&mut self, file: Vec, ) { self.file = Some(file); } - + + pub fn add_img(&mut self, file: Vec) { self.file = Some(file); } + pub fn as_value(&self) -> JsonValue { serde_json::to_value(self).unwrap() } } diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index db11cf3..5f660df 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -37,6 +37,17 @@ macro_rules! async_callback_with_state { }}; } +#[macro_export] +macro_rules! async_any_callback_with_state { + ($f:expr, $state:expr) => {{ + use futures_util::FutureExt; + let state = $state.clone(); + move |event: Event, payload: Payload, client: Client| { + $f(event, payload, client, state.clone()).boxed() + } + }}; +} + #[tokio::main] async fn main() { // -d -> debug diff --git a/ica-rs/src/tailchat.rs b/ica-rs/src/tailchat.rs index becf03a..b70b803 100644 --- a/ica-rs/src/tailchat.rs +++ b/ica-rs/src/tailchat.rs @@ -6,8 +6,8 @@ use std::sync::Arc; use colored::Colorize; use md5::{Digest, Md5}; use reqwest::ClientBuilder as reqwest_ClientBuilder; +use rust_socketio::async_callback; 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}; @@ -15,7 +15,7 @@ use tracing::{event, span, Level}; use crate::config::TailchatConfig; use crate::data_struct::tailchat::status::{BotStatus, LoginData}; use crate::error::{ClientResult, TailchatError}; -use crate::{async_callback_with_state, StopGetter}; +use crate::{async_any_callback_with_state, async_callback_with_state, StopGetter}; pub async fn start_tailchat( config: TailchatConfig, @@ -68,7 +68,7 @@ pub async fn start_tailchat( let socket = ClientBuilder::new(config.host) .auth(json!({"token": status.jwt.clone()})) .transport_type(TransportType::Websocket) - .on_any(async_any_callback!(events::any_event)) + .on_any(async_any_callback_with_state!(events::any_event, sharded_status.clone())) .on( "notify:chat.message.add", async_callback_with_state!(events::on_message, sharded_status.clone()), diff --git a/ica-rs/src/tailchat/client.rs b/ica-rs/src/tailchat/client.rs index 3110875..cf0a49f 100644 --- a/ica-rs/src/tailchat/client.rs +++ b/ica-rs/src/tailchat/client.rs @@ -10,7 +10,6 @@ use tracing::{debug, info, warn}; pub async fn send_message(client: &Client, message: &SendingMessage) -> bool { if message.contain_file() { // 处理文件 - } let value: Value = message.as_value(); match client.emit("chat.message.sendMessage", value).await { diff --git a/ica-rs/src/tailchat/events.rs b/ica-rs/src/tailchat/events.rs index cc1c48e..0897e71 100644 --- a/ica-rs/src/tailchat/events.rs +++ b/ica-rs/src/tailchat/events.rs @@ -10,7 +10,7 @@ use crate::data_struct::tailchat::status::{BotStatus, UpdateDMConverse}; use crate::tailchat::client::{emit_join_room, send_message}; /// 所有 -pub async fn any_event(event: Event, payload: Payload, _client: Client) { +pub async fn any_event(event: Event, payload: Payload, _client: Client, _status: Arc) { let handled = [ // 真正处理过的 "notify:chat.message.add", diff --git a/news.md b/news.md index a1d89f1..20df687 100644 --- a/news.md +++ b/news.md @@ -9,7 +9,11 @@ - `ReceiveMessage::meta` - 从 `JsonValue` 改成 `Option` - 用来解决发图片的时候没有 `meta` 字段的问题 -- 去除了 +- 去除了自带的两个 macro + - `wrap_callback` 和 `wrap_any_callback` + - 因为现在他俩已经进到 `rust_socketio` 里啦 +- 添加了新的 macro + - `` ## 0.6.7