Make permissions checking and notification separate functions
This commit is contained in:
@@ -19,19 +19,23 @@ impl Permission<State> for NotBannedPermission {
|
||||
.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)
|
||||
}
|
||||
}
|
||||
|
||||
async fn on_handle_denied(&self, ctx: &CommandContext<State>) -> Result<(), CommandError> {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,3 +18,4 @@ pub mod about;
|
||||
pub mod calls;
|
||||
pub mod gateway;
|
||||
pub mod servers;
|
||||
pub mod moderation;
|
||||
|
||||
@@ -20,17 +20,7 @@ pub struct ServerModeratorPermission;
|
||||
|
||||
#[async_trait]
|
||||
impl Permission<State> for ServerModeratorPermission {
|
||||
async fn check(&self, ctx: &CommandContext<State>) -> Result<bool, CommandError> {
|
||||
let member = ctx
|
||||
.rt
|
||||
.http
|
||||
.guild_member(ctx.event.guild_id.unwrap(), ctx.event.author.id)
|
||||
.await
|
||||
.map_err(CommandError::DiscordAPIFailed)?
|
||||
.model()
|
||||
.await
|
||||
.map_err(CommandError::DiscordDeserializationFailed)?;
|
||||
|
||||
async fn check(&self, _ctx: &CommandContext<State>) -> Result<bool, CommandError> {
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user