help command rework started
This commit is contained in:
parent
d8aaf92335
commit
268fcab8c5
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -292,12 +292,6 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "custom_error"
|
|
||||||
version = "1.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "51ac5e99a7fea3ee8a03fa4721a47e2efd3fbb38358fc61192a54d4c6f866c12"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@ -1348,7 +1342,6 @@ dependencies = [
|
|||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
"chrono-tz",
|
"chrono-tz",
|
||||||
"custom_error",
|
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
@ -18,7 +18,6 @@ chrono-tz = "0.5"
|
|||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
num-integer = "0.1"
|
num-integer = "0.1"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
custom_error = "1.7"
|
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
|
@ -5,12 +5,15 @@ use serenity::{client::Context, model::channel::Message};
|
|||||||
use chrono::offset::Utc;
|
use chrono::offset::Utc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
consts::DEFAULT_PREFIX,
|
consts::{DEFAULT_PREFIX, HELP_STRINGS},
|
||||||
|
language_manager::LanguageManager,
|
||||||
models::{GuildData, UserData},
|
models::{GuildData, UserData},
|
||||||
SQLPool, THEME_COLOR,
|
SQLPool, THEME_COLOR,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::language_manager::LanguageManager;
|
use levenshtein::levenshtein;
|
||||||
|
|
||||||
|
use inflector::Inflector;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
@ -31,7 +34,66 @@ async fn ping(ctx: &Context, msg: &Message, _args: String) {
|
|||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
#[can_blacklist(false)]
|
#[can_blacklist(false)]
|
||||||
async fn help(ctx: &Context, msg: &Message, _args: String) {
|
async fn help(ctx: &Context, msg: &Message, args: String) {
|
||||||
|
async fn default_help(
|
||||||
|
ctx: &Context,
|
||||||
|
msg: &Message,
|
||||||
|
lm: &LanguageManager,
|
||||||
|
prefix: &str,
|
||||||
|
language: &str,
|
||||||
|
) {
|
||||||
|
let desc = lm.get(language, "help/desc").replace("{prefix}", prefix);
|
||||||
|
|
||||||
|
let _ = msg
|
||||||
|
.channel_id
|
||||||
|
.send_message(ctx, |m| {
|
||||||
|
m.embed(move |e| {
|
||||||
|
e.title("Help Menu")
|
||||||
|
.description(desc)
|
||||||
|
.field(
|
||||||
|
lm.get(language, "help/setup_title"),
|
||||||
|
"`lang` `timezone`",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
lm.get(language, "help/mod_title"),
|
||||||
|
"`prefix` `blacklist` `restrict` `alias`",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
lm.get(language, "help/reminder_title"),
|
||||||
|
"`remind` `interval` `natural` `look`",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
lm.get(language, "help/reminder_mod_title"),
|
||||||
|
"`del` `offset` `pause` `nudge`",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
lm.get(language, "help/info_title"),
|
||||||
|
"`help` `info` `donate` `clock`",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
lm.get(language, "help/todo_title"),
|
||||||
|
"`todo` `todos` `todoc`",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.field(lm.get(language, "help/other_title"), "`timer`", true)
|
||||||
|
.footer(|f| {
|
||||||
|
f.text(concat!(
|
||||||
|
env!("CARGO_PKG_NAME"),
|
||||||
|
" ver ",
|
||||||
|
env!("CARGO_PKG_VERSION")
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.color(*THEME_COLOR)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.read().await;
|
||||||
|
|
||||||
let pool = data
|
let pool = data
|
||||||
@ -42,26 +104,43 @@ async fn help(ctx: &Context, msg: &Message, _args: String) {
|
|||||||
let lm = data.get::<LanguageManager>().unwrap();
|
let lm = data.get::<LanguageManager>().unwrap();
|
||||||
|
|
||||||
let language = UserData::language_of(&msg.author, &pool).await;
|
let language = UserData::language_of(&msg.author, &pool).await;
|
||||||
|
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
|
||||||
|
|
||||||
let desc = lm.get(&language, "help");
|
if !args.is_empty() {
|
||||||
|
let closest_match = HELP_STRINGS
|
||||||
|
.iter()
|
||||||
|
.map(|h| (levenshtein(h.split_at(5).1, &args), h))
|
||||||
|
.filter(|(dist, _)| dist < &3)
|
||||||
|
.min_by(|(dist_a, _), (dist_b, _)| dist_a.cmp(dist_b))
|
||||||
|
.map(|(_, string)| string);
|
||||||
|
|
||||||
let _ = msg
|
if let Some(help_str) = closest_match {
|
||||||
.channel_id
|
let desc = lm.get(&language, help_str);
|
||||||
.send_message(ctx, |m| {
|
let command_name = help_str.split_at(5).1;
|
||||||
m.embed(move |e| {
|
|
||||||
e.title("Help Menu")
|
let _ = msg
|
||||||
.description(desc)
|
.channel_id
|
||||||
.footer(|f| {
|
.send_message(ctx, |m| {
|
||||||
f.text(concat!(
|
m.embed(move |e| {
|
||||||
env!("CARGO_PKG_NAME"),
|
e.title(format!("{} Help", command_name.to_title_case()))
|
||||||
" ver ",
|
.description(desc.replace("{prefix}", &prefix))
|
||||||
env!("CARGO_PKG_VERSION")
|
.footer(|f| {
|
||||||
))
|
f.text(concat!(
|
||||||
|
env!("CARGO_PKG_NAME"),
|
||||||
|
" ver ",
|
||||||
|
env!("CARGO_PKG_VERSION")
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.color(*THEME_COLOR)
|
||||||
})
|
})
|
||||||
.color(*THEME_COLOR)
|
})
|
||||||
})
|
.await;
|
||||||
})
|
} else {
|
||||||
.await;
|
default_help(ctx, msg, lm, &prefix, &language).await;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
default_help(ctx, msg, lm, &prefix, &language).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
|
@ -1,6 +1,29 @@
|
|||||||
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] = [
|
||||||
|
"help/lang",
|
||||||
|
"help/timezone",
|
||||||
|
"help/prefix",
|
||||||
|
"help/blacklist",
|
||||||
|
"help/restrict",
|
||||||
|
"help/alias",
|
||||||
|
"help/remind",
|
||||||
|
"help/interval",
|
||||||
|
"help/natural",
|
||||||
|
"help/look",
|
||||||
|
"help/del",
|
||||||
|
"help/offset",
|
||||||
|
"help/pause",
|
||||||
|
"help/nudge",
|
||||||
|
"help/info",
|
||||||
|
"help/help",
|
||||||
|
"help/donate",
|
||||||
|
"help/clock",
|
||||||
|
"help/todo",
|
||||||
|
"help/todos",
|
||||||
|
"help/todoc",
|
||||||
|
];
|
||||||
|
|
||||||
pub const CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
|
pub const CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
|
||||||
|
|
||||||
@ -26,11 +49,11 @@ lazy_static! {
|
|||||||
|
|
||||||
pub static ref REGEX_REMIND_COMMAND: Regex = Regex::new(
|
pub static ref REGEX_REMIND_COMMAND: Regex = Regex::new(
|
||||||
r#"(?P<mentions>(?:<@\d+>\s|<@!\d+>\s|<#\d+>\s)*)(?P<time>(?:(?:\d+)(?:s|m|h|d|:|/|-|))+|()) (?P<content>.*)"#)
|
r#"(?P<mentions>(?:<@\d+>\s|<@!\d+>\s|<#\d+>\s)*)(?P<time>(?:(?:\d+)(?:s|m|h|d|:|/|-|))+|()) (?P<content>.*)"#)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
pub static ref REGEX_INTERVAL_COMMAND: Regex = Regex::new(
|
pub static ref REGEX_INTERVAL_COMMAND: Regex = Regex::new(
|
||||||
r#"(?P<mentions>(?:<@\d+>\s|<@!\d+>\s|<#\d+>\s)*)(?P<time>(?:(?:\d+)(?:s|m|h|d|:|/|-|))+) (?P<interval>(?:(?:\d+)(?:s|m|h|d|))+) (?P<content>.*)"#)
|
r#"(?P<mentions>(?:<@\d+>\s|<@!\d+>\s|<#\d+>\s)*)(?P<time>(?:(?:\d+)(?:s|m|h|d|:|/|-|))+) (?P<interval>(?:(?:\d+)(?:s|m|h|d|))+) (?P<content>.*)"#)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
pub static ref SUBSCRIPTION_ROLES: HashSet<u64> = HashSet::from_iter(
|
pub static ref SUBSCRIPTION_ROLES: HashSet<u64> = HashSet::from_iter(
|
||||||
env::var("SUBSCRIPTION_ROLES")
|
env::var("SUBSCRIPTION_ROLES")
|
||||||
@ -40,6 +63,7 @@ lazy_static! {
|
|||||||
.collect::<Vec<u64>>())
|
.collect::<Vec<u64>>())
|
||||||
.unwrap_or_else(|_| vec![])
|
.unwrap_or_else(|_| vec![])
|
||||||
);
|
);
|
||||||
|
|
||||||
pub static ref CNC_GUILD: Option<u64> = env::var("CNC_GUILD")
|
pub static ref CNC_GUILD: Option<u64> = env::var("CNC_GUILD")
|
||||||
.map(|var| var.parse::<u64>().ok())
|
.map(|var| var.parse::<u64>().ok())
|
||||||
.ok()
|
.ok()
|
||||||
|
Loading…
Reference in New Issue
Block a user