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 {