config: >rehash command to reload rustbot.conf live (channels/nick/prefix/verbose/modules) without a restart
All checks were successful
ci / check (push) Successful in 47s

This commit is contained in:
Jean Chevronnet 2026-07-30 01:40:18 +00:00
parent 6af92c1217
commit 3c2154bbc1
No known key found for this signature in database
GPG key ID: 439666D63A9477E4
7 changed files with 226 additions and 20 deletions

View file

@ -76,3 +76,52 @@ fn ignores_own_echoed_message() {
let out = run(":rubot!r@h PRIVMSG #chan :!ping\r\n");
assert!(!out.contains(":pong"), "{out}");
}
#[test]
fn rehash_applies_channel_nick_and_prefix() {
let output = Arc::new(Mutex::new(Vec::new()));
let mock = Mock {
input: Cursor::new(Vec::new()),
output: output.clone(),
};
let conn = Connection::from_stream(mock);
let cfg = Config {
name: "testnet".to_string(),
channels: vec!["#a".to_string(), "#keep".to_string()],
..Config::default()
};
let mut bot = Bot::new(cfg, conn);
let new = Config {
name: "testnet".to_string(),
channels: vec!["#keep".to_string(), "#b".to_string()],
command_prefix: ">".to_string(),
nick: "rubot2".to_string(),
..Config::default()
};
let summary = bot.apply_config(new).unwrap();
let out = String::from_utf8_lossy(&output.lock().unwrap()).into_owned();
assert!(out.contains("JOIN #b"), "{out}");
assert!(out.contains("PART #a"), "{out}");
assert!(!out.contains("PART #keep"), "{out}");
assert!(out.contains("NICK rubot2"), "{out}");
assert!(
summary.contains("+#b") && summary.contains("-#a"),
"{summary}"
);
assert!(
summary.contains("prefix") && summary.contains("nick"),
"{summary}"
);
}
#[test]
fn rehash_command_requires_admin() {
// no admin configured -> ignored (default prefix is !)
let out = run(":alice!a@h PRIVMSG #chan :!rehash\r\n");
assert!(
!out.contains("rehash:"),
"unauthorized rehash replied: {out}"
);
}

View file

@ -48,3 +48,13 @@ fn comments_and_blanks_are_ignored() {
assert_eq!(cfgs.len(), 1);
assert_eq!(cfgs[0].server, "irc.tchatou.fr");
}
#[test]
fn admin_list_is_parsed_and_inherited() {
let cfgs = parse_str("admin = reverse, alice\nwebchat = https://w/\n[net]\nserver = x\n");
assert_eq!(
cfgs[0].admin,
vec!["reverse".to_string(), "alice".to_string()]
);
assert_eq!(cfgs[0].webchat, "https://w/");
}