From 6402a9b70586f6c16b34bb7e93c99e87fdfc3c97 Mon Sep 17 00:00:00 2001 From: jellywx Date: Tue, 15 Dec 2020 22:26:42 +0000 Subject: [PATCH] removed look all, fixed look #channel with other switches. added a changelog to be posted to discord --- 1.3.0-changelog | 34 ++++++++++++++ src/commands/reminder_cmds.rs | 87 +++++++++-------------------------- 2 files changed, 55 insertions(+), 66 deletions(-) create mode 100644 1.3.0-changelog diff --git a/1.3.0-changelog b/1.3.0-changelog new file mode 100644 index 0000000..7949d5c --- /dev/null +++ b/1.3.0-changelog @@ -0,0 +1,34 @@ +**Reminder Bot Update 1.3.0** + +- `help` command reworked: + + The help command now shows all information within Discord, rather than redirecting to an external website + + The help command has separate pages for different commands with examples, and detailed information on arguments + +- `timezone` command reworked: + + Timezone was a notoriously annoying and confusing command to use, so these changes will hopefully improve its usability + + Typing `$timezone` will now show you a list of the most popular timezones and the time in those timezones, to make it easy for many users to select their timezones + + If a timezone is not recognised, the bot will show you a list of 'similar' timezones by name, and the times in these timezones + + Outputs are more descriptive + +- `language` command reworked: + + Language has been made to look somewhat nicer and you can now use reactions to respond with what language you wish to switch to + +- `timer` visual improvements: + + Some emojis have been added to the timer command to make it look nicer + +- `look` fixes: + + `$look all` has been removed again, as some users pointed out that this was flawed and allowed random users to check reminders in private channels + + Fixed a bug where channels would be ignored if other switches were provided to the command + +- `remind` command reworked: + + Backend of this command completely reworked to be much cleaner code + + Fixed providing times in exact format sometimes not working if a day was provided but not a month/year + + This command can now be used to bulk-set reminders to multiple locations + +- General changes: + + More command outputs use embeds to look nicer + + Commands that fail provide help outputs that are the same as the help command + + Remind commands now provide output that is more detailed. This includes showing the exact errors that occurred for each reminder that couldn't be set, if bulk-setting reminders + + Translations are now loaded from a JSON file included within the executable, which should be faster + + Reduced user caching by individually querying some attributes like language and timezone + diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index fc44e45..5632061 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -338,16 +338,10 @@ enum TimeDisplayType { Relative, } -enum Selection { - None, - Single(T), - All, -} - struct LookFlags { pub limit: u16, pub show_disabled: bool, - pub channel_id: Selection, + pub channel_id: Option, time_display: TimeDisplayType, } @@ -356,7 +350,7 @@ impl Default for LookFlags { Self { limit: u16::MAX, show_disabled: true, - channel_id: Selection::None, + channel_id: None, time_display: TimeDisplayType::Relative, } } @@ -376,20 +370,18 @@ impl LookFlags { new_flags.time_display = TimeDisplayType::Absolute; } - "all" => { - new_flags.channel_id = Selection::All; - } - param => { if let Ok(val) = param.parse::() { new_flags.limit = val; } else { - new_flags.channel_id = REGEX_CHANNEL - .captures(&args) + if let Some(channel) = REGEX_CHANNEL + .captures(&arg) .map(|cap| cap.get(1)) .flatten() .map(|c| c.as_str().parse::().unwrap()) - .map_or(Selection::None, Selection::Single); + { + new_flags.channel_id = Some(channel); + } } } } @@ -442,16 +434,13 @@ async fn look(ctx: &Context, msg: &Message, args: String) { let enabled = if flags.show_disabled { "0,1" } else { "1" }; let reminders = if let Some(guild_id) = msg.guild_id.map(|f| f.as_u64().to_owned()) { - let channel_id_opt = match flags.channel_id { - Selection::None => Some(msg.channel_id.as_u64().to_owned()), - Selection::Single(id) => Some(id), - Selection::All => None, - }; + let channel_id = flags + .channel_id + .unwrap_or_else(|| msg.channel_id.as_u64().to_owned()); - if let Some(channel_id) = channel_id_opt { - sqlx::query_as!( - LookReminder, - " + sqlx::query_as!( + LookReminder, + " SELECT reminders.id, reminders.time, channels.channel, messages.content, embeds.description FROM @@ -477,48 +466,13 @@ ORDER BY LIMIT ? ", - guild_id, - channel_id, - enabled, - flags.limit - ) - .fetch_all(&pool) - .await - } else { - sqlx::query_as!( - LookReminder, - " -SELECT - reminders.id, reminders.time, channels.channel, messages.content, embeds.description -FROM - reminders -INNER JOIN - channels -ON - reminders.channel_id = channels.id -INNER JOIN - messages -ON - messages.id = reminders.message_id -LEFT JOIN - embeds -ON - embeds.id = messages.embed_id -WHERE - channels.guild_id = (SELECT id FROM guilds WHERE guild = ?) AND - FIND_IN_SET(reminders.enabled, ?) -ORDER BY - reminders.time -LIMIT - ? - ", - guild_id, - enabled, - flags.limit - ) - .fetch_all(&pool) - .await - } + guild_id, + channel_id, + enabled, + flags.limit + ) + .fetch_all(&pool) + .await } else { sqlx::query_as_unchecked!( LookReminder, @@ -570,6 +524,7 @@ LIMIT .timestamp(reminder.time as i64, 0) .format("%Y-%m-%d %H:%M:%S") .to_string(), + TimeDisplayType::Relative => { let now = SystemTime::now() .duration_since(UNIX_EPOCH)