Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ pub fn all() -> Vec<Command> {
general!(stars),
general!(tag),
moderation!(set_welcome),
moderation!(support_ban, support_ban),
moderation!(support_ban, support_unban),
]
}
1 change: 1 addition & 0 deletions src/commands/moderation/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod set_welcome;
pub mod support_ban;
72 changes: 72 additions & 0 deletions src/commands/moderation/support_ban.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#![allow(clippy::unreadable_literal)]

use poise::serenity_prelude::{Member, RoleId};

use crate::{Context, Error};

const ROLE_ID: RoleId = RoleId::new(1149435921301786634);
const HELPER_ID: RoleId = RoleId::new(1391519658917761106);

#[poise::command(
slash_command,
prefix_command,
check = "require_helper",
ephemeral,
guild_only
)]
pub async fn support_ban(ctx: Context<'_>, member: Member) -> Result<(), Error> {
if member.roles.contains(&ROLE_ID) {
ctx.say(format!(
"❌ `{}` is already banned from support.",
member.user.tag()
))
.await?;

return Ok(());
}

member.add_role(ctx.http(), ROLE_ID).await?;
ctx.say(format!("✅ Banned `{}` from support!", &member.user.tag()))
.await?;

Ok(())
}

#[poise::command(
slash_command,
prefix_command,
check = "require_helper",
ephemeral,
guild_only
)]
pub async fn support_unban(ctx: Context<'_>, member: Member) -> Result<(), Error> {
if !member.roles.contains(&ROLE_ID) {
ctx.say(format!(
"❌ `{}` is not banned from support.",
member.user.tag()
))
.await?;

return Ok(());
}

member.remove_role(ctx.http(), ROLE_ID).await?;
ctx.say(format!(
"✅ Unbanned `{}` from support!",
&member.user.tag()
))
.await?;

Ok(())
}

async fn require_helper(ctx: Context<'_>) -> Result<bool, Error> {
let Some(member) = ctx.author_member().await else {
return Ok(false);
};

let is_helper = member.roles.contains(&HELPER_ID);
let is_moderator = member.permissions.unwrap_or_default().manage_roles();

Ok(is_helper || is_moderator)
}
19 changes: 19 additions & 0 deletions src/handlers/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ pub async fn handle(error: FrameworkError<'_, Data, Error>) {
}
}

FrameworkError::CommandCheckFailed { error, ctx, .. } => {
if let Some(error) = error {
// just log - it's probably best if people don't find out when they're breaking the perm checking
log::error!(
"Error checking permissions for {}:\n{error:?}",
ctx.command().name
);
} else if let poise::Context::Application(ctx) = ctx {
// only show for application commands - for prefix commands there is no way to hide the response and avoid spam
ctx.send(
poise::CreateReply::default()
.content("❌ You're not allowed to use this command.")
.ephemeral(true),
)
.await
.ok();
}
}

error => {
if let Err(e) = poise::builtins::on_error(error).await {
error!("Unhandled error occurred:\n{e:#?}");
Expand Down
Loading