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

@ -16,7 +16,7 @@ use serenity::{
use tokio::process::Command; use tokio::process::Command;
use crate::{ use crate::{
check_subscription_on_message, check_subscription_on_message, command_help,
consts::{ consts::{
CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, PYTHON_LOCATION, CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, PYTHON_LOCATION,
REGEX_CHANNEL, REGEX_CHANNEL_USER, REGEX_CONTENT_SUBSTITUTION, REGEX_INTERVAL_COMMAND, 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() { if args.is_empty() {
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await; let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
let desc = lm.get(&user_data.language, "help/offset");
let _ = msg command_help(ctx, msg, lm, &prefix, &user_data.language, "offset").await;
.channel_id
.send_message(ctx, |m| {
m.embed(move |e| {
e.title("Offset Help")
.description(desc.replace("{prefix}", &prefix))
.color(*THEME_COLOR)
})
})
.await;
} else { } else {
let parser = TimeParser::new(&args, user_data.timezone()); 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 prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
let _ = msg command_help(ctx, msg, lm, &prefix, &language, "timer").await;
.channel_id
.send_message(ctx, |m| {
m.embed(move |e| {
e.title("Timer Help")
.description(desc.replace("{prefix}", &prefix))
.color(*THEME_COLOR)
})
})
.await;
} }
} }
} }
@ -1199,33 +1179,17 @@ 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 prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
let _ = msg match command {
.channel_id RemindCommand::Remind => {
.send_message(ctx, |m| { command_help(ctx, msg, lm, &prefix, &user_data.language, "remind").await
m.embed(move |e| { }
e.title(title)
.description(desc.replace("{prefix}", &prefix)) RemindCommand::Interval => {
.color(*THEME_COLOR) command_help(ctx, msg, lm, &prefix, &user_data.language, "interval").await
}) }
}) }
.await;
} }
} }
} }

View File

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