diff options
| -rw-r--r-- | src/commands/moderation/config.rs | 49 | ||||
| -rw-r--r-- | src/handlers/event/pinboard.rs | 5 | ||||
| -rw-r--r-- | src/handlers/event/reactboard.rs | 9 | ||||
| -rw-r--r-- | src/storage/settings.rs | 4 |
4 files changed, 50 insertions, 17 deletions
diff --git a/src/commands/moderation/config.rs b/src/commands/moderation/config.rs index 4a1fb47..a8af8a0 100644 --- a/src/commands/moderation/config.rs +++ b/src/commands/moderation/config.rs @@ -1,7 +1,8 @@ use std::str::FromStr; use crate::{storage, Context}; -use storage::SettingsProperties; +use settings::{Settings, SettingsProperties}; +use storage::settings; use color_eyre::eyre::{eyre, Result}; use log::*; @@ -14,6 +15,24 @@ where list.split(',').filter_map(|s| s.parse().ok()).collect() } +fn prop_to_val(setting: &SettingsProperties, settings: &Settings) -> String { + match setting { + SettingsProperties::GuildId => settings.guild_id.to_string(), + SettingsProperties::PinBoardChannel => format!("{:#?}", settings.pinboard_channel), + SettingsProperties::PinBoardWatch => format!("{:#?}", settings.pinboard_watch), + SettingsProperties::PinBoardEnabled => settings.pinboard_enabled.to_string(), + SettingsProperties::ReactBoardChannel => format!("{:#?}", settings.reactboard_channel), + SettingsProperties::ReactBoardRequirement => { + format!("{:?}", settings.reactboard_requirement) + } + SettingsProperties::ReactBoardReactions => format!("{:?}", settings.reactboard_reactions), + SettingsProperties::ReactBoardEnabled => settings.reactboard_enabled.to_string(), + SettingsProperties::OptionalCommandsEnabled => { + settings.optional_commands_enabled.to_string() + } + } +} + #[poise::command( slash_command, subcommands("set", "get"), @@ -23,6 +42,7 @@ pub async fn config(_ctx: Context<'_>) -> Result<()> { Ok(()) } +#[allow(clippy::too_many_arguments)] #[poise::command(slash_command, ephemeral, guild_only)] pub async fn set( ctx: Context<'_>, @@ -31,6 +51,7 @@ pub async fn set( pinboard_channel: Option<GuildChannel>, #[description = "Comma separated list of channels PinBoard redirects. If empty, this will be all channels"] pinboard_watch: Option<String>, + #[description = "Toggle PinBoard"] pinboard_enabled: Option<bool>, #[channel_types("Text")] #[description = "Where to post messages that made it to the ReactBoard. If left empty, ReactBoard is disabled."] reactboard_channel: Option<GuildChannel>, @@ -38,6 +59,7 @@ pub async fn set( reactboard_reaction: Option<String>, #[description = "Minimum number of reactions a message needs to make it to the ReactBoard (defaults to 5)"] reactboard_requirement: Option<u64>, + #[description = "Toggle ReactBoard"] reactboard_enabled: Option<bool>, #[description = "Enables 'extra' commands like teawiespam and copypasta. Defaults to false."] optional_commands_enabled: Option<bool>, ) -> Result<()> { @@ -58,6 +80,11 @@ pub async fn set( settings.pinboard_watch = Some(channels); } + if let Some(enabled) = pinboard_enabled { + debug!("Setting pinboard_enabled to {enabled} for {gid}"); + settings.pinboard_enabled = enabled; + } + if let Some(channel) = reactboard_channel { debug!("Setting reactboard_channel to {channel} for {gid}"); settings.reactboard_channel = Some(channel.id); @@ -76,6 +103,11 @@ pub async fn set( settings.reactboard_reactions = Some(emojis); } + if let Some(enabled) = reactboard_enabled { + debug!("Setting reactboard_enabled to {enabled} for {gid}"); + settings.reactboard_enabled = enabled; + } + if let Some(enabled) = optional_commands_enabled { debug!("Setting optional_commands_enabled to {enabled} for {}", gid); settings.optional_commands_enabled = enabled; @@ -104,20 +136,7 @@ pub async fn get( .ok_or_else(|| eyre!("Failed to get GuildId from context!"))?; let settings = ctx.data().storage.get_guild_settings(gid).await?; - - let value = match setting { - SettingsProperties::GuildId => settings.guild_id.to_string(), - SettingsProperties::PinBoardChannel => format!("{:#?}", settings.pinboard_channel), - SettingsProperties::PinBoardWatch => format!("{:#?}", settings.pinboard_watch), - SettingsProperties::ReactBoardChannel => format!("{:#?}", settings.reactboard_channel), - SettingsProperties::ReactBoardRequirement => { - format!("{:?}", settings.reactboard_requirement) - } - SettingsProperties::ReactBoardReactions => format!("{:?}", settings.reactboard_reactions), - SettingsProperties::OptionalCommandsEnabled => { - settings.optional_commands_enabled.to_string() - } - }; + let value = prop_to_val(&setting, &settings); ctx.send(|m| m.embed(|e| e.field(setting, value, false))) .await?; diff --git a/src/handlers/event/pinboard.rs b/src/handlers/event/pinboard.rs index d95cfee..7a13b88 100644 --- a/src/handlers/event/pinboard.rs +++ b/src/handlers/event/pinboard.rs @@ -9,6 +9,11 @@ pub async fn handle(ctx: &Context, pin: &ChannelPinsUpdateEvent, data: &Data) -> let gid = pin.guild_id.unwrap_or_default(); let settings = data.storage.get_guild_settings(&gid).await?; + if !settings.pinboard_enabled { + debug!("PinBoard is disabled in {gid}, ignoring"); + return Ok(()); + } + let target = if let Some(target) = settings.pinboard_channel { target } else { diff --git a/src/handlers/event/reactboard.rs b/src/handlers/event/reactboard.rs index d23a762..fa546c0 100644 --- a/src/handlers/event/reactboard.rs +++ b/src/handlers/event/reactboard.rs @@ -47,10 +47,15 @@ async fn send_to_reactboard( let settings = storage.get_guild_settings(guild_id).await?; // make sure everything is in order... + if !settings.reactboard_enabled { + debug!("ReactBoard is disabled in {guild_id}, ignoring"); + return Ok(()); + } + let target = if let Some(target) = settings.reactboard_channel { target } else { - debug!("Reactboard is disabled in {guild_id}, ignoring"); + debug!("ReactBoard is disabled in {guild_id}, ignoring"); return Ok(()); }; @@ -61,7 +66,7 @@ async fn send_to_reactboard( if reaction.count < settings.reactboard_requirement.unwrap_or(5) { debug!( - "Ignoring message {} on reactboard, not enough reactions", + "Ignoring message {} on ReactBoard, not enough reactions", msg.id ); return Ok(()); diff --git a/src/storage/settings.rs b/src/storage/settings.rs index c8a663d..d60327f 100644 --- a/src/storage/settings.rs +++ b/src/storage/settings.rs @@ -9,9 +9,11 @@ pub enum SettingsProperties { GuildId, PinBoardChannel, PinBoardWatch, + PinBoardEnabled, ReactBoardChannel, ReactBoardRequirement, ReactBoardReactions, + ReactBoardEnabled, OptionalCommandsEnabled, } @@ -20,9 +22,11 @@ pub struct Settings { pub guild_id: GuildId, pub pinboard_channel: Option<ChannelId>, pub pinboard_watch: Option<Vec<ChannelId>>, + pub pinboard_enabled: bool, pub reactboard_channel: Option<ChannelId>, pub reactboard_requirement: Option<u64>, pub reactboard_reactions: Option<Vec<ReactionType>>, + pub reactboard_enabled: bool, pub optional_commands_enabled: bool, } |
