37 lines
962 B
Rust
37 lines
962 B
Rust
use async_trait::async_trait;
|
|
|
|
use crate::{
|
|
framework::commands::{CommandError, context::CommandContext, permissions::Permission},
|
|
state::State,
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
pub struct GuildOnlyPermission;
|
|
|
|
#[async_trait]
|
|
impl Permission<State> for GuildOnlyPermission {
|
|
async fn check(&self, ctx: &CommandContext<State>) -> Result<bool, CommandError> {
|
|
Ok(ctx.event.guild_id.is_none())
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
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)?;
|
|
|
|
Ok(true)
|
|
}
|
|
}
|