处理一下 join request

This commit is contained in:
shenjack-5600u 2025-03-31 06:31:48 +08:00
parent e41279d843
commit 3d08a7da91
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F
4 changed files with 62 additions and 4 deletions

View File

@ -1,5 +1,5 @@
use crate::data_struct::ica::messages::{At, LastMessage, SendMessage}; use crate::data_struct::ica::messages::{At, LastMessage, SendMessage};
use crate::data_struct::ica::RoomId; use crate::data_struct::ica::{RoomId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{Number, Value as JsonValue}; use serde_json::{Number, Value as JsonValue};
@ -101,3 +101,38 @@ struct InnerRoom {
// #[serde(rename = "downloadPath")] // #[serde(rename = "downloadPath")]
// pub download_path: Option<String>, // pub download_path: Option<String>,
} }
/// ```json
/// {
/// "comment": "问题:从哪里了解到的本群\n答案aaa",
/// "flag": "e4cd5a892ba34bed063196a0cc47a8",
/// "group_id": xxxxx,
/// "group_name": "Nuitka 和 Python 打包",
/// "nickname": "jashcken",
/// "post_type": "request",
/// "request_type": "group",
/// "self_id": 45620725,
/// "sub_type": "add",
/// "time": 1743372872,
/// "tips": "",
/// "user_id": 3838663305
/// }
/// ```
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct JoinRequestRoom {
/// 问题+答案
pub comment: String,
pub group_id: RoomId,
pub group_name: String,
pub user_id: UserId,
pub nickname: String,
// 剩下的应该没用了……吧?
pub request_type: String,
pub post_type: String,
pub sub_type: String,
pub time: i64,
pub tips: String,
pub flag: String,
}

View File

@ -63,6 +63,7 @@ pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientRe
.on("setMessages", async_callback!(events::set_messages)) .on("setMessages", async_callback!(events::set_messages))
.on("addMessage", async_callback!(events::add_message)) .on("addMessage", async_callback!(events::add_message))
.on("deleteMessage", async_callback!(events::delete_message)) .on("deleteMessage", async_callback!(events::delete_message))
.on("handleRequest", async_callback!(events::join_request))
.connect() .connect()
.await .await
{ {

View File

@ -4,7 +4,7 @@ use rust_socketio::{Event, Payload};
use serde_json::json; use serde_json::json;
use tracing::{event, info, span, warn, Level}; use tracing::{event, info, span, warn, Level};
use crate::data_struct::ica::all_rooms::Room; use crate::data_struct::ica::all_rooms::{JoinRequestRoom, Room};
use crate::data_struct::ica::messages::{Message, MessageTrait, NewMessage}; use crate::data_struct::ica::messages::{Message, MessageTrait, NewMessage};
use crate::data_struct::ica::online_data::OnlineData; use crate::data_struct::ica::online_data::OnlineData;
use crate::data_struct::ica::RoomId; use crate::data_struct::ica::RoomId;
@ -175,6 +175,25 @@ pub async fn failed_message(payload: Payload, _client: Client) {
} }
} }
/// 处理加群申请
///
/// add: 2.0.1
pub async fn join_request(payload: Payload, _client: Client) {
if let Payload::Text(values) = payload {
if let Some(value) = values.first() {
match serde_json::from_value::<JoinRequestRoom>(value.clone()) {
Ok(join_room) => {
event!(Level::INFO, "{}", format!("收到加群申请 {:?}", join_room).on_blue());
},
Err(e) => {
event!(Level::WARN, "呼叫 shenjack! JoinRequestRoom 的 serde 没写好! {}\nraw: {:#?}", e, value)
},
}
}
}
}
pub async fn fetch_history(client: Client, room: RoomId) { let mut request_body = json!(room); } pub async fn fetch_history(client: Client, room: RoomId) { let mut request_body = json!(room); }
pub async fn fetch_messages(client: &Client, room: RoomId) { pub async fn fetch_messages(client: &Client, room: RoomId) {
@ -187,6 +206,7 @@ pub async fn fetch_messages(client: &Client, room: RoomId) {
} }
} }
/// 所有 /// 所有
pub async fn any_event(event: Event, payload: Payload, _client: Client) { pub async fn any_event(event: Event, payload: Payload, _client: Client) {
let handled = vec![ let handled = vec![
@ -200,11 +220,11 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
"deleteMessage", "deleteMessage",
"setAllRooms", "setAllRooms",
"setMessages", "setMessages",
"handleRequest", // 处理验证消息 (加入请求之类的)
// 也许以后会用到 // 也许以后会用到
"messageSuccess", "messageSuccess",
"messageFailed", "messageFailed",
"setAllChatGroups", "setAllChatGroups",
"handleRequest", // 处理验证消息 (加入请求之类的)
// 忽略的 // 忽略的
"notify", "notify",
"setShutUp", // 禁言 "setShutUp", // 禁言

View File

@ -1,6 +1,8 @@
# 0.9 更新日志 # 0.9 更新日志
## ica 2.0.1 ## 0.9.0
### ica 2.0.1
> 添加了 `Room` 相关的 api > 添加了 `Room` 相关的 api