From 5a702b16cb79bee0e715b037850113bbb353816c Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Mon, 6 Jul 2020 12:52:45 -0400 Subject: [PATCH] Remove limits for mods on voting and community buckets --- youmubot-core/src/community/votes.rs | 1 + youmubot/src/main.rs | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/youmubot-core/src/community/votes.rs b/youmubot-core/src/community/votes.rs index 61152b0..17adbaf 100644 --- a/youmubot-core/src/community/votes.rs +++ b/youmubot-core/src/community/votes.rs @@ -18,6 +18,7 @@ use youmubot_prelude::{Duration as ParseDuration, *}; #[bucket = "voting"] #[only_in(guilds)] #[min_args(2)] +#[owner_privilege] pub fn vote(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult { // Parse stuff first let args = args.quoted(); diff --git a/youmubot/src/main.rs b/youmubot/src/main.rs index 8b35894..cb21aa0 100644 --- a/youmubot/src/main.rs +++ b/youmubot/src/main.rs @@ -3,8 +3,10 @@ use dotenv::var; use serenity::{ framework::standard::{DispatchError, StandardFramework}, model::{ - channel::{Message, Reaction}, + channel::{Channel, Message, Reaction}, gateway, + id::{ChannelId, GuildId, UserId}, + permissions::Permissions, }, }; use youmubot_prelude::*; @@ -41,6 +43,19 @@ impl EventHandler for Handler { } } +/// Returns whether the user has "MANAGE_MESSAGES" permission in the channel. +fn is_channel_mod(ctx: &mut Context, _: Option, ch: ChannelId, u: UserId) -> bool { + match ch.to_channel(&ctx) { + Ok(Channel::Guild(gc)) => { + let gc = gc.read(); + gc.permissions_for_user(&ctx, u) + .map(|perms| perms.contains(Permissions::MANAGE_MESSAGES)) + .unwrap_or(false) + } + _ => false, + } +} + fn main() { // Setup dotenv if let Ok(path) = dotenv::dotenv() { @@ -167,11 +182,11 @@ fn setup_framework(client: &Client) -> StandardFramework { // println!("Message is not a command '{}'", message.content); }) .bucket("voting", |c| { - c.delay(120 /* 2 minutes */).time_span(120).limit(1) + c.check(|ctx, g, ch, u| !is_channel_mod(ctx, g, ch, u)).delay(120 /* 2 minutes */).time_span(120).limit(1) }) .bucket("images", |c| c.time_span(60).limit(2)) .bucket("community", |c| { - c.delay(30).time_span(30).limit(1) + c.check(|ctx, g, ch, u| !is_channel_mod(ctx, g, ch, u)).delay(30).time_span(30).limit(1) }) .group(&prelude_commands::PRELUDE_GROUP); // groups here