alias all working now

This commit is contained in:
jude 2020-09-04 21:21:47 +01:00
parent aff303dda6
commit 571802c232
3 changed files with 13 additions and 4 deletions

View File

@ -22,7 +22,9 @@ use crate::{
GuildData, GuildData,
}, },
SQLPool, SQLPool,
FrameworkCtx,
}; };
use serenity::framework::Framework;
lazy_static! { lazy_static! {
static ref REGEX_CHANNEL: Regex = Regex::new(r#"^\s*<#(\d+)>\s*$"#).unwrap(); static ref REGEX_CHANNEL: Regex = Regex::new(r#"^\s*<#(\d+)>\s*$"#).unwrap();
@ -309,13 +311,19 @@ UPDATE command_aliases SET command = ? WHERE guild_id = (SELECT id FROM guilds W
else { else {
match sqlx::query!( match sqlx::query!(
" "
SELECT command FROM command_aliases WHERE guild_id = ? AND name = ? SELECT command FROM command_aliases WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?) AND name = ?
", guild_id, name) ", guild_id, name)
.fetch_one(&pool) .fetch_one(&pool)
.await { .await {
Ok(row) => { Ok(row) => {
// run aliased command content let framework = ctx.data.read().await
.get::<FrameworkCtx>().cloned().expect("Could not get FrameworkCtx from data");
let mut new_msg = msg.clone();
new_msg.content = format!("<@{}> {}", &ctx.cache.current_user_id().await, row.command);
framework.dispatch(ctx.clone(), new_msg).await;
}, },
Err(_) => { Err(_) => {

View File

@ -295,8 +295,7 @@ impl Framework for RegexFramework {
if (msg.author.bot && self.ignore_bots) || if (msg.author.bot && self.ignore_bots) ||
msg.tts || msg.tts ||
msg.content.len() == 0 || msg.content.len() == 0 ||
msg.attachments.len() > 0 msg.attachments.len() > 0 {
{
return return
} }

View File

@ -86,6 +86,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.add_command("offset", &reminder_cmds::OFFSET_COMMAND) .add_command("offset", &reminder_cmds::OFFSET_COMMAND)
.add_command("nudge", &reminder_cmds::NUDGE_COMMAND) .add_command("nudge", &reminder_cmds::NUDGE_COMMAND)
.add_command("alias", &moderation_cmds::ALIAS_COMMAND)
.build(); .build();
let framework_arc = Arc::new(Box::new(framework) as Box<dyn Framework + Send + Sync>); let framework_arc = Arc::new(Box::new(framework) as Box<dyn Framework + Send + Sync>);