mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 12:41:05 +08:00
p2
This commit is contained in:
parent
ca9033a23f
commit
de12c495f0
|
@ -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() }
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue
Block a user