Commit 2767831328

2767831328cf9aea957d46277333563bb605db49

parent: eaa25fa955

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-06-23 16:01 UTC
committer: <strk@kbt.io>

feat: add matrix part command

Layout: unified · split

src/commands/mod.rs +4
@@ -16,6 +16,7 @@ mod me;
16mod media; 16mod media;
17mod page_up; 17mod page_up;
18mod upload; 18mod upload;
19mod part;
19mod verification; 20mod verification;
20 21
21use buffer_clear::BufferClearCommand; 22use buffer_clear::BufferClearCommand;
@@ -27,6 +28,7 @@ use me::MeCommand;
27use media::MediaCommand; 28use media::MediaCommand;
28use page_up::PageUpCommand; 29use page_up::PageUpCommand;
29use upload::UploadCommand; 30use upload::UploadCommand;
31use part::PartCommand;
30 32
31pub struct Commands { 33pub struct Commands {
32 _matrix: Command, 34 _matrix: Command,
@@ -38,6 +40,7 @@ pub struct Commands {
38 _join: CommandRun, 40 _join: CommandRun,
39 _me: CommandRun, 41 _me: CommandRun,
40 _upload: CommandRun, 42 _upload: CommandRun,
43 _part: CommandRun,
41} 44}
42 45
43impl Commands { 46impl Commands {
@@ -55,6 +58,7 @@ impl Commands {
55 _join: JoinCommand::create(servers)?, 58 _join: JoinCommand::create(servers)?,
56 _me: MeCommand::create(servers)?, 59 _me: MeCommand::create(servers)?,
57 _upload: UploadCommand::create(servers)?, 60 _upload: UploadCommand::create(servers)?,
61 _part: PartCommand::create(servers)?,
58 }) 62 })
59 } 63 }
60} 64}
src/commands/part.rs added +50
@@ -0,0 +1,50 @@
1use std::borrow::Cow;
2
3use weechat::{
4 buffer::Buffer,
5 hooks::{CommandRun, CommandRunCallback},
6 ReturnCode, Weechat,
7};
8
9use crate::Servers;
10
11pub struct PartCommand {
12 servers: Servers,
13}
14
15impl PartCommand {
16 pub fn create(servers: &Servers) -> Result<CommandRun, ()> {
17 CommandRun::new(
18 "/part",
19 PartCommand {
20 servers: servers.clone(),
21 },
22 )
23 }
24}
25
26impl CommandRunCallback for PartCommand {
27 fn callback(
28 &mut self,
29 _: &Weechat,
30 buffer: &Buffer,
31 _: Cow<str>,
32 ) -> ReturnCode {
33 if let Some(room) = self.servers.find_room(buffer) {
34 let room = room.room().clone();
35
36 match self.servers.runtime().block_on(room.leave()) {
37 Ok(()) => ReturnCode::Ok,
38 Err(error) => {
39 Weechat::print(&format!("Failed to leave room: {}", error));
40 ReturnCode::Error
41 }
42 }
43 } else {
44 Weechat::print(
45 "The /part command needs to be run in a Matrix room buffer.",
46 );
47 ReturnCode::Error
48 }
49 }
50}