check for patreon role

This commit is contained in:
jude-lafitteIII 2020-04-30 01:21:34 +01:00
parent 9f2317eb6a
commit 5a0b208d81

View File

@ -16,6 +16,10 @@ use serenity::{
} }
}, },
model::{ model::{
id::{
GuildId,
RoleId,
},
channel::Message, channel::Message,
guild::Guild, guild::Guild,
}, },
@ -70,6 +74,16 @@ lazy_static! {
dotenv().unwrap(); dotenv().unwrap();
env::var("MAX_SOUNDS").unwrap().parse::<u32>().unwrap() env::var("MAX_SOUNDS").unwrap().parse::<u32>().unwrap()
}; };
static ref PATREON_GUILD: u64 = {
dotenv().unwrap();
env::var("PATREON_GUILD").unwrap().parse::<u64>().unwrap()
};
static ref PATREON_ROLE: u64 = {
dotenv().unwrap();
env::var("PATREON_ROLE").unwrap().parse::<u64>().unwrap()
};
} }
#[group] #[group]
@ -591,12 +605,21 @@ async fn upload_new_sound(ctx: &mut Context, msg: &Message, mut args: Args) -> C
// need to check how many sounds user currently has // need to check how many sounds user currently has
let count = Sound::count_user_sounds(*msg.author.id.as_u64(), pool.clone()).await?; let count = Sound::count_user_sounds(*msg.author.id.as_u64(), pool.clone()).await?;
let mut permit_upload = true;
// need to check if user is patreon or nah // need to check if user is patreon or nah
if count >= *MAX_SOUNDS { if count >= *MAX_SOUNDS {
let patreon_guild_member = GuildId(*PATREON_GUILD).member(&ctx, msg.author.id).await?;
if patreon_guild_member.roles.contains(&RoleId(*PATREON_ROLE)) {
permit_upload = true;
}
else {
permit_upload = false;
}
} }
if permit_upload {
msg.channel_id.say(&ctx, "Please now upload an audio file under 1MB in size:").await?; msg.channel_id.say(&ctx, "Please now upload an audio file under 1MB in size:").await?;
let reply = msg.channel_id.await_reply(&ctx) let reply = msg.channel_id.await_reply(&ctx)
@ -621,8 +644,7 @@ async fn upload_new_sound(ctx: &mut Context, msg: &Message, mut args: Args) -> C
msg.channel_id.say(&ctx, "Sound failed to upload. Size may be too large").await?; msg.channel_id.say(&ctx, "Sound failed to upload. Size may be too large").await?;
} }
} }
} } else {
else {
msg.channel_id.say(&ctx, "Please upload 1 attachment following your upload command. Aborted").await?; msg.channel_id.say(&ctx, "Please upload 1 attachment following your upload command. Aborted").await?;
} }
} }
@ -632,6 +654,10 @@ async fn upload_new_sound(ctx: &mut Context, msg: &Message, mut args: Args) -> C
} }
} }
} }
else {
msg.channel_id.say(&ctx, "You have reached the maximum number of sounds ({}). Either delete some with `{}delete` or join our Patreon for unlimited uploads at **https://patreon.com/jellywx**").await?;
}
}
else { else {
msg.channel_id.say(&ctx, "Usage: `?upload <name>`. Please ensure the name provided is less than 20 characters in length").await?; msg.channel_id.say(&ctx, "Usage: `?upload <name>`. Please ensure the name provided is less than 20 characters in length").await?;
} }