From c62add05e69007875576eb91d3be7d36caa6c859 Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Sat, 2 May 2020 15:55:32 -0400 Subject: [PATCH] debug_say for crosspost --- src/commands/crosspost.rs | 5 ++--- src/util/mod.rs | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/commands/crosspost.rs b/src/commands/crosspost.rs index 1e261ce..9363f03 100644 --- a/src/commands/crosspost.rs +++ b/src/commands/crosspost.rs @@ -1,6 +1,5 @@ -use crate::util::debug_say; +use crate::util::debug_channel_say; use lazy_static::lazy_static; -use log::error; use regex::Regex; use serenity::framework::standard::CommandError; use serenity::framework::standard::{macros::command, Args, CommandResult}; @@ -44,7 +43,7 @@ async fn crosspost(ctx: &Context, msg: &Message, mut args: Args) -> CommandResul args.rest() ); for channel in channels { - channel.say(ctx, &rest).await?; + debug_channel_say(&channel.into(), *msg.author.id.as_u64(), ctx, &rest).await?; } Ok(()) diff --git a/src/util/mod.rs b/src/util/mod.rs index 935c079..b13b3a0 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,5 +1,8 @@ use lazy_static::lazy_static; -use serenity::{http::Http, model::channel::Message}; +use serenity::{ + http::Http, + model::{channel::Message, id::ChannelId}, +}; use std::env::var; pub mod db; pub mod error; @@ -24,12 +27,19 @@ pub async fn debug_say( ctx: impl AsRef, resp: impl std::fmt::Display, ) -> Result, serenity::Error> { - if cfg!(debug_assertions) && *msg.author.id.as_u64() == *BOT_OWNER_ID { - Ok(Some( - msg.channel_id.say(ctx, format!("DEBUG: {}", resp)).await?, - )) + debug_channel_say(&msg.channel_id, *msg.author.id.as_u64(), ctx, resp).await +} + +pub async fn debug_channel_say( + channel: &ChannelId, + author_id: u64, + ctx: impl AsRef, + resp: impl std::fmt::Display, +) -> Result, serenity::Error> { + if cfg!(debug_assertions) && author_id == *BOT_OWNER_ID { + Ok(Some(channel.say(ctx, format!("DEBUG: {}", resp)).await?)) } else if !cfg!(debug_assertions) { - Ok(Some(msg.channel_id.say(ctx, resp).await?)) + Ok(Some(channel.say(ctx, resp).await?)) } else { Ok(None) }