Create NotBannedPermission

This commit is contained in:
2025-08-14 23:50:18 -03:00
parent 208e0ddbf5
commit fb7eba11bb
2 changed files with 38 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@ pub(super) mod components;
pub(super) mod embeds; pub(super) mod embeds;
pub mod events; pub mod events;
pub(super) mod moderation; pub(super) mod moderation;
pub(super) mod permissions;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct DisplayProfile { pub struct DisplayProfile {
+37
View File
@@ -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<State> for NotBannedPermission {
async fn check(&self, ctx: &CommandContext<State>) -> Result<bool, CommandError> {
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)
}
}
}