BotServ: richer TRIGGERs — capture groups + cooldown

Responses can now use $1..$9 to substitute regex capture groups (e.g.
ADD hi (\w+)|Hi $1!), and an optional trailing |<secs> sets a per-trigger
cooldown so a trigger can't be spammed. The cache compiles each pattern to
its own Regex (for captures) and tracks last-fired for the cooldown.
This commit is contained in:
Jean Chevronnet 2026-07-13 19:25:35 +00:00
parent 766ef6ca47
commit 374748b1f9
No known key found for this signature in database
4 changed files with 92 additions and 22 deletions

View file

@ -351,6 +351,7 @@ pub struct MemoView {
pub struct TriggerView {
pub pattern: String,
pub response: String,
pub cooldown: u32,
}
#[derive(Debug, Clone)]
@ -598,7 +599,7 @@ pub trait Store {
// Copy one channel's BotServ config (kickers/badwords/greet/nobot) to another.
fn copy_bot_config(&mut self, src: &str, dst: &str) -> Result<(), ChanError>;
// Auto-response triggers (regex -> response).
fn trigger_add(&mut self, channel: &str, pattern: &str, response: &str) -> Result<bool, ChanError>;
fn trigger_add(&mut self, channel: &str, pattern: &str, response: &str, cooldown: u32) -> Result<bool, ChanError>;
fn trigger_del(&mut self, channel: &str, index: usize) -> Result<bool, ChanError>;
fn trigger_clear(&mut self, channel: &str) -> Result<usize, ChanError>;
fn triggers(&self, channel: &str) -> Vec<TriggerView>;