mention for commands

This commit is contained in:
jude-lafitteIII 2020-05-20 15:33:28 +01:00
parent 815600709d
commit 03e3c4f301
4 changed files with 11 additions and 11 deletions

View File

@ -22,4 +22,4 @@ Config options:
* `PATREON_GUILD`- specifies the ID of the guild being used for Patreon benefits * `PATREON_GUILD`- specifies the ID of the guild being used for Patreon benefits
* `PATREON_ROLE`- specifies the role being checked 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/`) * `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

View File

@ -13,7 +13,7 @@ impl GuildData {
let guild = sqlx::query_as!( let guild = sqlx::query_as!(
GuildData, GuildData,
" "
SELECT * SELECT id, name, prefix, volume
FROM servers FROM servers
WHERE id = ? WHERE id = ?
", guild_id ", guild_id
@ -21,11 +21,8 @@ SELECT *
.fetch_one(&db_pool) .fetch_one(&db_pool)
.await; .await;
match guild {
Ok(guild) => Some(guild),
Err(_) => None, guild.ok()
}
} }
pub async fn create_from_guild(guild: Guild, db_pool: MySqlPool) -> Result<GuildData, Box<dyn std::error::Error>> { pub async fn create_from_guild(guild: Guild, db_pool: MySqlPool) -> Result<GuildData, Box<dyn std::error::Error>> {

View File

@ -28,6 +28,7 @@ use serenity::{
id::{ id::{
GuildId, GuildId,
RoleId, RoleId,
UserId,
}, },
voice::VoiceState, voice::VoiceState,
}, },
@ -296,6 +297,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.allow_dm(false) .allow_dm(false)
.ignore_bots(true) .ignore_bots(true)
.ignore_webhooks(true) .ignore_webhooks(true)
.on_mention(env::var("CLIENT_ID")
.and_then(|val| Ok(UserId(val.parse::<u64>().expect("CLIENT_ID not valid")))).ok())
) )
.group(&ALLUSERS_GROUP) .group(&ALLUSERS_GROUP)
.group(&ROLEMANAGEDUSERS_GROUP) .group(&ROLEMANAGEDUSERS_GROUP)
@ -745,7 +748,7 @@ async fn change_public(ctx: &Context, msg: &Message, args: Args) -> CommandResul
match sound_result { match sound_result {
Some(sound) => { 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?; 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 { match sound_result {
Some(sound) => { 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?; 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) .fetch_all(&pool)
.await?; .await.unwrap();
format_search_results(search_results, msg, ctx).await?; format_search_results(search_results, msg, ctx).await.unwrap();
Ok(()) Ok(())
} }

View File

@ -24,7 +24,7 @@ pub struct Sound {
pub plays: u32, pub plays: u32,
pub public: bool, pub public: bool,
pub server_id: u64, pub server_id: u64,
pub uploader_id: u64, pub uploader_id: Option<u64>,
pub src: Vec<u8>, pub src: Vec<u8>,
} }