mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-19 15:49:53 +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 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() }
|
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]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// -d -> debug
|
// -d -> debug
|
||||||
|
|
|
@ -6,8 +6,8 @@ use std::sync::Arc;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use md5::{Digest, Md5};
|
use md5::{Digest, Md5};
|
||||||
use reqwest::ClientBuilder as reqwest_ClientBuilder;
|
use reqwest::ClientBuilder as reqwest_ClientBuilder;
|
||||||
|
use rust_socketio::async_callback;
|
||||||
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 serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use tracing::{event, span, Level};
|
use tracing::{event, span, Level};
|
||||||
|
@ -15,7 +15,7 @@ use tracing::{event, span, Level};
|
||||||
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_callback_with_state, StopGetter};
|
use crate::{async_any_callback_with_state, async_callback_with_state, StopGetter};
|
||||||
|
|
||||||
pub async fn start_tailchat(
|
pub async fn start_tailchat(
|
||||||
config: TailchatConfig,
|
config: TailchatConfig,
|
||||||
|
@ -68,7 +68,7 @@ pub async fn start_tailchat(
|
||||||
let socket = ClientBuilder::new(config.host)
|
let socket = ClientBuilder::new(config.host)
|
||||||
.auth(json!({"token": status.jwt.clone()}))
|
.auth(json!({"token": status.jwt.clone()}))
|
||||||
.transport_type(TransportType::Websocket)
|
.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(
|
.on(
|
||||||
"notify:chat.message.add",
|
"notify:chat.message.add",
|
||||||
async_callback_with_state!(events::on_message, sharded_status.clone()),
|
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 {
|
pub async fn send_message(client: &Client, message: &SendingMessage) -> bool {
|
||||||
if message.contain_file() {
|
if message.contain_file() {
|
||||||
// 处理文件
|
// 处理文件
|
||||||
|
|
||||||
}
|
}
|
||||||
let value: Value = message.as_value();
|
let value: Value = message.as_value();
|
||||||
match client.emit("chat.message.sendMessage", value).await {
|
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};
|
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 = [
|
let handled = [
|
||||||
// 真正处理过的
|
// 真正处理过的
|
||||||
"notify:chat.message.add",
|
"notify:chat.message.add",
|
||||||
|
|
6
news.md
6
news.md
|
@ -9,7 +9,11 @@
|
||||||
- `ReceiveMessage::meta`
|
- `ReceiveMessage::meta`
|
||||||
- 从 `JsonValue` 改成 `Option<JsonValue>`
|
- 从 `JsonValue` 改成 `Option<JsonValue>`
|
||||||
- 用来解决发图片的时候没有 `meta` 字段的问题
|
- 用来解决发图片的时候没有 `meta` 字段的问题
|
||||||
- 去除了
|
- 去除了自带的两个 macro
|
||||||
|
- `wrap_callback` 和 `wrap_any_callback`
|
||||||
|
- 因为现在他俩已经进到 `rust_socketio` 里啦
|
||||||
|
- 添加了新的 macro
|
||||||
|
- ``
|
||||||
|
|
||||||
## 0.6.7
|
## 0.6.7
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user