Skip to content

Commit ac1112b

Browse files
committed
Add support ban/pardon
1 parent 04faac4 commit ac1112b

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

src/commands/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ pub fn all() -> Vec<Command> {
4343
general!(stars),
4444
general!(tag),
4545
moderation!(set_welcome),
46+
moderation!(support_ban, support_ban),
47+
moderation!(support_ban, support_unban),
4648
]
4749
}

src/commands/moderation/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod set_welcome;
2+
pub mod support_ban;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#![allow(clippy::unreadable_literal)]
2+
3+
4+
use poise::serenity_prelude::{Member, Permissions, RoleId};
5+
6+
use crate::{Context, Error};
7+
8+
const ROLE_ID: RoleId = RoleId::new(1391767823122042910);
9+
const HELPER_ID: RoleId = RoleId::new(1391769732968878133);
10+
11+
#[poise::command(slash_command, prefix_command, check = "require_helper", ephemeral, guild_only)]
12+
pub async fn support_ban(ctx: Context<'_>, member: Member) -> Result<(), Error> {
13+
if member.roles.contains(&ROLE_ID) {
14+
ctx.say(format!("❌ `{}` is already banned from support.", member.user.tag())).await?;
15+
16+
return Ok(())
17+
}
18+
19+
member.add_role(ctx.http(), ROLE_ID).await?;
20+
ctx.say(format!("✅ Banned `{}` from support!", &member.user.tag()))
21+
.await?;
22+
23+
Ok(())
24+
}
25+
26+
#[poise::command(slash_command, prefix_command, check = "require_helper", ephemeral, guild_only)]
27+
pub async fn support_unban(ctx: Context<'_>, member: Member) -> Result<(), Error> {
28+
if !member.roles.contains(&ROLE_ID) {
29+
ctx.say(format!("❌ `{}` is not banned from support.", member.user.tag())).await?;
30+
31+
return Ok(())
32+
}
33+
34+
member.remove_role(ctx.http(), ROLE_ID).await?;
35+
ctx.say(format!(
36+
"✅ Unbanned `{}` from support!",
37+
&member.user.tag()
38+
))
39+
.await?;
40+
41+
Ok(())
42+
}
43+
44+
async fn require_helper(ctx: Context<'_>) -> Result<bool, Error> {
45+
let Some(member) = ctx.author_member().await else {
46+
return Ok(false);
47+
};
48+
49+
let is_helper = member.roles.contains(&HELPER_ID);
50+
let is_moderator = member.permissions.unwrap_or_default() & Permissions::MANAGE_ROLES;
51+
52+
return Ok(is_helper || is_moderator)
53+
}

src/handlers/error.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ pub async fn handle(error: FrameworkError<'_, Data, Error>) {
8989
}
9090
}
9191

92+
FrameworkError::CommandCheckFailed { error, ctx, .. } => {
93+
if let Some(error) = error {
94+
// just log - it's probably best if people don't find out when they're breaking the perm checking
95+
log::error!(
96+
"Error checking permissions for {}:\n{error:?}",
97+
ctx.command().name
98+
);
99+
} else if let poise::Context::Application(ctx) = ctx {
100+
// only show for application commands - for prefix commands there is no way to hide the response and avoid spam
101+
ctx.send(
102+
poise::CreateReply::default()
103+
.content("❌ You're not allowed to use this command.")
104+
.ephemeral(true),
105+
)
106+
.await
107+
.ok();
108+
}
109+
}
110+
92111
error => {
93112
if let Err(e) = poise::builtins::on_error(error).await {
94113
error!("Unhandled error occurred:\n{e:#?}");

0 commit comments

Comments
 (0)