help command rework

This commit is contained in:
jellywx 2020-11-30 21:55:34 +00:00
parent 268fcab8c5
commit 167a5a404f
4 changed files with 91 additions and 17 deletions

View File

@ -534,9 +534,18 @@ WHERE
let _ = msg.channel_id.say(&ctx, display).await; let _ = msg.channel_id.say(&ctx, display).await;
} else { } else {
let desc = lm.get(&language, "help/restrict");
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
let _ = msg let _ = msg
.channel_id .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; .await;
} }
} }
@ -675,8 +684,17 @@ SELECT command FROM command_aliases WHERE guild_id = (SELECT id FROM guilds WHER
} }
} else { } else {
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; 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;
} }
} }

View File

@ -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(); let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
if args.is_empty() { 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 let _ = msg
.channel_id .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; .await;
} else { } else {
let parser = TimeParser::new(&args, user_data.timezone()); 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 let _ = msg
.channel_id .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; .await;
} }
} }
@ -1174,9 +1192,31 @@ async fn remind_command(ctx: &Context, msg: &Message, args: String, command: Rem
} }
None => { 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 let _ = msg
.channel_id .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; .await;
} }
} }

View File

@ -12,6 +12,7 @@ use serenity::{
use std::fmt; use std::fmt;
use crate::{ use crate::{
consts::THEME_COLOR,
models::{GuildData, UserData}, models::{GuildData, UserData},
SQLPool, SQLPool,
}; };
@ -458,15 +459,29 @@ async fn show_help(ctx: &Context, msg: &Message, target: Option<TodoTarget>) {
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap(); let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
let content = lm let command = match target {
.get(&user_data.language, "todo/help") None => "help/todo",
.replace("{prefix}", &prefix) Some(t) => {
.replace( if t.channel.is_some() {
"{command}", "help/todoc"
target } else if t.guild.is_some() {
.map_or_else(|| "todo user".to_string(), |t| t.command(None)) "help/todos"
.as_str(), } 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;
} }

View File

@ -1,7 +1,7 @@
pub const DAY: u64 = 86_400; pub const DAY: u64 = 86_400;
pub const HOUR: u64 = 3_600; pub const HOUR: u64 = 3_600;
pub const MINUTE: u64 = 60; pub const MINUTE: u64 = 60;
pub const HELP_STRINGS: [&'static str; 21] = [ pub const HELP_STRINGS: [&'static str; 22] = [
"help/lang", "help/lang",
"help/timezone", "help/timezone",
"help/prefix", "help/prefix",
@ -23,6 +23,7 @@ pub const HELP_STRINGS: [&'static str; 21] = [
"help/todo", "help/todo",
"help/todos", "help/todos",
"help/todoc", "help/todoc",
"help/timer",
]; ];
pub const CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; pub const CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";