Remove limits for mods on voting and community buckets

This commit is contained in:
Natsu Kagami 2020-07-06 12:52:45 -04:00
parent 9e83501259
commit 5a702b16cb
Signed by: nki
GPG key ID: 73376E117CD20735
2 changed files with 19 additions and 3 deletions

View file

@ -18,6 +18,7 @@ use youmubot_prelude::{Duration as ParseDuration, *};
#[bucket = "voting"] #[bucket = "voting"]
#[only_in(guilds)] #[only_in(guilds)]
#[min_args(2)] #[min_args(2)]
#[owner_privilege]
pub fn vote(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult { pub fn vote(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
// Parse stuff first // Parse stuff first
let args = args.quoted(); let args = args.quoted();

View file

@ -3,8 +3,10 @@ use dotenv::var;
use serenity::{ use serenity::{
framework::standard::{DispatchError, StandardFramework}, framework::standard::{DispatchError, StandardFramework},
model::{ model::{
channel::{Message, Reaction}, channel::{Channel, Message, Reaction},
gateway, gateway,
id::{ChannelId, GuildId, UserId},
permissions::Permissions,
}, },
}; };
use youmubot_prelude::*; 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<GuildId>, 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() { fn main() {
// Setup dotenv // Setup dotenv
if let Ok(path) = dotenv::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); // println!("Message is not a command '{}'", message.content);
}) })
.bucket("voting", |c| { .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("images", |c| c.time_span(60).limit(2))
.bucket("community", |c| { .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); .group(&prelude_commands::PRELUDE_GROUP);
// groups here // groups here