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};
99
1010mod buffer_clear;
1111mod devices;
12mod ignore;
1213mod invite;
1314mod join;
1415mod keys;
@@ -26,6 +27,7 @@ mod verification;
2627
2728use buffer_clear::BufferClearCommand;
2829use devices::DevicesCommand;
30use ignore::IgnoreCommand;
2931use invite::InviteCommand;
3032use join::JoinCommand;
3133use keys::KeysCommand;
@@ -45,6 +47,7 @@ pub struct Commands {
4547 _keys: Command,
4648 _devices: Command,
4749 _invite: Command,
50 _ignore: [CommandRun; 2],
4851 _ban: Command,
4952 _kick: Command,
5053 _page_up: CommandRun,
@@ -69,6 +72,7 @@ impl Commands {
6972 _matrix: MatrixCommand::create(servers, config)?,
7073 _devices: DevicesCommand::create(servers)?,
7174 _invite: InviteCommand::create(servers)?,
75 _ignore: IgnoreCommand::create()?,
7276 _ban: ModerationCommand::ban(servers)?,
7377 _kick: ModerationCommand::kick(servers)?,
7478 _keys: KeysCommand::create(servers)?,