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;
1616mod media;
1717mod page_up;
1818mod upload;
19mod part;
1920mod verification;
2021
2122use buffer_clear::BufferClearCommand;
@@ -27,6 +28,7 @@ use me::MeCommand;
2728use media::MediaCommand;
2829use page_up::PageUpCommand;
2930use upload::UploadCommand;
31use part::PartCommand;
3032
3133pub struct Commands {
3234 _matrix: Command,
@@ -38,6 +40,7 @@ pub struct Commands {
3840 _join: CommandRun,
3941 _me: CommandRun,
4042 _upload: CommandRun,
43 _part: CommandRun,
4144}
4245
4346impl Commands {
@@ -55,6 +58,7 @@ impl Commands {
5558 _join: JoinCommand::create(servers)?,
5659 _me: MeCommand::create(servers)?,
5760 _upload: UploadCommand::create(servers)?,
61 _part: PartCommand::create(servers)?,
5862 })
5963 }
6064}
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}