diff --git a/ica-rs/rustfmt.toml b/ica-rs/rustfmt.toml index 24a1762..089f403 100644 --- a/ica-rs/rustfmt.toml +++ b/ica-rs/rustfmt.toml @@ -21,3 +21,5 @@ use_field_init_shorthand = true color = "Always" edition = "2021" +# 这样不用 nightly 也可以使用 unstable 特性 +unstable_features = true diff --git a/ica-rs/src/ica/client.rs b/ica-rs/src/ica/client.rs index ab98839..1b60dbb 100644 --- a/ica-rs/src/ica/client.rs +++ b/ica-rs/src/ica/client.rs @@ -1,4 +1,5 @@ use crate::data_struct::ica::messages::{DeleteMessage, SendMessage}; +use crate::data_struct::ica::{RoomId, RoomIdTrait}; use crate::error::{ClientResult, IcaError}; use crate::MainStatus; @@ -23,6 +24,7 @@ pub async fn send_message(client: &Client, message: &SendMessage) -> bool { } } } + /// "安全" 的 删除一条消息 pub async fn delete_message(client: &Client, message: &DeleteMessage) -> bool { let value = message.as_value(); @@ -37,13 +39,14 @@ pub async fn delete_message(client: &Client, message: &DeleteMessage) -> bool { } } } + /// "安全" 的 获取历史消息 /// ```typescript /// async fetchHistory(messageId: string, roomId: number, currentLoadedMessagesCount: number) /// ``` // #[allow(dead_code)] // pub async fn fetch_history(client: &Client, roomd_id: RoomId) -> bool { false } -async fn inner_sign(payload: Payload, client: Client) -> ClientResult<(), IcaError> { +async fn inner_sign(payload: Payload, client: &Client) -> ClientResult<(), IcaError> { let span = span!(Level::INFO, "signing icalingua"); let _guard = span.enter(); @@ -100,5 +103,49 @@ async fn inner_sign(payload: Payload, client: Client) -> ClientResult<(), IcaErr /// 签名回调 /// 失败的时候得 panic pub async fn sign_callback(payload: Payload, client: Client) { - inner_sign(payload, client).await.expect("Faild to sign"); + inner_sign(payload, &client).await.expect("Faild to sign"); +} + +/// 向指定群发送签到信息 +/// +/// 只能是群啊, 不能是私聊 +pub async fn send_room_sign_in(client: &Client, room_id: RoomId) -> bool { + if room_id.is_chat() { + event!(Level::WARN, "不能向私聊发送签到信息"); + return false; + } + match client.emit("sendGroupSign", room_id).await { + Ok(_) => { + event!(Level::INFO, "已向群 {} 发送签到信息", room_id); + true + } + Err(e) => { + event!(Level::ERROR, "向群 {} 发送签到信息失败: {}", room_id, e); + false + } + } +} + +/// 向某个群/私聊的某个人发送戳一戳 +pub async fn send_poke(client: &Client, room_id: RoomId, target: UserId) -> bool { + match client.emit( + "sendGroupPoke", + (room_id, { + if room_id.is_chat() { + room_id + // 以防你 target 写错了 + } else { + target + } + }), + ) { + Ok(_) => { + event!(Level::INFO, "已向 {} 的 {} 发送戳一戳", room_id, target); + true + } + Err(e) => { + event!(Level::ERROR, "向 {} 的 {} 发送戳一戳失败: {}", room_id, target, e); + false + } + } } diff --git a/ica-rs/src/ica/events.rs b/ica-rs/src/ica/events.rs index e8b0e25..2a733c8 100644 --- a/ica-rs/src/ica/events.rs +++ b/ica-rs/src/ica/events.rs @@ -9,7 +9,7 @@ use crate::data_struct::ica::all_rooms::Room; use crate::data_struct::ica::messages::{Message, MessageTrait, NewMessage}; use crate::data_struct::ica::online_data::OnlineData; use crate::ica::client::send_message; -use crate::{client_id, help_msg, py, version_str, MainStatus, VERSION, start_up_time}; +use crate::{client_id, help_msg, py, start_up_time, version_str, MainStatus, VERSION}; /// 获取在线数据 pub async fn get_online_data(payload: Payload, _client: Client) { diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index 9c2eebc..b80e0d4 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -29,7 +29,7 @@ pub type MainStatus = status::BotStatus; pub type StopGetter = tokio::sync::oneshot::Receiver<()>; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); -pub const ICA_VERSION: &str = "1.6.4"; +pub const ICA_VERSION: &str = "1.6.5"; pub const TAILCHAT_VERSION: &str = "1.2.4"; const HELP_MSG: &str = r#"/bot-rs diff --git a/ica-rs/src/py/class/ica.rs b/ica-rs/src/py/class/ica.rs index b22b6ca..b3acc93 100644 --- a/ica-rs/src/py/class/ica.rs +++ b/ica-rs/src/py/class/ica.rs @@ -9,7 +9,7 @@ use crate::data_struct::ica::messages::{ DeleteMessage, MessageTrait, NewMessage, ReplyMessage, SendMessage, }; use crate::data_struct::ica::{MessageId, RoomId, RoomIdTrait}; -use crate::ica::client::{delete_message, send_message}; +use crate::ica::client::{delete_message, send_message, send_poke, send_room_sign_in}; use crate::MainStatus; #[pyclass] @@ -184,6 +184,26 @@ pub struct IcaClientPy { #[pymethods] impl IcaClientPy { + /// 签到 + /// + /// 添加自 1.6.5 版本 + pub fn send_room_sign_in(&self, room_id: RoomId) -> bool { + tokio::task::block_in_place(|| { + let rt = Runtime::new().unwrap(); + rt.block_on(send_room_sign_in(&self.client, room_id)) + }) + } + + /// 戳一戳 + /// + /// 添加自 1.6.5 版本 + pub fn send_poke(&self, room_id: RoomId, user_id: UserId) -> bool { + tokio::task::block_in_place(|| { + let rt = Runtime::new().unwrap(); + rt.block_on(send_poke(&self.client, room_id, user_id)) + }) + } + pub fn send_message(&self, message: SendMessagePy) -> bool { tokio::task::block_in_place(|| { let rt = Runtime::new().unwrap(); diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index db33710..8d2ff10 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -59,9 +59,7 @@ impl PyStatus { self.files.get(path).map(|plugin| plugin.enabled) } - pub fn sync_status(&mut self) { - self.config.sync_status_from_config(); - } + pub fn sync_status(&mut self) { self.config.sync_status_from_config(); } pub fn set_status(&mut self, path: &Path, status: bool) { self.config.set_status(path, status); diff --git a/ica-rs/src/tailchat/events.rs b/ica-rs/src/tailchat/events.rs index 37b2d23..ff682b1 100644 --- a/ica-rs/src/tailchat/events.rs +++ b/ica-rs/src/tailchat/events.rs @@ -8,10 +8,10 @@ use tracing::{event, info, Level}; use crate::data_struct::tailchat::messages::ReceiveMessage; use crate::data_struct::tailchat::status::{BotStatus, UpdateDMConverse}; -use crate::tailchat::client::{emit_join_room, send_message}; -use crate::py::PyStatus; use crate::py::call::tailchat_new_message_py; -use crate::{client_id, help_msg, version_str, MainStatus, VERSION, start_up_time}; +use crate::py::PyStatus; +use crate::tailchat::client::{emit_join_room, send_message}; +use crate::{client_id, help_msg, start_up_time, version_str, MainStatus, VERSION}; /// 所有 pub async fn any_event(event: Event, payload: Payload, _client: Client, _status: Arc) { @@ -97,7 +97,7 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc format!("{:?}", d), diff --git a/news.md b/news.md index f705624..05c566e 100644 --- a/news.md +++ b/news.md @@ -6,6 +6,17 @@ - 从 `py::PyStatus` 开始进行一个 `static mut` -> `static mut OnceLock` 的改造 - 用于看着更舒服(逃) +### ica 1.6.5 + +- 添加了 `send_room_sign_in` api + - 用于发送群签到信息 + - socketio event: `sendGroupSign` +- 添加了 `send_poke` api + - 用于发送戳一戳 + - 可以指定群的某个人 + - 或者指定好友 + - socketio event: `sendGroupPoke` + ## 0.7.4 - ica 兼容版本号更新到 `2.12.23`