slashy/
permissions.rs

1use serenity::{
2    client::Context,
3    futures::future::BoxFuture,
4    http::Http,
5    model::{channel::GuildChannel, guild::Member},
6};
7
8use crate::commands::CommandResult;
9
10use slashy_macros::permissions_check;
11
12/// A permissions check
13pub type PermissionsCheck =
14    for<'a> fn(&'a Http, &'a Member, &'a GuildChannel) -> BoxFuture<'a, PermsResult>;
15/// The return type of a permissions check
16pub type PermsResult = CommandResult<bool>;
17
18
19/// Permission check that passes if the member has the administrator permission
20#[allow(non_snake_case)]
21#[permissions_check]
22pub async fn ADMINISTRATOR(
23    ctx: &Context,
24    member: &Member,
25    _channel: &GuildChannel,
26) -> CommandResult<bool> {
27    Ok(member.permissions(ctx)?.administrator())
28}
29
30/// Permission check that passes if the member has the manage messages permission either globaly or in the channel
31#[allow(non_snake_case)]
32#[permissions_check]
33pub async fn MANNAGE_MESSAGES(
34    ctx: &Context,
35    member: &Member,
36    channel: &GuildChannel,
37) -> CommandResult<bool> {
38    Ok(member.permissions(ctx)?.manage_messages()
39        || channel
40            .permissions_for_user(ctx, member.user.id)?
41            .manage_messages())
42}