Commit b8c248a756

b8c248a7565fa36f48582b583f25b8dcc17425d1

parent: ef39e6b642

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-07-22 11:40 UTC
committer: <strk@kbt.io>

fix: reject ignore in Matrix buffers

Layout: unified · split

src/commands/ignore.rs added +74
@@ -0,0 +1,74 @@
1use std::borrow::Cow;
2
3use weechat::{
4 buffer::Buffer,
5 hooks::{CommandRun, CommandRunCallback},
6 Prefix, ReturnCode, Weechat,
7};
8
9use crate::PLUGIN_NAME;
10
11pub struct IgnoreCommand;
12
13#[derive(Debug, Eq, PartialEq)]
14enum IgnoreDisposition {
15 EatWithUnsupportedMessage,
16 PassThrough,
17}
18
19impl IgnoreCommand {
20 pub fn create() -> Result<[CommandRun; 2], ()> {
21 Ok([
22 CommandRun::new("2000|/ignore", IgnoreCommand)?,
23 CommandRun::new("2000|/ignore *", IgnoreCommand)?,
24 ])
25 }
26}
27
28fn disposition(plugin_name: &str) -> IgnoreDisposition {
29 if plugin_name == PLUGIN_NAME {
30 IgnoreDisposition::EatWithUnsupportedMessage
31 } else {
32 IgnoreDisposition::PassThrough
33 }
34}
35
36impl CommandRunCallback for IgnoreCommand {
37 fn callback(
38 &mut self,
39 _: &Weechat,
40 buffer: &Buffer,
41 _: Cow<str>,
42 ) -> ReturnCode {
43 match disposition(&buffer.plugin_name()) {
44 IgnoreDisposition::EatWithUnsupportedMessage => {
45 buffer.print(&format!(
46 "{}{}: /ignore is not supported in Matrix buffers.",
47 Weechat::prefix(Prefix::Error),
48 PLUGIN_NAME,
49 ));
50 ReturnCode::OkEat
51 }
52 IgnoreDisposition::PassThrough => ReturnCode::Ok,
53 }
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 use super::{disposition, IgnoreDisposition};
60
61 #[test]
62 fn eats_ignore_in_matrix_buffers() {
63 assert_eq!(
64 IgnoreDisposition::EatWithUnsupportedMessage,
65 disposition("matrix")
66 );
67 }
68
69 #[test]
70 fn passes_ignore_through_in_other_buffers() {
71 assert_eq!(IgnoreDisposition::PassThrough, disposition("irc"));
72 assert_eq!(IgnoreDisposition::PassThrough, disposition("core"));
73 }
74}
src/commands/mod.rs +4
@@ -9,6 +9,7 @@ use crate::{config::ConfigHandle, Servers};
9 9
10mod buffer_clear; 10mod buffer_clear;
11mod devices; 11mod devices;
12mod ignore;
12mod invite; 13mod invite;
13mod join; 14mod join;
14mod keys; 15mod keys;
@@ -26,6 +27,7 @@ mod verification;
26 27
27use buffer_clear::BufferClearCommand; 28use buffer_clear::BufferClearCommand;
28use devices::DevicesCommand; 29use devices::DevicesCommand;
30use ignore::IgnoreCommand;
29use invite::InviteCommand; 31use invite::InviteCommand;
30use join::JoinCommand; 32use join::JoinCommand;
31use keys::KeysCommand; 33use keys::KeysCommand;
@@ -45,6 +47,7 @@ pub struct Commands {
45 _keys: Command, 47 _keys: Command,
46 _devices: Command, 48 _devices: Command,
47 _invite: Command, 49 _invite: Command,
50 _ignore: [CommandRun; 2],
48 _ban: Command, 51 _ban: Command,
49 _kick: Command, 52 _kick: Command,
50 _page_up: CommandRun, 53 _page_up: CommandRun,
@@ -69,6 +72,7 @@ impl Commands {
69 _matrix: MatrixCommand::create(servers, config)?, 72 _matrix: MatrixCommand::create(servers, config)?,
70 _devices: DevicesCommand::create(servers)?, 73 _devices: DevicesCommand::create(servers)?,
71 _invite: InviteCommand::create(servers)?, 74 _invite: InviteCommand::create(servers)?,
75 _ignore: IgnoreCommand::create()?,
72 _ban: ModerationCommand::ban(servers)?, 76 _ban: ModerationCommand::ban(servers)?,
73 _kick: ModerationCommand::kick(servers)?, 77 _kick: ModerationCommand::kick(servers)?,
74 _keys: KeysCommand::create(servers)?, 78 _keys: KeysCommand::create(servers)?,