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;
1010mod devices;
1111mod keys;
1212mod matrix;
13mod me;
1314mod page_up;
1415
1516use buffer_clear::BufferClearCommand;
1617use devices::DevicesCommand;
1718use keys::KeysCommand;
1819use matrix::MatrixCommand;
20use me::MeCommand;
1921use page_up::PageUpCommand;
2022
2123pub struct Commands {
@@ -24,6 +26,7 @@ pub struct Commands {
2426 _devices: Command,
2527 _page_up: CommandRun,
2628 _buffer_clear: CommandRun,
29 _me: CommandRun,
2730}
2831
2932impl Commands {
@@ -37,6 +40,7 @@ impl Commands {
3740 _keys: KeysCommand::create(servers)?,
3841 _page_up: PageUpCommand::create(servers)?,
3942 _buffer_clear: BufferClearCommand::create(servers)?,
43 _me: MeCommand::create(servers)?,
4044 })
4145 }
4246}