diff --git a/src/groups/calls/mod.rs b/src/groups/calls/mod.rs index 51d0c04..1b42859 100644 --- a/src/groups/calls/mod.rs +++ b/src/groups/calls/mod.rs @@ -10,6 +10,7 @@ pub(super) mod components; pub(super) mod embeds; pub mod events; pub(super) mod moderation; +pub(super) mod permissions; #[derive(Debug, Clone)] pub struct DisplayProfile { diff --git a/src/groups/calls/permissions.rs b/src/groups/calls/permissions.rs new file mode 100644 index 0000000..c459988 --- /dev/null +++ b/src/groups/calls/permissions.rs @@ -0,0 +1,37 @@ +use async_trait::async_trait; + +use crate::{ + database::models::UserIncident, + framework::commands::{CommandError, context::CommandContext, permissions::Permission}, + groups::calls::components::{CodeOfConductButton, NeedHelpButton}, + state::State, +}; + +#[derive(Debug)] +pub struct NotBannedPermission; + +#[async_trait] +impl Permission for NotBannedPermission { + async fn check(&self, ctx: &CommandContext) -> Result { + let incidents = UserIncident::get_for_user(ctx.event.author.id.get(), &ctx.rt.state.db) + .await + .inspect_err(|e| log::error!("Failed to get user incidents: {e}")) + .map_err(|_| CommandError::DatabaseQueryFailed)?; + + if incidents.iter().any(|i| i.is_active()) { + ctx.send() + .content("❌ You've been banned from Payphone.") + .component(CodeOfConductButton, 1) + .component(NeedHelpButton, 1) + .await + .inspect_err(|e| { + log::error!("Failed to send message: {e}"); + }) + .map_err(|_| CommandError::MessageSendingFailed)?; + + Ok(false) + } else { + Ok(true) + } + } +}