Commit f8b5484def
Unsigned
Layout: unified · split
src/commands/me.rs added +47
| @@ -0,0 +1,47 @@ | ||
| 1 | use std::borrow::Cow; | |
| 2 | ||
| 3 | use matrix_sdk::ruma::events::{ | |
| 4 | message::MessageEventContent, | |
| 5 | room::message::{NoticeMessageEventContent, RoomMessageEventContent}, | |
| 6 | }; | |
| 7 | use weechat::{ | |
| 8 | buffer::Buffer, | |
| 9 | hooks::{CommandRun, CommandRunCallback}, | |
| 10 | ReturnCode, Weechat, | |
| 11 | }; | |
| 12 | ||
| 13 | use crate::Servers; | |
| 14 | ||
| 15 | pub struct MeCommand { | |
| 16 | servers: Servers, | |
| 17 | } | |
| 18 | ||
| 19 | impl MeCommand { | |
| 20 | pub fn create(servers: &Servers) -> Result<CommandRun, ()> { | |
| 21 | CommandRun::new( | |
| 22 | "/me", | |
| 23 | MeCommand { | |
| 24 | servers: servers.clone(), | |
| 25 | }, | |
| 26 | ) | |
| 27 | } | |
| 28 | } | |
| 29 | ||
| 30 | impl CommandRunCallback for MeCommand { | |
| 31 | fn callback( | |
| 32 | &mut self, | |
| 33 | _: &Weechat, | |
| 34 | buffer: &Buffer, | |
| 35 | cmd: Cow<str>, | |
| 36 | ) -> ReturnCode { | |
| 37 | if let Some(room) = self.servers.find_room(buffer) { | |
| 38 | self.servers.runtime().block_on(room.send_message( | |
| 39 | RoomMessageEventContent::emote_plain( | |
| 40 | cmd.strip_prefix("/me ").map(|s| s.to_string()).unwrap(), | |
| 41 | ), | |
| 42 | )); | |
| 43 | } | |
| 44 | ||
| 45 | ReturnCode::Ok | |
| 46 | } | |
| 47 | } | |
src/commands/mod.rs +4
| @@ -10,12 +10,14 @@ mod buffer_clear; | ||
| 10 | 10 | mod devices; |
| 11 | 11 | mod keys; |
| 12 | 12 | mod matrix; |
| 13 | mod me; | |
| 13 | 14 | mod page_up; |
| 14 | 15 | |
| 15 | 16 | use buffer_clear::BufferClearCommand; |
| 16 | 17 | use devices::DevicesCommand; |
| 17 | 18 | use keys::KeysCommand; |
| 18 | 19 | use matrix::MatrixCommand; |
| 20 | use me::MeCommand; | |
| 19 | 21 | use page_up::PageUpCommand; |
| 20 | 22 | |
| 21 | 23 | pub struct Commands { |
| @@ -24,6 +26,7 @@ pub struct Commands { | ||
| 24 | 26 | _devices: Command, |
| 25 | 27 | _page_up: CommandRun, |
| 26 | 28 | _buffer_clear: CommandRun, |
| 29 | _me: CommandRun, | |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | 32 | impl Commands { |
| @@ -37,6 +40,7 @@ impl Commands { | ||
| 37 | 40 | _keys: KeysCommand::create(servers)?, |
| 38 | 41 | _page_up: PageUpCommand::create(servers)?, |
| 39 | 42 | _buffer_clear: BufferClearCommand::create(servers)?, |
| 43 | _me: MeCommand::create(servers)?, | |
| 40 | 44 | }) |
| 41 | 45 | } |
| 42 | 46 | } |