socket-bot/ica-rs/src/tailchat/client.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

2024-06-04 23:48:01 +08:00
use crate::data_struct::tailchat::messages::SendingMessage;
// use crate::data_struct::tailchat::{ConverseId, GroupId, MessageId, UserId};
2024-03-30 18:30:43 +08:00
2024-06-04 23:48:01 +08:00
use rust_socketio::asynchronous::Client;
use colored::Colorize;
2024-06-10 16:05:24 +08:00
use serde_json::{json, Value};
use tracing::{debug, info, warn};
2024-06-04 23:48:01 +08:00
pub async fn send_message(client: &Client, message: &SendingMessage) -> bool {
2024-06-15 00:35:21 +08:00
if message.contain_file() {
// 处理文件
}
2024-06-04 23:48:01 +08:00
let value: Value = message.as_value();
match client.emit("chat.message.sendMessage", value).await {
Ok(_) => {
debug!("send_message {}", format!("{:#?}", message).cyan());
true
}
Err(e) => {
warn!("send_message faild:{}", format!("{:#?}", e).red());
false
}
}
}
2024-06-10 16:05:24 +08:00
pub async fn emit_join_room(client: &Client) -> bool {
match client.emit("chat.converse.findAndJoinRoom", json!([])).await {
Ok(_) => {
info!("emiting join room");
true
}
Err(e) => {
warn!("emit_join_room faild:{}", format!("{:#?}", e).red());
false
}
}
}