From bff5684b38c531577272253cb8540f4c9d710482 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 26 Apr 2020 21:14:00 -0500 Subject: [PATCH] Added permissions check + Permissions are handled in the `before` command call --- src/main.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main.rs b/src/main.rs index e37fff2..821115c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -255,6 +255,26 @@ fn get_config(data: &Arc>) -> std::result::Result bool { + if let Some(guild_id) = msg.guild_id { + if let Ok(config) = get_config(&ctx.data) { + if let Ok(roles) = ctx.http.get_guild_roles(guild_id.0) { + for role in roles { + if config.event_roles.contains(&role.id.0) { + return match msg.author.has_role(ctx, guild_id, role) { + Ok(has_role) => has_role, + Err(_) => false, + }; + } + } + } + } + } + + false +} + #[command] /// Posts the pending event in the shared context fn confirm_event(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult { @@ -351,6 +371,7 @@ fn create_event(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResu Ok(()) } + embed_migrations!("migrations/"); fn main() -> clap::Result<()> { // Initialize arg parser @@ -394,7 +415,9 @@ fn main() -> clap::Result<()> { c.prefix(cfg.prefix.as_str().clone()) .allow_dm(false) .ignore_bots(true) + .ignore_webhooks(true) }) + .before(permission_check) .group(&EVENTCOMMANDS_GROUP), );