ChanServ: add SET EMAIL channel contact address
Founders can attach a contact email to a channel, shown in INFO and cleared when set empty. Mirrors SET URL exactly; Local-scope channel metadata. Completes the channel DESC/URL/EMAIL trio.
This commit is contained in:
parent
7eb1adce5e
commit
01ea0fa95e
10 changed files with 52 additions and 5 deletions
|
|
@ -11,7 +11,7 @@ impl Db {
|
|||
self.log
|
||||
.append(Event::ChannelRegistered { name: name.to_string(), founder: founder.to_string(), ts })
|
||||
.map_err(|_| ChanError::Internal)?;
|
||||
self.channels.insert(k, ChannelInfo { name: name.to_string(), founder: founder.to_string(), ts, lock_on: String::new(), lock_off: String::new(), access: Vec::new(), akick: Vec::new(), successor: None, desc: String::new(), entrymsg: String::new(), url: String::new(), settings: ChanSettings::default(), topic: String::new(), suspension: None, assigned_bot: None , kickers: KickerSettings::default() , badwords: Vec::new(), badwords_rev: 0 , triggers: Vec::new(), triggers_rev: 0, last_used: ts, noexpire: false, expiry_warned: false, oper_note: None });
|
||||
self.channels.insert(k, ChannelInfo { name: name.to_string(), founder: founder.to_string(), ts, lock_on: String::new(), lock_off: String::new(), access: Vec::new(), akick: Vec::new(), successor: None, desc: String::new(), entrymsg: String::new(), url: String::new(), email: String::new(), settings: ChanSettings::default(), topic: String::new(), suspension: None, assigned_bot: None , kickers: KickerSettings::default() , badwords: Vec::new(), badwords_rev: 0 , triggers: Vec::new(), triggers_rev: 0, last_used: ts, noexpire: false, expiry_warned: false, oper_note: None });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -199,6 +199,18 @@ impl Db {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_channel_email(&mut self, channel: &str, email: &str) -> Result<(), ChanError> {
|
||||
let k = key(channel);
|
||||
if !self.channels.contains_key(&k) {
|
||||
return Err(ChanError::NoChannel);
|
||||
}
|
||||
self.log
|
||||
.append(Event::ChannelEmailSet { channel: channel.to_string(), email: email.to_string() })
|
||||
.map_err(|_| ChanError::Internal)?;
|
||||
self.channels.get_mut(&k).unwrap().email = email.to_string();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Turn one ChanServ SET option on or off for a channel.
|
||||
pub fn set_channel_setting(&mut self, channel: &str, setting: ChanSetting, on: bool) -> Result<(), ChanError> {
|
||||
let k = key(channel);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ pub enum Event {
|
|||
ChannelDescSet { channel: String, desc: String },
|
||||
ChannelEntryMsgSet { channel: String, msg: String },
|
||||
ChannelUrlSet { channel: String, url: String },
|
||||
ChannelEmailSet { channel: String, email: String },
|
||||
ChannelSettingsSet { channel: String, settings: ChanSettings },
|
||||
ChannelKickerSet { channel: String, kickers: KickerSettings },
|
||||
ChannelBadwordsSet { channel: String, badwords: Vec<String> },
|
||||
|
|
@ -210,6 +211,7 @@ impl Event {
|
|||
| Event::ChannelDescSet { .. }
|
||||
| Event::ChannelEntryMsgSet { .. }
|
||||
| Event::ChannelUrlSet { .. }
|
||||
| Event::ChannelEmailSet { .. }
|
||||
| Event::ChannelSettingsSet { .. }
|
||||
| Event::ChannelKickerSet { .. }
|
||||
| Event::ChannelBadwordsSet { .. }
|
||||
|
|
@ -395,7 +397,7 @@ pub(crate) fn apply(accounts: &mut HashMap<String, Account>, channels: &mut Hash
|
|||
grouped.remove(&key(&nick));
|
||||
}
|
||||
Event::ChannelRegistered { name, founder, ts } => {
|
||||
channels.insert(key(&name), ChannelInfo { name, founder, ts, lock_on: String::new(), lock_off: String::new(), access: Vec::new(), akick: Vec::new(), successor: None, desc: String::new(), entrymsg: String::new(), url: String::new(), settings: ChanSettings::default(), topic: String::new(), suspension: None, assigned_bot: None , kickers: KickerSettings::default() , badwords: Vec::new(), badwords_rev: 0 , triggers: Vec::new(), triggers_rev: 0, last_used: ts, noexpire: false, expiry_warned: false, oper_note: None });
|
||||
channels.insert(key(&name), ChannelInfo { name, founder, ts, lock_on: String::new(), lock_off: String::new(), access: Vec::new(), akick: Vec::new(), successor: None, desc: String::new(), entrymsg: String::new(), url: String::new(), email: String::new(), settings: ChanSettings::default(), topic: String::new(), suspension: None, assigned_bot: None , kickers: KickerSettings::default() , badwords: Vec::new(), badwords_rev: 0 , triggers: Vec::new(), triggers_rev: 0, last_used: ts, noexpire: false, expiry_warned: false, oper_note: None });
|
||||
}
|
||||
Event::ChannelDropped { name } => {
|
||||
channels.remove(&key(&name));
|
||||
|
|
@ -448,6 +450,11 @@ pub(crate) fn apply(accounts: &mut HashMap<String, Account>, channels: &mut Hash
|
|||
c.url = url;
|
||||
}
|
||||
}
|
||||
Event::ChannelEmailSet { channel, email } => {
|
||||
if let Some(c) = channels.get_mut(&key(&channel)) {
|
||||
c.email = email;
|
||||
}
|
||||
}
|
||||
Event::ChannelSettingsSet { channel, settings } => {
|
||||
if let Some(c) = channels.get_mut(&key(&channel)) {
|
||||
c.settings = settings;
|
||||
|
|
|
|||
|
|
@ -422,6 +422,9 @@ pub struct ChannelInfo {
|
|||
// Channel homepage URL, shown in INFO (empty = none).
|
||||
#[serde(default)]
|
||||
pub url: String,
|
||||
// Channel contact email, shown in INFO (empty = none).
|
||||
#[serde(default)]
|
||||
pub email: String,
|
||||
// On/off options set via ChanServ SET.
|
||||
#[serde(default)]
|
||||
pub settings: ChanSettings,
|
||||
|
|
|
|||
|
|
@ -377,6 +377,9 @@ impl Store for Db {
|
|||
fn set_url(&mut self, channel: &str, url: &str) -> Result<(), ChanError> {
|
||||
Db::set_url(self, channel, url)
|
||||
}
|
||||
fn set_channel_email(&mut self, channel: &str, email: &str) -> Result<(), ChanError> {
|
||||
Db::set_channel_email(self, channel, email)
|
||||
}
|
||||
fn set_channel_setting(&mut self, channel: &str, setting: ChanSetting, on: bool) -> Result<(), ChanError> {
|
||||
Db::set_channel_setting(self, channel, setting, on)
|
||||
}
|
||||
|
|
@ -559,6 +562,7 @@ fn channel_view(c: &ChannelInfo) -> ChannelView {
|
|||
desc: c.desc.clone(),
|
||||
entrymsg: c.entrymsg.clone(),
|
||||
url: c.url.clone(),
|
||||
email: c.email.clone(),
|
||||
signkick: c.settings.signkick,
|
||||
private: c.settings.private,
|
||||
peace: c.settings.peace,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue