UP re-applies the op/voice status your channel access entitles you to; DOWN removes your status. Mirrors the OP/VOICE command's access check and mode emission, and requires you to actually be in the channel.
This commit is contained in:
parent
98ecbca414
commit
959d085e7a
3 changed files with 71 additions and 0 deletions
35
modules/chanserv/src/updown.rs
Normal file
35
modules/chanserv/src/updown.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
use echo_api::{NetView, Sender, ServiceCtx, Store};
|
||||
|
||||
// UP <#channel>: (re)apply the status mode your access entitles you to.
|
||||
// DOWN <#channel>: drop your channel status modes. `up` selects which.
|
||||
pub fn handle(me: &str, from: &Sender, up: bool, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &dyn Store) {
|
||||
let Some(&chan) = args.get(1) else {
|
||||
ctx.notice(me, from.uid, if up { "Syntax: UP <#channel>" } else { "Syntax: DOWN <#channel>" });
|
||||
return;
|
||||
};
|
||||
let Some(account) = from.account else {
|
||||
ctx.notice(me, from.uid, "You need to be logged in. Identify to NickServ first.");
|
||||
return;
|
||||
};
|
||||
let Some(info) = db.channel(chan) else {
|
||||
ctx.notice(me, from.uid, format!("\x02{chan}\x02 isn't registered."));
|
||||
return;
|
||||
};
|
||||
if !net.channel_members(chan).iter().any(|u| u.as_str() == from.uid) {
|
||||
ctx.notice(me, from.uid, format!("You're not in \x02{chan}\x02."));
|
||||
return;
|
||||
}
|
||||
if up {
|
||||
match info.join_mode(account) {
|
||||
Some(mode) => {
|
||||
ctx.channel_mode(me, chan, &format!("{mode} {}", from.uid));
|
||||
ctx.notice(me, from.uid, format!("Your status in \x02{chan}\x02 has been applied."));
|
||||
}
|
||||
None => ctx.notice(me, from.uid, format!("You have no status access in \x02{chan}\x02.")),
|
||||
}
|
||||
} else {
|
||||
// Strip op and voice; the ircd ignores any mode you don't currently hold.
|
||||
ctx.channel_mode(me, chan, &format!("-ov {} {}", from.uid, from.uid));
|
||||
ctx.notice(me, from.uid, format!("Your status in \x02{chan}\x02 has been removed."));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue