mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 12:41:05 +08:00
去掉自己的那个macro,准备上下一波
This commit is contained in:
parent
cd67c5b94d
commit
5db2978eb5
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -6,8 +6,7 @@ config.toml
|
||||||
*.pyc
|
*.pyc
|
||||||
*__pycache__/
|
*__pycache__/
|
||||||
|
|
||||||
|
make.ps1
|
||||||
|
|
||||||
# Added by cargo
|
# Added by cargo
|
||||||
|
|
||||||
/target
|
/target
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
|
|
||||||
use futures_util::FutureExt;
|
|
||||||
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 tracing::{event, span, Level};
|
use tracing::{event, span, Level};
|
||||||
|
|
||||||
use crate::config::IcaConfig;
|
use crate::config::IcaConfig;
|
||||||
use crate::error::{ClientResult, IcaError};
|
use crate::error::{ClientResult, IcaError};
|
||||||
use crate::{wrap_any_callback, wrap_callback, StopGetter};
|
use crate::StopGetter;
|
||||||
|
|
||||||
const ICA_PROTOCOL_VERSION: &str = "2.12.6";
|
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())
|
let socket = match ClientBuilder::new(config.host.clone())
|
||||||
.transport_type(TransportType::Websocket)
|
.transport_type(TransportType::Websocket)
|
||||||
.on_any(wrap_any_callback!(events::any_event))
|
.on_any(async_any_callback!(events::any_event))
|
||||||
.on("requireAuth", wrap_callback!(client::sign_callback))
|
.on("requireAuth", async_callback!(client::sign_callback))
|
||||||
.on("message", wrap_callback!(events::connect_callback))
|
.on("message", async_callback!(events::connect_callback))
|
||||||
.on("authSucceed", wrap_callback!(events::connect_callback))
|
.on("authSucceed", async_callback!(events::connect_callback))
|
||||||
.on("authFailed", wrap_callback!(events::connect_callback))
|
.on("authFailed", async_callback!(events::connect_callback))
|
||||||
.on("messageSuccess", wrap_callback!(events::succes_message))
|
.on("messageSuccess", async_callback!(events::succes_message))
|
||||||
.on("messageFailed", wrap_callback!(events::failed_message))
|
.on("messageFailed", async_callback!(events::failed_message))
|
||||||
.on("onlineData", wrap_callback!(events::get_online_data))
|
.on("onlineData", async_callback!(events::get_online_data))
|
||||||
.on("setAllRooms", wrap_callback!(events::update_all_room))
|
.on("setAllRooms", async_callback!(events::update_all_room))
|
||||||
.on("setMessages", wrap_callback!(events::set_messages))
|
.on("setMessages", async_callback!(events::set_messages))
|
||||||
.on("addMessage", wrap_callback!(events::add_message))
|
.on("addMessage", async_callback!(events::add_message))
|
||||||
.on("deleteMessage", wrap_callback!(events::delete_message))
|
.on("deleteMessage", async_callback!(events::delete_message))
|
||||||
.connect()
|
.connect()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|
|
@ -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) {
|
pub async fn add_message(payload: Payload, client: Client) {
|
||||||
if let Payload::Text(values) = payload {
|
if let Payload::Text(values) = payload {
|
||||||
|
|
|
@ -28,19 +28,16 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
pub const ICA_VERSION: &str = "1.6.0";
|
pub const ICA_VERSION: &str = "1.6.0";
|
||||||
pub const TAILCHAT_VERSION: &str = "1.1.0";
|
pub const TAILCHAT_VERSION: &str = "1.1.0";
|
||||||
|
|
||||||
#[macro_export]
|
/// usage:
|
||||||
macro_rules! wrap_callback {
|
/// #[derive(Clone)]
|
||||||
($f:expr) => {
|
/// struct BotState(String);
|
||||||
|payload: Payload, client: Client| $f(payload, client).boxed()
|
///
|
||||||
};
|
/// async fn some_event_with_state(payload: Payload, client: Client, state: Arc<BotState>) {
|
||||||
}
|
/// // do something
|
||||||
|
///
|
||||||
#[macro_export]
|
// macro_rules! wrap_callback_with_state {
|
||||||
macro_rules! wrap_any_callback {
|
// ($f:expr, $state:tt) => {};
|
||||||
($f:expr) => {
|
// }
|
||||||
|event: Event, payload: Payload, client: Client| $f(event, payload, client).boxed()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
|
|
@ -2,10 +2,10 @@ pub mod client;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use futures_util::FutureExt;
|
|
||||||
use md5::{Digest, Md5};
|
use md5::{Digest, Md5};
|
||||||
use reqwest::ClientBuilder as reqwest_ClientBuilder;
|
use reqwest::ClientBuilder as reqwest_ClientBuilder;
|
||||||
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};
|
||||||
|
@ -13,7 +13,7 @@ use tracing::{event, span, Level};
|
||||||
use crate::config::TailchatConfig;
|
use crate::config::TailchatConfig;
|
||||||
use crate::data_struct::tailchat::status::LoginData;
|
use crate::data_struct::tailchat::status::LoginData;
|
||||||
use crate::error::{ClientResult, TailchatError};
|
use crate::error::{ClientResult, TailchatError};
|
||||||
use crate::{wrap_any_callback, wrap_callback, StopGetter};
|
use crate::StopGetter;
|
||||||
|
|
||||||
pub async fn start_tailchat(
|
pub async fn start_tailchat(
|
||||||
config: TailchatConfig,
|
config: TailchatConfig,
|
||||||
|
@ -63,12 +63,12 @@ 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(wrap_any_callback!(events::any_event))
|
.on_any(async_any_callback!(events::any_event))
|
||||||
.on("notify:chat.message.add", wrap_callback!(events::on_message))
|
.on("notify:chat.message.add", async_callback!(events::on_message))
|
||||||
.on("notify:chat.message.delete", wrap_callback!(events::on_msg_delete))
|
.on("notify:chat.message.delete", async_callback!(events::on_msg_delete))
|
||||||
.on(
|
.on(
|
||||||
"notify:chat.converse.updateDMConverse",
|
"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.update", wrap_callback!(events::on_message))
|
||||||
// .on("notify:chat.message.addReaction", wrap_callback!(events::on_msg_update))
|
// .on("notify:chat.message.addReaction", wrap_callback!(events::on_msg_update))
|
||||||
|
|
|
@ -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) {
|
pub async fn on_message(payload: Payload, client: Client) {
|
||||||
if let Payload::Text(values) = payload {
|
if let Payload::Text(values) = payload {
|
||||||
if let Some(value) = values.first() {
|
if let Some(value) = values.first() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user