disallow numeric names
This commit is contained in:
parent
302e0d0254
commit
3465d7aab6
37
src/main.rs
37
src/main.rs
@ -246,7 +246,7 @@ impl EventHandler for Handler {
|
||||
.send()
|
||||
.await;
|
||||
|
||||
if let Ok(res) = response {
|
||||
if let Err(res) = response {
|
||||
println!("DiscordBots Response: {:?}", res);
|
||||
}
|
||||
}
|
||||
@ -670,9 +670,24 @@ async fn change_prefix(ctx: &Context, msg: &Message, mut args: Args) -> CommandR
|
||||
|
||||
#[command("upload")]
|
||||
async fn upload_new_sound(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
|
||||
fn is_numeric(s: &String) -> bool {
|
||||
for char in s.chars() {
|
||||
if char.is_digit(10) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
let new_name = args.rest().to_string();
|
||||
|
||||
if !new_name.is_empty() && new_name.len() <= 20 {
|
||||
|
||||
if !is_numeric(&new_name) {
|
||||
let pool = ctx.data.read().await
|
||||
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
|
||||
|
||||
@ -680,21 +695,18 @@ async fn upload_new_sound(ctx: &Context, msg: &Message, args: Args) -> CommandRe
|
||||
let count_name = Sound::count_named_user_sounds(*msg.author.id.as_u64(), &new_name, pool.clone()).await?;
|
||||
if count_name > 0 {
|
||||
msg.channel_id.say(&ctx, "You are already using that name. Please choose a unique name for your upload.").await?;
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
// need to check how many sounds user currently has
|
||||
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
|
||||
if count >= *MAX_SOUNDS {
|
||||
let patreon_guild_member = GuildId(*PATREON_GUILD).member(ctx, msg.author.id).await?;
|
||||
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 {
|
||||
if let Ok(member) = patreon_guild_member {
|
||||
permit_upload = member.roles.contains(&RoleId(*PATREON_ROLE));
|
||||
} else {
|
||||
permit_upload = false;
|
||||
}
|
||||
}
|
||||
@ -733,8 +745,7 @@ async fn upload_new_sound(ctx: &Context, msg: &Message, args: Args) -> CommandRe
|
||||
msg.channel_id.say(&ctx, "Upload timed out. Please redo the command").await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
msg.channel_id.say(
|
||||
&ctx,
|
||||
format!(
|
||||
@ -744,6 +755,10 @@ async fn upload_new_sound(ctx: &Context, msg: &Message, args: Args) -> CommandRe
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
msg.channel_id.say(&ctx, "Please ensure the sound name contains a non-numerical character").await?;
|
||||
}
|
||||
}
|
||||
else {
|
||||
msg.channel_id.say(&ctx, "Usage: `?upload <name>`. Please ensure the name provided is less than 20 characters in length").await?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user