Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: ban command
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Aug 21, 2022
1 parent 25efe87 commit efaa619
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/commands/moderation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cmp;

use bson::{doc, Document};
use chrono::{Duration, Utc};
use mongodb::options::{UpdateModifications, UpdateOptions};
Expand Down Expand Up @@ -286,4 +288,47 @@ pub async fn purge(
})
.await?;
Ok(())
}
}

/// Ban a member.
#[poise::command(slash_command)]
pub async fn ban(
ctx: Context<'_>,
#[description = "User"] member: Member,
#[description = "Amount of days to delete messages"] dmd: Option<u8>,
#[description = "Reason for the ban"] reason: Option<String>,
) -> Result<(), Error> {
let reason = &reason
.or_else(|| Some("None specified".to_string()))
.unwrap();

let ban_result = member
.ban_with_reason(
&ctx.discord().http,
cmp::min(dmd.or_else(|| Some(0)).unwrap(), 7),
reason,
)
.await;

let embed_color = ctx.data().read().await.configuration.general.embed_color;

ctx.send(|f| {
f.embed(|e| {
if let Err(error) = ban_result {
e.title(format!("Failed to ban {}", member.user.tag()))
.field("Error", error, false)
} else {
e.title(format!("Banned {}", member.user.tag()))
.thumbnail(
member
.avatar_url()
.unwrap_or_else(|| member.user.default_avatar_url()),
)
.field("Reason", reason, false)
}
.color(embed_color)
})
})
.await?;
Ok(())
}

0 comments on commit efaa619

Please sign in to comment.