mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 12:41:05 +08:00
gogogo
This commit is contained in:
parent
0858085df7
commit
5a07286d2d
|
@ -14,7 +14,7 @@ pub async fn get_online_data(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() {
|
||||||
let online_data = OnlineData::new_from_json(value);
|
let online_data = OnlineData::new_from_json(value);
|
||||||
info!("update_online_data {}", format!("{:?}", online_data).cyan());
|
event!(Level::DEBUG, "update_online_data {}", format!("{:?}", online_data).cyan());
|
||||||
MainStatus::global_ica_status_mut().update_online_status(online_data);
|
MainStatus::global_ica_status_mut().update_online_status(online_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ pub async fn update_all_room(payload: Payload, _client: Client) {
|
||||||
if let Some(value) = values.first() {
|
if let Some(value) = values.first() {
|
||||||
if let Some(raw_rooms) = value.as_array() {
|
if let Some(raw_rooms) = value.as_array() {
|
||||||
let rooms: Vec<Room> = raw_rooms.iter().map(Room::new_from_json).collect();
|
let rooms: Vec<Room> = raw_rooms.iter().map(Room::new_from_json).collect();
|
||||||
info!("update_all_room {}", rooms.len());
|
event!(Level::DEBUG, "update_all_room {}", rooms.len());
|
||||||
MainStatus::global_ica_status_mut().update_rooms(rooms);
|
MainStatus::global_ica_status_mut().update_rooms(rooms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,21 +62,22 @@ pub async fn start_tailchat(
|
||||||
.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(wrap_any_callback!(events::any_event))
|
||||||
.on("chat.message.sendMessage", wrap_callback!(events::on_message))
|
.on("notify:chat.message.add", wrap_callback!(events::on_message))
|
||||||
|
.on("notify:chat.message.delete", wrap_callback!(events::on_msg_delete))
|
||||||
|
// .on("notify:chat.message.update", wrap_callback!(events::on_message))
|
||||||
|
// .on("notify:chat.message.addReaction", wrap_callback!(events::on_msg_update))
|
||||||
.connect()
|
.connect()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
event!(Level::INFO, "tailchat connected");
|
event!(Level::INFO, "tailchat connected");
|
||||||
|
|
||||||
// sleep for 1 sec
|
// sleep for 500ms to wait for the connection to be established
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||||
|
|
||||||
socket.emit("chat.converse.findAndJoinRoom", json!([])).await.unwrap();
|
socket.emit("chat.converse.findAndJoinRoom", json!([])).await.unwrap();
|
||||||
|
|
||||||
event!(Level::INFO, "tailchat joined room");
|
event!(Level::INFO, "tailchat joined room");
|
||||||
// notify:chat.message.delete
|
|
||||||
// notify:chat.message.add
|
|
||||||
|
|
||||||
stop_reciver.await.ok();
|
stop_reciver.await.ok();
|
||||||
event!(Level::INFO, "socketio client stopping");
|
event!(Level::INFO, "socketio client stopping");
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use rust_socketio::asynchronous::Client;
|
use rust_socketio::asynchronous::Client;
|
||||||
use rust_socketio::{Event, Payload};
|
use rust_socketio::{Event, Payload};
|
||||||
use serde_json::json;
|
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
|
use crate::data_struct::tailchat::messages::ReciveMessage;
|
||||||
|
|
||||||
/// 所有
|
/// 所有
|
||||||
pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
||||||
let handled = [
|
let handled = [
|
||||||
// 真正处理过的
|
// 真正处理过的
|
||||||
"chat.message.sendMessage",
|
"notify:chat.message.add",
|
||||||
// "notify:chat.message.add",
|
"notify:chat.message.delete",
|
||||||
// 也许以后会用到
|
// 也许以后会用到
|
||||||
|
"notify:chat.message.update",
|
||||||
|
"notify:chat.message.addReaction",
|
||||||
|
"notify:chat.message.removeReaction",
|
||||||
// 忽略的
|
// 忽略的
|
||||||
|
"notify:chat.inbox.append", // 被 @ 之类的事件
|
||||||
];
|
];
|
||||||
println!("event: {:?}", event);
|
|
||||||
println!("payload: {:?}", payload);
|
|
||||||
match &event {
|
match &event {
|
||||||
Event::Custom(event_name) => {
|
Event::Custom(event_name) => {
|
||||||
if handled.contains(&event_name.as_str()) {
|
if handled.contains(&event_name.as_str()) {
|
||||||
|
@ -54,18 +56,24 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn on_message(payload: Payload, client: Client) {
|
pub async fn on_message(payload: Payload, _client: Client) {
|
||||||
match payload {
|
match payload {
|
||||||
Payload::Text(values) => {
|
Payload::Text(values) => {
|
||||||
if let Some(value) = values.first() {
|
if let Some(value) = values.first() {
|
||||||
info!("收到消息 {}", value.to_string().yellow());
|
let message: ReciveMessage = serde_json::from_value(value.clone()).unwrap();
|
||||||
|
info!("收到消息 {:?}", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub async fn on_msg_delete(payload: Payload, _client: Client) {
|
||||||
pub async fn on_connect(payload: Payload, client: Client) {
|
match payload {
|
||||||
let _ = client.emit("chat.converse.findAndJoinRoom", json! {[]}).await;
|
Payload::Text(values) => {
|
||||||
info!("连接成功 {:?}", payload);
|
if let Some(value) = values.first() {
|
||||||
|
info!("删除消息 {}", value.to_string().red());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user