BotServ GREET + NickServ SET GREET
Members set a personal greet with NickServ SET GREET; a channel founder enables display with BotServ SET <#channel> GREET ON. On join, if greets are enabled and the member has channel access and a non-empty greet, the assigned bot shows [account] greet in the channel. Per-account greet is a typed field on Account (AccountGreetSet event, rides the account snapshot); the per-channel toggle is a new ChanSetting::BotGreet bool. Greet is public in NickServ INFO.
This commit is contained in:
parent
801bfc5c96
commit
ad8041bd9d
8 changed files with 172 additions and 5 deletions
|
|
@ -12,6 +12,8 @@ mod assign;
|
|||
mod info;
|
||||
#[path = "say.rs"]
|
||||
mod say;
|
||||
#[path = "set.rs"]
|
||||
mod set;
|
||||
|
||||
pub struct BotServ {
|
||||
pub uid: String,
|
||||
|
|
@ -37,7 +39,8 @@ impl Service for BotServ {
|
|||
Some("INFO") => info::handle(me, from, args, ctx, db),
|
||||
Some("SAY") => say::handle(me, from, args, ctx, net, db, false),
|
||||
Some("ACT") => say::handle(me, from, args, ctx, net, db, true),
|
||||
Some("HELP") | None => ctx.notice(me, from.uid, "BotServ keeps service bots for your channels: \x02ASSIGN\x02 <#channel> <bot> puts a bot in your channel, \x02UNASSIGN\x02 <#channel> removes it, \x02INFO\x02 <bot|#channel> shows details, \x02SAY\x02/\x02ACT\x02 <#channel> <text> speaks through the bot. Operators also have \x02BOT\x02 ADD|DEL|LIST."),
|
||||
Some("SET") => set::handle(me, from, args, ctx, db),
|
||||
Some("HELP") | None => ctx.notice(me, from.uid, "BotServ keeps service bots for your channels: \x02ASSIGN\x02 <#channel> <bot> puts a bot in your channel, \x02UNASSIGN\x02 <#channel> removes it, \x02INFO\x02 <bot|#channel> shows details, \x02SAY\x02/\x02ACT\x02 <#channel> <text> speaks through the bot, \x02SET\x02 <#channel> GREET <on|off> toggles greets. Operators also have \x02BOT\x02 ADD|DEL|LIST."),
|
||||
Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
34
botserv/src/set.rs
Normal file
34
botserv/src/set.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use fedserv_api::{ChanSetting, Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// SET <#channel> <option> <on|off>: per-channel bot options. Founder-or-admin.
|
||||
// Currently: GREET (show members' personal greets when they join).
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let (Some(&chan), Some(option)) = (args.get(1), args.get(2)) else {
|
||||
ctx.notice(me, from.uid, "Syntax: SET <#channel> GREET <ON|OFF>");
|
||||
return;
|
||||
};
|
||||
let Some(founder) = db.channel(chan).map(|c| c.founder) else {
|
||||
ctx.notice(me, from.uid, format!("\x02{chan}\x02 isn't registered."));
|
||||
return;
|
||||
};
|
||||
if from.account != Some(founder.as_str()) && !from.privs.has(Priv::Admin) {
|
||||
ctx.notice(me, from.uid, format!("Only \x02{chan}\x02's founder can change its bot options."));
|
||||
return;
|
||||
}
|
||||
let on = match args.get(3).map(|s| s.to_ascii_uppercase()).as_deref() {
|
||||
Some("ON") | Some("TRUE") => true,
|
||||
Some("OFF") | Some("FALSE") => false,
|
||||
_ => {
|
||||
ctx.notice(me, from.uid, "Syntax: SET <#channel> GREET <ON|OFF>");
|
||||
return;
|
||||
}
|
||||
};
|
||||
match option.to_ascii_uppercase().as_str() {
|
||||
"GREET" => match db.set_channel_setting(chan, ChanSetting::BotGreet, on) {
|
||||
Ok(()) if on => ctx.notice(me, from.uid, format!("Greet messages are now \x02on\x02 in \x02{chan}\x02.")),
|
||||
Ok(()) => ctx.notice(me, from.uid, format!("Greet messages are now \x02off\x02 in \x02{chan}\x02.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
},
|
||||
other => ctx.notice(me, from.uid, format!("Unknown option \x02{other}\x02. Available: \x02GREET\x02.")),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue