From e38a441e37ec1a1dff07cf8bcff3e36a411709aa Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 15 Dec 2023 01:14:15 -0500 Subject: remove moderation commands this was mainly an experiment; i don't think we need them --- src/commands/general/config.rs | 160 +++++++++++++++++++++++++++++++++++++ src/commands/general/mod.rs | 21 +++-- src/commands/mod.rs | 14 +--- src/commands/moderation/actions.rs | 84 ------------------- src/commands/moderation/config.rs | 160 ------------------------------------- src/commands/moderation/mod.rs | 5 -- src/commands/optional/mod.rs | 10 ++- 7 files changed, 186 insertions(+), 268 deletions(-) create mode 100644 src/commands/general/config.rs delete mode 100644 src/commands/moderation/actions.rs delete mode 100644 src/commands/moderation/config.rs delete mode 100644 src/commands/moderation/mod.rs (limited to 'src/commands') diff --git a/src/commands/general/config.rs b/src/commands/general/config.rs new file mode 100644 index 0000000..64cdb83 --- /dev/null +++ b/src/commands/general/config.rs @@ -0,0 +1,160 @@ +use std::str::FromStr; + +use crate::{storage, Context}; +use storage::{Settings, SettingsProperties}; + +use color_eyre::eyre::{eyre, Result}; +use log::*; +use poise::serenity_prelude::{GuildChannel, ReactionType}; + +fn split_argument(list: String) -> Vec +where + T: FromStr, +{ + list.split(',') + .filter_map(|s| s.trim().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, + prefix_command, + subcommands("set", "get"), + required_permissions = "MANAGE_GUILD", + default_member_permissions = "MANAGE_GUILD" +)] +pub async fn config(_ctx: Context<'_>) -> Result<()> { + Ok(()) +} + +#[allow(clippy::too_many_arguments)] +#[poise::command( + slash_command, + prefix_command, + ephemeral, + guild_only, + required_permissions = "MANAGE_GUILD" +)] +pub async fn set( + ctx: Context<'_>, + #[channel_types("Text")] + #[description = "Where to redirect pins from channels. If empty (the default), the PinBoard is disabled."] + pinboard_channel: Option, + #[description = "Comma separated list of channels PinBoard redirects. If empty, this will be all channels"] + pinboard_watch: Option, + #[description = "Toggle PinBoard"] pinboard_enabled: Option, + #[channel_types("Text")] + #[description = "Where to post messages that made it to the ReactBoard. If left empty, ReactBoard is disabled."] + reactboard_channel: Option, + #[description = "Comma separated list of emojis that will count towards ReactBoard. If empty, ReactBoard is disabled."] + reactboard_reaction: Option, + #[description = "Minimum number of reactions a message needs to make it to the ReactBoard (defaults to 5)"] + reactboard_requirement: Option, + #[description = "Toggle ReactBoard"] reactboard_enabled: Option, + #[description = "Enables 'extra' commands like teawiespam and copypasta. Defaults to false."] + optional_commands_enabled: Option, +) -> Result<()> { + let storage = &ctx.data().storage; + let gid = ctx.guild_id().unwrap_or_default(); + let mut settings = storage.get_guild_settings(&gid).await?; + let previous_settings = settings.clone(); + + if let Some(channel) = pinboard_channel { + debug!("Setting pinboard_channel to {channel} for {gid}"); + settings.pinboard_channel = Some(channel.id); + } + + if let Some(watch) = pinboard_watch { + let channels = split_argument(watch); + debug!("Setting pinboard_watch to {channels:#?} for {gid}"); + + 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); + } + + if let Some(requirement) = reactboard_requirement { + debug!("Setting reactboard_requirement to {requirement} for {gid}"); + settings.reactboard_requirement = Some(requirement); + } + + if let Some(reaction) = reactboard_reaction { + let emojis: Vec = + reaction.split(',').filter_map(|r| r.parse().ok()).collect(); + debug!("Setting reactboard_reactions to {emojis:#?} for {gid}"); + + 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; + } + + if previous_settings != settings { + debug!("Updating settings key for {gid}"); + storage.create_guild_settings(settings).await?; + ctx.reply("Configuration updated!").await?; + } else { + debug!("Not updating settings key for {gid} since no changes were made"); + ctx.reply("No changes made, so i'm not updating anything") + .await?; + } + + Ok(()) +} + +#[poise::command( + slash_command, + prefix_command, + ephemeral, + guild_only, + required_permissions = "MANAGE_GUILD" +)] +pub async fn get( + ctx: Context<'_>, + #[description = "The setting you want to get"] setting: SettingsProperties, +) -> Result<()> { + let gid = &ctx + .guild_id() + .ok_or_else(|| eyre!("Failed to get GuildId from context!"))?; + + let settings = ctx.data().storage.get_guild_settings(gid).await?; + let value = prop_to_val(&setting, &settings); + + ctx.send(|m| m.embed(|e| e.field(setting, value, false))) + .await?; + + Ok(()) +} diff --git a/src/commands/general/mod.rs b/src/commands/general/mod.rs index ffb4d63..1031d5b 100644 --- a/src/commands/general/mod.rs +++ b/src/commands/general/mod.rs @@ -1,11 +1,22 @@ +use crate::Data; + +use color_eyre::eyre::Report; +use poise::Command; + mod ask; mod bing; +mod config; mod convert; mod random; mod version; -pub use ask::ask; -pub use bing::bing; -pub use convert::convert; -pub use random::random; -pub use version::version; +pub fn to_comands() -> Vec> { + vec![ + ask::ask(), + bing::bing(), + config::config(), + convert::convert(), + random::random(), + version::version(), + ] +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 833df38..df2d857 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -4,22 +4,12 @@ use color_eyre::eyre::Report; use poise::Command; mod general; -mod moderation; mod optional; pub fn to_global_commands() -> Vec> { - vec![ - general::ask(), - general::bing(), - general::convert(), - general::random(), - general::version(), - moderation::config(), - moderation::ban_user(), - moderation::kick_user(), - ] + general::to_comands() } pub fn to_optional_commands() -> Vec> { - vec![optional::copypasta(), optional::teawiespam()] + optional::to_commands() } diff --git a/src/commands/moderation/actions.rs b/src/commands/moderation/actions.rs deleted file mode 100644 index f7ba7b7..0000000 --- a/src/commands/moderation/actions.rs +++ /dev/null @@ -1,84 +0,0 @@ -use crate::colors::Colors; -use crate::Context; - -use color_eyre::eyre::{eyre, Result}; -use log::*; -use poise::serenity_prelude::{CreateEmbed, User}; - -fn create_moderation_embed( - title: String, - user: &User, - delete_messages_days: Option, - reason: String, -) -> impl FnOnce(&mut CreateEmbed) -> &mut CreateEmbed { - let reason = if reason.is_empty() { - "n/a".to_string() - } else { - reason - }; - - let fields = [ - ("User", format!("{} ({})", user.name, user.id), false), - ("Reason", reason, false), - ( - "Deleted messages", - format!("Last {} days", delete_messages_days.unwrap_or(0)), - false, - ), - ]; - - |e: &mut CreateEmbed| e.title(title).fields(fields).color(Colors::Red) -} - -/// ban a user -#[poise::command( - slash_command, - prefix_command, - required_permissions = "BAN_MEMBERS", - default_member_permissions = "BAN_MEMBERS" -)] -pub async fn ban_user( - ctx: Context<'_>, - user: User, - delete_messages_days: Option, - reason: Option, -) -> Result<()> { - let days = delete_messages_days.unwrap_or(1); - let guild = ctx - .guild() - .ok_or_else(|| eyre!("Couldn't get guild from message; Unable to ban!"))?; - - let reason = reason.unwrap_or_default(); - - debug!("Banning user {} with reason {reason}", user.id); - guild.ban_with_reason(ctx, &user, days, &reason).await?; - - let embed = create_moderation_embed("User banned!".to_string(), &user, Some(days), reason); - - ctx.send(|m| m.embed(embed)).await?; - - Ok(()) -} - -/// kick a user -#[poise::command( - slash_command, - prefix_command, - required_permissions = "KICK_MEMBERS", - default_member_permissions = "KICK_MEMBERS" -)] -pub async fn kick_user(ctx: Context<'_>, user: User, reason: Option) -> Result<()> { - let guild = ctx - .guild() - .ok_or_else(|| eyre!("Couldn't get guild from message; Unable to ban!"))?; - - let reason = reason.unwrap_or_default(); - - debug!("Kicking user {} for reason {reason}", user.id); - guild.kick_with_reason(ctx, &user, &reason).await?; - - let embed = create_moderation_embed("User kicked!".to_string(), &user, None, reason); - ctx.send(|m| m.embed(embed)).await?; - - Ok(()) -} diff --git a/src/commands/moderation/config.rs b/src/commands/moderation/config.rs deleted file mode 100644 index 64cdb83..0000000 --- a/src/commands/moderation/config.rs +++ /dev/null @@ -1,160 +0,0 @@ -use std::str::FromStr; - -use crate::{storage, Context}; -use storage::{Settings, SettingsProperties}; - -use color_eyre::eyre::{eyre, Result}; -use log::*; -use poise::serenity_prelude::{GuildChannel, ReactionType}; - -fn split_argument(list: String) -> Vec -where - T: FromStr, -{ - list.split(',') - .filter_map(|s| s.trim().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, - prefix_command, - subcommands("set", "get"), - required_permissions = "MANAGE_GUILD", - default_member_permissions = "MANAGE_GUILD" -)] -pub async fn config(_ctx: Context<'_>) -> Result<()> { - Ok(()) -} - -#[allow(clippy::too_many_arguments)] -#[poise::command( - slash_command, - prefix_command, - ephemeral, - guild_only, - required_permissions = "MANAGE_GUILD" -)] -pub async fn set( - ctx: Context<'_>, - #[channel_types("Text")] - #[description = "Where to redirect pins from channels. If empty (the default), the PinBoard is disabled."] - pinboard_channel: Option, - #[description = "Comma separated list of channels PinBoard redirects. If empty, this will be all channels"] - pinboard_watch: Option, - #[description = "Toggle PinBoard"] pinboard_enabled: Option, - #[channel_types("Text")] - #[description = "Where to post messages that made it to the ReactBoard. If left empty, ReactBoard is disabled."] - reactboard_channel: Option, - #[description = "Comma separated list of emojis that will count towards ReactBoard. If empty, ReactBoard is disabled."] - reactboard_reaction: Option, - #[description = "Minimum number of reactions a message needs to make it to the ReactBoard (defaults to 5)"] - reactboard_requirement: Option, - #[description = "Toggle ReactBoard"] reactboard_enabled: Option, - #[description = "Enables 'extra' commands like teawiespam and copypasta. Defaults to false."] - optional_commands_enabled: Option, -) -> Result<()> { - let storage = &ctx.data().storage; - let gid = ctx.guild_id().unwrap_or_default(); - let mut settings = storage.get_guild_settings(&gid).await?; - let previous_settings = settings.clone(); - - if let Some(channel) = pinboard_channel { - debug!("Setting pinboard_channel to {channel} for {gid}"); - settings.pinboard_channel = Some(channel.id); - } - - if let Some(watch) = pinboard_watch { - let channels = split_argument(watch); - debug!("Setting pinboard_watch to {channels:#?} for {gid}"); - - 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); - } - - if let Some(requirement) = reactboard_requirement { - debug!("Setting reactboard_requirement to {requirement} for {gid}"); - settings.reactboard_requirement = Some(requirement); - } - - if let Some(reaction) = reactboard_reaction { - let emojis: Vec = - reaction.split(',').filter_map(|r| r.parse().ok()).collect(); - debug!("Setting reactboard_reactions to {emojis:#?} for {gid}"); - - 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; - } - - if previous_settings != settings { - debug!("Updating settings key for {gid}"); - storage.create_guild_settings(settings).await?; - ctx.reply("Configuration updated!").await?; - } else { - debug!("Not updating settings key for {gid} since no changes were made"); - ctx.reply("No changes made, so i'm not updating anything") - .await?; - } - - Ok(()) -} - -#[poise::command( - slash_command, - prefix_command, - ephemeral, - guild_only, - required_permissions = "MANAGE_GUILD" -)] -pub async fn get( - ctx: Context<'_>, - #[description = "The setting you want to get"] setting: SettingsProperties, -) -> Result<()> { - let gid = &ctx - .guild_id() - .ok_or_else(|| eyre!("Failed to get GuildId from context!"))?; - - let settings = ctx.data().storage.get_guild_settings(gid).await?; - let value = prop_to_val(&setting, &settings); - - ctx.send(|m| m.embed(|e| e.field(setting, value, false))) - .await?; - - Ok(()) -} diff --git a/src/commands/moderation/mod.rs b/src/commands/moderation/mod.rs deleted file mode 100644 index def251c..0000000 --- a/src/commands/moderation/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod actions; -mod config; - -pub use actions::*; -pub use config::config; diff --git a/src/commands/optional/mod.rs b/src/commands/optional/mod.rs index 451deeb..2be1fef 100644 --- a/src/commands/optional/mod.rs +++ b/src/commands/optional/mod.rs @@ -1,5 +1,11 @@ +use crate::Data; + +use color_eyre::eyre::Report; +use poise::Command; + mod copypasta; mod teawiespam; -pub use copypasta::copypasta; -pub use teawiespam::teawiespam; +pub fn to_commands() -> Vec> { + vec![copypasta::copypasta(), teawiespam::teawiespam()] +} -- cgit v1.2.3