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;
} 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;
}
}

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();
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;
}
}

View File

@ -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<TodoTarget>) {
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 _ = msg.channel_id.say(&ctx, content).await;
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 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 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_";