From 167a5a404fd042cacc59509da14649fa11aa294c Mon Sep 17 00:00:00 2001 From: jellywx Date: Mon, 30 Nov 2020 21:55:34 +0000 Subject: [PATCH] help command rework --- src/commands/moderation_cmds.rs | 24 ++++++++++++++--- src/commands/reminder_cmds.rs | 46 ++++++++++++++++++++++++++++++--- src/commands/todo_cmds.rs | 35 ++++++++++++++++++------- src/consts.rs | 3 ++- 4 files changed, 91 insertions(+), 17 deletions(-) diff --git a/src/commands/moderation_cmds.rs b/src/commands/moderation_cmds.rs index f027944..71aa464 100644 --- a/src/commands/moderation_cmds.rs +++ b/src/commands/moderation_cmds.rs @@ -534,9 +534,18 @@ WHERE let _ = msg.channel_id.say(&ctx, display).await; } else { + let desc = lm.get(&language, "help/restrict"); + let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; + let _ = msg .channel_id - .say(&ctx, lm.get(&language, "restrict/help")) + .send_message(ctx, |m| { + m.embed(move |e| { + e.title("Restrict Help") + .description(desc.replace("{prefix}", &prefix)) + .color(*THEME_COLOR) + }) + }) .await; } } @@ -675,8 +684,17 @@ SELECT command FROM command_aliases WHERE guild_id = (SELECT id FROM guilds WHER } } else { let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; - let content = lm.get(&language, "alias/help").replace("{prefix}", &prefix); + let desc = lm.get(&language, "help/alias"); - let _ = msg.channel_id.say(&ctx, content).await; + let _ = msg + .channel_id + .send_message(ctx, |m| { + m.embed(move |e| { + e.title("Alias Help") + .description(desc.replace("{prefix}", &prefix)) + .color(*THEME_COLOR) + }) + }) + .await; } } diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index 32c6228..712a881 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -203,9 +203,18 @@ async fn offset(ctx: &Context, msg: &Message, args: String) { let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap(); if args.is_empty() { + let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; + let desc = lm.get(&user_data.language, "help/offset"); + let _ = msg .channel_id - .say(&ctx, lm.get(&user_data.language, "offset/help")) + .send_message(ctx, |m| { + m.embed(move |e| { + e.title("Offset Help") + .description(desc.replace("{prefix}", &prefix)) + .color(*THEME_COLOR) + }) + }) .await; } else { let parser = TimeParser::new(&args, user_data.timezone()); @@ -890,9 +899,18 @@ DELETE FROM timers WHERE owner = ? AND name = ? } _ => { + let desc = lm.get(&language, "help/timer"); + let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; + let _ = msg .channel_id - .say(&ctx, lm.get(&language, "timer/help")) + .send_message(ctx, |m| { + m.embed(move |e| { + e.title("Timer Help") + .description(desc.replace("{prefix}", &prefix)) + .color(*THEME_COLOR) + }) + }) .await; } } @@ -1174,9 +1192,31 @@ async fn remind_command(ctx: &Context, msg: &Message, args: String, command: Rem } None => { + let desc = lm.get( + &user_data.language, + match command { + RemindCommand::Remind => "help/remind", + + RemindCommand::Interval => "help/interval", + }, + ); + + let title = match command { + RemindCommand::Remind => "Remind Help", + RemindCommand::Interval => "Interval Help", + }; + + let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; + let _ = msg .channel_id - .say(&ctx, lm.get(&user_data.language, "remind/no_argument")) + .send_message(ctx, |m| { + m.embed(move |e| { + e.title(title) + .description(desc.replace("{prefix}", &prefix)) + .color(*THEME_COLOR) + }) + }) .await; } } diff --git a/src/commands/todo_cmds.rs b/src/commands/todo_cmds.rs index d4918e3..a3061b1 100644 --- a/src/commands/todo_cmds.rs +++ b/src/commands/todo_cmds.rs @@ -12,6 +12,7 @@ use serenity::{ use std::fmt; use crate::{ + consts::THEME_COLOR, models::{GuildData, UserData}, SQLPool, }; @@ -458,15 +459,29 @@ async fn show_help(ctx: &Context, msg: &Message, target: Option) { let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap(); let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; - let content = lm - .get(&user_data.language, "todo/help") - .replace("{prefix}", &prefix) - .replace( - "{command}", - target - .map_or_else(|| "todo user".to_string(), |t| t.command(None)) - .as_str(), - ); + let command = match target { + None => "help/todo", + Some(t) => { + if t.channel.is_some() { + "help/todoc" + } else if t.guild.is_some() { + "help/todos" + } else { + "help/todo" + } + } + }; - let _ = msg.channel_id.say(&ctx, content).await; + let desc = lm.get(&user_data.language, command); + + let _ = msg + .channel_id + .send_message(ctx, |m| { + m.embed(move |e| { + e.title("Todo Help") + .description(desc.replace("{prefix}", &prefix)) + .color(*THEME_COLOR) + }) + }) + .await; } diff --git a/src/consts.rs b/src/consts.rs index b257754..e3a000a 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,7 +1,7 @@ pub const DAY: u64 = 86_400; pub const HOUR: u64 = 3_600; pub const MINUTE: u64 = 60; -pub const HELP_STRINGS: [&'static str; 21] = [ +pub const HELP_STRINGS: [&'static str; 22] = [ "help/lang", "help/timezone", "help/prefix", @@ -23,6 +23,7 @@ pub const HELP_STRINGS: [&'static str; 21] = [ "help/todo", "help/todos", "help/todoc", + "help/timer", ]; pub const CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";