summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorseth <[email protected]>2023-12-02 19:14:51 -0500
committerseth <[email protected]>2023-12-15 16:41:13 -0500
commit0ca61ddff6ec7404f0aeabc1c8c785bbc8db7fd5 (patch)
tree2c3a7d73a96e9e02f110a19b24a7f9a6ad579c5a /src
parent36bb911f312a9baa5c152cc591060b2e4f8bc930 (diff)
feat: add basic moderation commands
Diffstat (limited to 'src')
-rw-r--r--src/colors.rs2
-rw-r--r--src/commands/mod.rs2
-rw-r--r--src/commands/moderation/actions.rs81
-rw-r--r--src/commands/moderation/mod.rs2
4 files changed, 87 insertions, 0 deletions
diff --git a/src/colors.rs b/src/colors.rs
index 5291933..2a3f402 100644
--- a/src/colors.rs
+++ b/src/colors.rs
@@ -3,6 +3,7 @@ use poise::serenity_prelude::Colour;
pub enum Colors {
Blue,
Orange,
+ Red,
}
impl From<Colors> for Colour {
@@ -10,6 +11,7 @@ impl From<Colors> for Colour {
match val {
Colors::Blue => Colour::from((136, 199, 253)),
Colors::Orange => Colour::from((255, 179, 74)),
+ Colors::Red => Colour::from((255, 94, 74)),
}
}
}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 8c265d3..5e6419c 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -15,6 +15,8 @@ pub fn to_global_commands() -> Vec<Command<Data, Report>> {
general::random(),
general::version(),
moderation::config(),
+ moderation::ban_user(),
+ moderation::kick_user(),
]
}
diff --git a/src/commands/moderation/actions.rs b/src/commands/moderation/actions.rs
new file mode 100644
index 0000000..1050656
--- /dev/null
+++ b/src/commands/moderation/actions.rs
@@ -0,0 +1,81 @@
+use crate::colors::Colors;
+use crate::Context;
+
+use color_eyre::eyre::{eyre, Result};
+use poise::serenity_prelude::{CreateEmbed, User};
+
+fn create_moderation_embed(
+ title: String,
+ user: &User,
+ delete_messages_days: Option<u8>,
+ reason: String,
+) -> impl FnOnce(&mut CreateEmbed) -> &mut CreateEmbed {
+ 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,
+ default_member_permissions = "BAN_MEMBERS"
+)]
+pub async fn ban_user(
+ ctx: Context<'_>,
+ user: User,
+ delete_messages_days: Option<u8>,
+ reason: Option<String>,
+) -> 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("n/a".to_string());
+
+ if reason != "n/a" {
+ guild.ban_with_reason(ctx, &user, days, &reason).await?;
+ } else {
+ guild.ban(ctx, &user, days).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,
+ default_member_permissions = "KICK_MEMBERS"
+)]
+pub async fn kick_user(ctx: Context<'_>, user: User, reason: Option<String>) -> Result<()> {
+ let guild = ctx
+ .guild()
+ .ok_or_else(|| eyre!("Couldn't get guild from message; Unable to ban!"))?;
+
+ let reason = reason.unwrap_or("n/a".to_string());
+
+ if reason != "n/a" {
+ guild.kick_with_reason(ctx, &user, &reason).await?;
+ } else {
+ guild.kick(ctx, &user).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/mod.rs b/src/commands/moderation/mod.rs
index d54b3f8..def251c 100644
--- a/src/commands/moderation/mod.rs
+++ b/src/commands/moderation/mod.rs
@@ -1,3 +1,5 @@
+mod actions;
mod config;
+pub use actions::*;
pub use config::config;