BotServ: DONTKICKVOICES, plus neutral code comments
KICK <#channel> DONTKICKVOICES <on|off> exempts voiced users from the kickers. The network view now tracks +v the same way it tracks +o: a new ChannelVoice event is parsed from FMODE +v/-v and from +v join prefixes, and set_voice/is_voiced mirror set_op/is_op (voice is cleared on part and quit). scan_ops generalised to scan_status for any status letter. Also scrubbed third-party project name-drops from code comments.
This commit is contained in:
parent
929a4cdd92
commit
5d1bfb3144
9 changed files with 99 additions and 23 deletions
|
|
@ -30,6 +30,7 @@ pub struct User {
|
|||
pub struct Channel {
|
||||
pub members: HashSet<String>, // uids
|
||||
pub ops: HashSet<String>, // uids holding channel-operator status
|
||||
pub voices: HashSet<String>, // uids holding +v
|
||||
pub key: Option<String>,
|
||||
}
|
||||
|
||||
|
|
@ -96,6 +97,7 @@ impl Network {
|
|||
for c in self.channels.values_mut() {
|
||||
c.members.remove(uid);
|
||||
c.ops.remove(uid);
|
||||
c.voices.remove(uid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -143,6 +145,7 @@ impl Network {
|
|||
if let Some(c) = self.channels.get_mut(&lc(channel)) {
|
||||
c.members.remove(uid);
|
||||
c.ops.remove(uid);
|
||||
c.voices.remove(uid);
|
||||
}
|
||||
if let Some(nick) = self.nick_of(uid) {
|
||||
self.seen.insert(lc(nick), Seen { nick: nick.to_string(), ts: now(), what: format!("leaving {channel}") });
|
||||
|
|
@ -164,6 +167,21 @@ impl Network {
|
|||
self.channels.get(&lc(channel)).is_some_and(|c| c.ops.contains(uid))
|
||||
}
|
||||
|
||||
// Set or clear a user's voice status (+v).
|
||||
pub fn set_voice(&mut self, channel: &str, uid: &str, voice: bool) {
|
||||
let c = self.channels.entry(lc(channel)).or_default();
|
||||
if voice {
|
||||
c.voices.insert(uid.to_string());
|
||||
} else {
|
||||
c.voices.remove(uid);
|
||||
}
|
||||
}
|
||||
|
||||
// Whether `uid` currently holds voice in `channel`.
|
||||
pub fn is_voiced(&self, channel: &str, uid: &str) -> bool {
|
||||
self.channels.get(&lc(channel)).is_some_and(|c| c.voices.contains(uid))
|
||||
}
|
||||
|
||||
// Uids currently in `channel`.
|
||||
pub fn channel_members(&self, channel: &str) -> impl Iterator<Item = &str> {
|
||||
self.channels.get(&lc(channel)).into_iter().flat_map(|c| c.members.iter().map(String::as_str))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue