From 08ab5575014bcfb13e1e2b9664dd6ae930637123 Mon Sep 17 00:00:00 2001 From: Chikage Date: Sun, 15 Oct 2023 14:53:30 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0help?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/qbittorrent/src/matrix.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/plugins/qbittorrent/src/matrix.rs b/plugins/qbittorrent/src/matrix.rs index 07aed37..c0f71e2 100644 --- a/plugins/qbittorrent/src/matrix.rs +++ b/plugins/qbittorrent/src/matrix.rs @@ -75,6 +75,37 @@ pub fn add_listener(room: &matrix::room::Room) { }, ); + room.0.add_event_handler( + |event: OriginalSyncRoomMessageEvent, room: matrix_sdk::room::Room| async move { + if let matrix_sdk::room::Room::Joined(room) = room { + let msg_body = match event.content.msgtype { + MessageType::Text(TextMessageEventContent { body, .. }) => body, + _ => return, + }; + + let msg_body = msg_body.trim(); + + if msg_body.is_empty() { + return; + } + if msg_body.starts_with("!qbithelp") { + let room_id = room.room_id().as_str(); + + let map = ROOM_MAP.get().and_then(|map| map.get(room_id)); + + if let Some((room, _setting)) = map { + let msg = "!download - 添加磁力至下载\n!status - 查看下载状态"; + room.send_relates_msg(&msg, event.event_id.as_str(), false) + .await + .unwrap_or_else(|e| { + log::error!("send message failed: {}", e); + }); + } + } + } + }, + ); + room.0.add_event_handler( |event: OriginalSyncRoomMessageEvent, room: matrix_sdk::room::Room| async move { if let matrix_sdk::room::Room::Joined(room) = room {