deduplication

This commit is contained in:
jellywx 2020-12-18 17:41:36 +00:00
parent ca68b45ebe
commit ec04c40cc8
3 changed files with 24 additions and 101 deletions

View File

@ -15,6 +15,7 @@ use inflector::Inflector;
use levenshtein::levenshtein;
use crate::{
command_help,
consts::{REGEX_ALIAS, REGEX_CHANNEL, REGEX_COMMANDS, REGEX_ROLE, THEME_COLOR},
framework::SendIterator,
get_ctx_data,
@ -240,17 +241,7 @@ async fn change_meridian(ctx: &Context, msg: &Message, args: String) {
} else {
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
let _ = msg
.channel_id
.send_message(&ctx, |m| {
m.embed(|e| {
e.title("Meridian Help").color(*THEME_COLOR).description(
lm.get(&user_data.language, "help/meridian")
.replace("{prefix}", &prefix),
)
})
})
.await;
command_help(ctx, msg, lm, &prefix, &user_data.language, "meridian").await;
}
}
@ -539,19 +530,9 @@ WHERE
})
.await;
} else {
let desc = lm.get(&language, "help/restrict");
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
let _ = msg
.channel_id
.send_message(ctx, |m| {
m.embed(move |e| {
e.title("Restrict Help")
.description(desc.replace("{prefix}", &prefix))
.color(*THEME_COLOR)
})
})
.await;
command_help(ctx, msg, lm, &prefix, &language, "restrict").await;
}
}
@ -677,17 +658,7 @@ 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 desc = lm.get(&language, "help/alias");
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;
command_help(ctx, msg, lm, &prefix, &language, "alias").await;
}
}

View File

@ -16,7 +16,7 @@ use serenity::{
use tokio::process::Command;
use crate::{
check_subscription_on_message,
check_subscription_on_message, command_help,
consts::{
CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, PYTHON_LOCATION,
REGEX_CHANNEL, REGEX_CHANNEL_USER, REGEX_CONTENT_SUBSTITUTION, REGEX_INTERVAL_COMMAND,
@ -178,18 +178,8 @@ async fn offset(ctx: &Context, msg: &Message, args: String) {
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
.send_message(ctx, |m| {
m.embed(move |e| {
e.title("Offset Help")
.description(desc.replace("{prefix}", &prefix))
.color(*THEME_COLOR)
})
})
.await;
command_help(ctx, msg, lm, &prefix, &user_data.language, "offset").await;
} else {
let parser = TimeParser::new(&args, user_data.timezone());
@ -781,19 +771,9 @@ 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
.send_message(ctx, |m| {
m.embed(move |e| {
e.title("Timer Help")
.description(desc.replace("{prefix}", &prefix))
.color(*THEME_COLOR)
})
})
.await;
command_help(ctx, msg, lm, &prefix, &language, "timer").await;
}
}
}
@ -1199,33 +1179,17 @@ 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
.send_message(ctx, |m| {
m.embed(move |e| {
e.title(title)
.description(desc.replace("{prefix}", &prefix))
.color(*THEME_COLOR)
})
})
.await;
match command {
RemindCommand::Remind => {
command_help(ctx, msg, lm, &prefix, &user_data.language, "remind").await
}
RemindCommand::Interval => {
command_help(ctx, msg, lm, &prefix, &user_data.language, "interval").await
}
}
}
}
}

View File

@ -12,8 +12,7 @@ use serenity::{
use std::fmt;
use crate::{
consts::THEME_COLOR,
get_ctx_data,
command_help, get_ctx_data,
models::{GuildData, UserData},
};
use sqlx::MySqlPool;
@ -431,32 +430,21 @@ async fn todo_guild(ctx: &Context, msg: &Message, args: String) {
async fn show_help(ctx: &Context, msg: &Message, target: Option<TodoTarget>) {
let (pool, lm) = get_ctx_data(&ctx).await;
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
let language = UserData::language_of(&msg.author, &pool);
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool);
let command = match target {
None => "help/todo",
None => "todo",
Some(t) => {
if t.channel.is_some() {
"help/todoc"
"todoc"
} else if t.guild.is_some() {
"help/todos"
"todos"
} else {
"help/todo"
"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;
command_help(ctx, msg, lm, &prefix.await, &language.await, command).await;
}