From 65708e7fbfe11b13d1e54279e0a4da6ae9804c11 Mon Sep 17 00:00:00 2001 From: Ole D Date: Wed, 7 Sep 2022 15:06:43 +0200 Subject: [PATCH 1/2] feat: add hackban command --- bot/src/commands.rs | 4 ++++ bot/src/commands/moderation.rs | 33 +++++++++++++++++++++++++++++++++ bot/src/main.rs | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 bot/src/commands/moderation.rs diff --git a/bot/src/commands.rs b/bot/src/commands.rs index 87808c8..8e70099 100644 --- a/bot/src/commands.rs +++ b/bot/src/commands.rs @@ -1,4 +1,8 @@ mod invite; +mod moderation; #[doc(inline)] pub use invite::invite; + +#[doc(inline)] +pub use moderation::hackban; \ No newline at end of file diff --git a/bot/src/commands/moderation.rs b/bot/src/commands/moderation.rs new file mode 100644 index 0000000..e829d18 --- /dev/null +++ b/bot/src/commands/moderation.rs @@ -0,0 +1,33 @@ +use poise::serenity_prelude::{UserId, Color}; + +use crate::{Context, Result}; + +/// Moderate stuff +#[command( + slash_command, + guild_only, + required_permissions = "BAN_MEMBERS", + required_bot_permissions = "BAN_MEMBERS" +)] +pub async fn hackban(ctx: Context<'_>, #[description = "The member you want to ban"] user: UserId, reason: Option) -> Result<()> { + if let Some(ref reason) = reason { + ctx.guild().unwrap().ban_with_reason(&ctx.discord().http, user, 0, reason).await?; + } else { + ctx.guild().unwrap().ban(&ctx.discord().http, user, 0).await?; + } + ctx.send(|b| { + b.ephemeral(true); + b.embed(|e| { + e.color(Color::DARK_GREEN); + e.title("Banned 🚫"); + if let Some(reason) = reason { + e.description(format!("User `{}` got banned for reason `{}`", user, reason)); + } else { + e.description(format!("User `{}` got banned", user)); + } + e + }); + b + }).await?; + Ok(()) +} \ No newline at end of file diff --git a/bot/src/main.rs b/bot/src/main.rs index 58a978b..7683fd3 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -85,7 +85,7 @@ async fn main() -> anyhow::Result<()> { ..Default::default() }, owners, - commands: vec![register::register(), commands::invite()], + commands: vec![register::register(), commands::invite(), commands::hackban()], ..Default::default() }, data: data.clone(), From 39cbb76db43d805a34dab5f6865f2ecaa51c1451 Mon Sep 17 00:00:00 2001 From: Ole D Date: Thu, 8 Sep 2022 11:44:10 +0200 Subject: [PATCH 2/2] refactor: run fmt --- bot/src/commands.rs | 3 +-- bot/src/commands/moderation.rs | 28 +++++++++++++++++++++------- bot/src/main.rs | 6 +++++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/bot/src/commands.rs b/bot/src/commands.rs index 8e70099..c16ad19 100644 --- a/bot/src/commands.rs +++ b/bot/src/commands.rs @@ -3,6 +3,5 @@ mod moderation; #[doc(inline)] pub use invite::invite; - #[doc(inline)] -pub use moderation::hackban; \ No newline at end of file +pub use moderation::hackban; diff --git a/bot/src/commands/moderation.rs b/bot/src/commands/moderation.rs index e829d18..9f9ce50 100644 --- a/bot/src/commands/moderation.rs +++ b/bot/src/commands/moderation.rs @@ -1,4 +1,4 @@ -use poise::serenity_prelude::{UserId, Color}; +use poise::serenity_prelude::{Color, UserId}; use crate::{Context, Result}; @@ -9,11 +9,21 @@ use crate::{Context, Result}; required_permissions = "BAN_MEMBERS", required_bot_permissions = "BAN_MEMBERS" )] -pub async fn hackban(ctx: Context<'_>, #[description = "The member you want to ban"] user: UserId, reason: Option) -> Result<()> { +pub async fn hackban( + ctx: Context<'_>, + #[description = "The member you want to ban"] user: UserId, + reason: Option, +) -> Result<()> { if let Some(ref reason) = reason { - ctx.guild().unwrap().ban_with_reason(&ctx.discord().http, user, 0, reason).await?; + ctx.guild() + .unwrap() + .ban_with_reason(&ctx.discord().http, user, 0, reason) + .await?; } else { - ctx.guild().unwrap().ban(&ctx.discord().http, user, 0).await?; + ctx.guild() + .unwrap() + .ban(&ctx.discord().http, user, 0) + .await?; } ctx.send(|b| { b.ephemeral(true); @@ -21,13 +31,17 @@ pub async fn hackban(ctx: Context<'_>, #[description = "The member you want to b e.color(Color::DARK_GREEN); e.title("Banned 🚫"); if let Some(reason) = reason { - e.description(format!("User `{}` got banned for reason `{}`", user, reason)); + e.description(format!( + "User `{}` got banned for reason `{}`", + user, reason + )); } else { e.description(format!("User `{}` got banned", user)); } e }); b - }).await?; + }) + .await?; Ok(()) -} \ No newline at end of file +} diff --git a/bot/src/main.rs b/bot/src/main.rs index 7683fd3..2c06113 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -85,7 +85,11 @@ async fn main() -> anyhow::Result<()> { ..Default::default() }, owners, - commands: vec![register::register(), commands::invite(), commands::hackban()], + commands: vec![ + register::register(), + commands::invite(), + commands::hackban(), + ], ..Default::default() }, data: data.clone(),