From 3d08a7da9147f5678bb894559993f9f40f72d860 Mon Sep 17 00:00:00 2001 From: shenjack-5600u <3695888@qq.com> Date: Mon, 31 Mar 2025 06:31:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E4=B8=80=E4=B8=8B=20join=20r?= =?UTF-8?q?equest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/src/data_struct/ica/all_rooms.rs | 37 ++++++++++++++++++++++++- ica-rs/src/ica.rs | 1 + ica-rs/src/ica/events.rs | 24 ++++++++++++++-- news/0-9.md | 4 ++- 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/ica-rs/src/data_struct/ica/all_rooms.rs b/ica-rs/src/data_struct/ica/all_rooms.rs index 2837feb..3b0e1c3 100644 --- a/ica-rs/src/data_struct/ica/all_rooms.rs +++ b/ica-rs/src/data_struct/ica/all_rooms.rs @@ -1,5 +1,5 @@ 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_json::{Number, Value as JsonValue}; @@ -101,3 +101,38 @@ struct InnerRoom { // #[serde(rename = "downloadPath")] // pub download_path: Option, } + + +/// ```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, +} diff --git a/ica-rs/src/ica.rs b/ica-rs/src/ica.rs index dac8d4c..9d8e9d5 100644 --- a/ica-rs/src/ica.rs +++ b/ica-rs/src/ica.rs @@ -63,6 +63,7 @@ pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientRe .on("setMessages", async_callback!(events::set_messages)) .on("addMessage", async_callback!(events::add_message)) .on("deleteMessage", async_callback!(events::delete_message)) + .on("handleRequest", async_callback!(events::join_request)) .connect() .await { diff --git a/ica-rs/src/ica/events.rs b/ica-rs/src/ica/events.rs index 98c5b5a..48968c5 100644 --- a/ica-rs/src/ica/events.rs +++ b/ica-rs/src/ica/events.rs @@ -4,7 +4,7 @@ use rust_socketio::{Event, Payload}; use serde_json::json; 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::online_data::OnlineData; 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::(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_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) { let handled = vec![ @@ -200,11 +220,11 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) { "deleteMessage", "setAllRooms", "setMessages", + "handleRequest", // 处理验证消息 (加入请求之类的) // 也许以后会用到 "messageSuccess", "messageFailed", "setAllChatGroups", - "handleRequest", // 处理验证消息 (加入请求之类的) // 忽略的 "notify", "setShutUp", // 禁言 diff --git a/news/0-9.md b/news/0-9.md index c4b24bf..7ae4c5b 100644 --- a/news/0-9.md +++ b/news/0-9.md @@ -1,6 +1,8 @@ # 0.9 更新日志 -## ica 2.0.1 +## 0.9.0 + +### ica 2.0.1 > 添加了 `Room` 相关的 api