From 4f3789aeed4fa9dcab3b296ef880f51222ed9440 Mon Sep 17 00:00:00 2001 From: jude Date: Sun, 27 Sep 2020 22:57:55 +0100 Subject: [PATCH] added help for natural command. added prefix_from_id for guilddata --- src/commands/reminder_cmds.rs | 21 +++++++++++---------- src/models.rs | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index b2ae066..373c5ee 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -53,7 +53,6 @@ use sqlx::{ use std::str::from_utf8; use num_integer::Integer; -use num_traits::cast::ToPrimitive; use std::{ convert::TryInto, @@ -744,15 +743,13 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult { .output() .await; - if let Some(timestamp) = python_call.ok().map(|inner| { - println!("{}", from_utf8(&*inner.stdout).unwrap()); - + if let Some(timestamp) = python_call.ok().map(|inner| if inner.status.success() { Some(from_utf8(&*inner.stdout).unwrap().parse::().unwrap()) } else { None - }}).flatten() { + }).flatten() { let mut location_ids = vec![ReminderScope::Channel(msg.channel_id.as_u64().to_owned())]; let mut content = msg_crop; @@ -798,20 +795,24 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult { if res.is_ok() { issue_count += 1; } - else { - println!("{:?}", res); - } } let _ = msg.channel_id.say(&ctx, format!("successfully set {} reminders", issue_count)).await; } // something not right with the time parse else { - println!("ewifjewiof"); + let _ = msg.channel_id.say(&ctx, "DEV ERROR: Failed to invoke Python").await; } } else { - println!("aaaaaaaaaaaaaaaaaaa"); + let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; + + let resp = user_data.response(&pool, "natural/no_argument").await.replace("{prefix}", &prefix); + + let _ = msg.channel_id.send_message(&ctx, |m| m + .embed(|e| e + .description(resp) + )).await; } Ok(()) diff --git a/src/models.rs b/src/models.rs index 5acf561..7e78d0c 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,6 +1,7 @@ use serenity::{ http::CacheHttp, model::{ + id::GuildId, guild::Guild, channel::Channel, user::User, @@ -20,6 +21,25 @@ pub struct GuildData { } impl GuildData { + pub async fn prefix_from_id>(guild_id_opt: Option, pool: &MySqlPool) -> String { + if let Some(guild_id) = guild_id_opt { + let guild_id = guild_id.into().as_u64().to_owned(); + + let row = sqlx::query!( + " +SELECT prefix FROM guilds WHERE guild = ? + ", guild_id + ) + .fetch_one(pool) + .await; + + row.map_or("$".to_string(), |r| r.prefix) + } + else { + "$".to_string() + } + } + pub async fn from_guild(guild: Guild, pool: &MySqlPool) -> Result> { let guild_id = guild.id.as_u64().to_owned();