diff --git a/README.md b/README.md index 75cd662..8230abd 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ Config options: * `PATREON_GUILD`- specifies the ID of the guild being used for Patreon benefits * `PATREON_ROLE`- specifies the role being checked for Patreon benefits * `CACHING_LOCATION`- specifies the location in which to cache the audio files (defaults to `/tmp/`) - +* `CLIENT_ID`- specifies the ID of the client for mention commands diff --git a/src/guilddata.rs b/src/guilddata.rs index 513d248..fdbecba 100644 --- a/src/guilddata.rs +++ b/src/guilddata.rs @@ -13,7 +13,7 @@ impl GuildData { let guild = sqlx::query_as!( GuildData, " -SELECT * +SELECT id, name, prefix, volume FROM servers WHERE id = ? ", guild_id @@ -21,11 +21,8 @@ SELECT * .fetch_one(&db_pool) .await; - match guild { - Ok(guild) => Some(guild), - Err(_) => None, - } + guild.ok() } pub async fn create_from_guild(guild: Guild, db_pool: MySqlPool) -> Result> { diff --git a/src/main.rs b/src/main.rs index 54e07ef..e4d0a56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ use serenity::{ id::{ GuildId, RoleId, + UserId, }, voice::VoiceState, }, @@ -296,6 +297,8 @@ async fn main() -> Result<(), Box> { .allow_dm(false) .ignore_bots(true) .ignore_webhooks(true) + .on_mention(env::var("CLIENT_ID") + .and_then(|val| Ok(UserId(val.parse::().expect("CLIENT_ID not valid")))).ok()) ) .group(&ALLUSERS_GROUP) .group(&ROLEMANAGEDUSERS_GROUP) @@ -745,7 +748,7 @@ async fn change_public(ctx: &Context, msg: &Message, args: Args) -> CommandResul match sound_result { Some(sound) => { - if sound.uploader_id != *uid { + if sound.uploader_id != Some(*uid) { msg.channel_id.say(&ctx, "You can only change the availability of sounds you have uploaded. Use `?list me` to view your sounds").await?; } @@ -787,7 +790,7 @@ async fn delete_sound(ctx: &Context, msg: &Message, args: Args) -> CommandResult match sound_result { Some(sound) => { - if sound.uploader_id != uid && sound.server_id != gid { + if sound.uploader_id != Some(uid) && sound.server_id != gid { msg.channel_id.say(&ctx, "You can only delete sounds from this guild or that you have uploaded.").await?; } @@ -881,9 +884,9 @@ SELECT * FROM sounds " ) .fetch_all(&pool) - .await?; + .await.unwrap(); - format_search_results(search_results, msg, ctx).await?; + format_search_results(search_results, msg, ctx).await.unwrap(); Ok(()) } diff --git a/src/sound.rs b/src/sound.rs index 180f070..1058293 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -24,7 +24,7 @@ pub struct Sound { pub plays: u32, pub public: bool, pub server_id: u64, - pub uploader_id: u64, + pub uploader_id: Option, pub src: Vec, }