This commit is contained in:
shenjack 2024-06-15 00:35:35 +08:00
parent ca9033a23f
commit de12c495f0
Signed by: shenjack
GPG Key ID: 7B1134A979775551
6 changed files with 23 additions and 9 deletions

View File

@ -142,7 +142,7 @@ impl SendingMessage {
}
pub fn contain_file(&self) -> bool { self.file.is_some() }
pub fn add_img(&mut self, file: Vec<u8>, ) { self.file = Some(file); }
pub fn add_img(&mut self, file: Vec<u8>) { self.file = Some(file); }
pub fn as_value(&self) -> JsonValue { serde_json::to_value(self).unwrap() }
}

View File

@ -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

View File

@ -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()),

View File

@ -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 {

View File

@ -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<BotStatus>) {
let handled = [
// 真正处理过的
"notify:chat.message.add",

View File

@ -9,7 +9,11 @@
- `ReceiveMessage::meta`
- 从 `JsonValue` 改成 `Option<JsonValue>`
- 用来解决发图片的时候没有 `meta` 字段的问题
- 去除了
- 去除了自带的两个 macro
- `wrap_callback``wrap_any_callback`
- 因为现在他俩已经进到 `rust_socketio` 里啦
- 添加了新的 macro
- ``
## 0.6.7