Commit f8b5484def

f8b5484defe46cd50e7b9ea217843de0f0cbea8d

parent: 9dcbd9a291

Unsigned

Jakub Panek <me@panekj.dev> · 2025-04-21 19:17 UTC
committer: <poljar@termina.org.uk>

commands: add /me

Layout: unified · split

src/commands/me.rs added +47
@@ -0,0 +1,47 @@
1use std::borrow::Cow;
2
3use matrix_sdk::ruma::events::{
4 message::MessageEventContent,
5 room::message::{NoticeMessageEventContent, RoomMessageEventContent},
6};
7use weechat::{
8 buffer::Buffer,
9 hooks::{CommandRun, CommandRunCallback},
10 ReturnCode, Weechat,
11};
12
13use crate::Servers;
14
15pub struct MeCommand {
16 servers: Servers,
17}
18
19impl 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
30impl 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;
10mod devices; 10mod devices;
11mod keys; 11mod keys;
12mod matrix; 12mod matrix;
13mod me;
13mod page_up; 14mod page_up;
14 15
15use buffer_clear::BufferClearCommand; 16use buffer_clear::BufferClearCommand;
16use devices::DevicesCommand; 17use devices::DevicesCommand;
17use keys::KeysCommand; 18use keys::KeysCommand;
18use matrix::MatrixCommand; 19use matrix::MatrixCommand;
20use me::MeCommand;
19use page_up::PageUpCommand; 21use page_up::PageUpCommand;
20 22
21pub struct Commands { 23pub struct Commands {
@@ -24,6 +26,7 @@ pub struct Commands {
24 _devices: Command, 26 _devices: Command,
25 _page_up: CommandRun, 27 _page_up: CommandRun,
26 _buffer_clear: CommandRun, 28 _buffer_clear: CommandRun,
29 _me: CommandRun,
27} 30}
28 31
29impl Commands { 32impl Commands {
@@ -37,6 +40,7 @@ impl Commands {
37 _keys: KeysCommand::create(servers)?, 40 _keys: KeysCommand::create(servers)?,
38 _page_up: PageUpCommand::create(servers)?, 41 _page_up: PageUpCommand::create(servers)?,
39 _buffer_clear: BufferClearCommand::create(servers)?, 42 _buffer_clear: BufferClearCommand::create(servers)?,
43 _me: MeCommand::create(servers)?,
40 }) 44 })
41 } 45 }
42} 46}