2020-05-02 11:37:34 -07:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use serenity::{http::Http, model::channel::Message};
|
|
|
|
use std::env::var;
|
2020-05-01 19:41:29 -07:00
|
|
|
pub mod db;
|
2020-05-01 22:04:51 -07:00
|
|
|
pub mod error;
|
2020-05-02 11:37:34 -07:00
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
static ref BOT_OWNER_ID: u64 = var("BOT_OWNER_ID")
|
|
|
|
.unwrap_or_else(|_| {
|
|
|
|
log::warn!("`BOT_OWNER_ID` env var missing, bot will never respond in debug mode!");
|
|
|
|
String::new()
|
|
|
|
})
|
|
|
|
.parse()
|
|
|
|
.unwrap_or_else(|_| {
|
|
|
|
log::error!(
|
|
|
|
"`BOT_OWNER_ID` env var is not a valid u64! Bot will never respond in debug mode!"
|
|
|
|
);
|
|
|
|
0
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn debug_say(
|
|
|
|
msg: &Message,
|
|
|
|
ctx: impl AsRef<Http>,
|
|
|
|
resp: impl std::fmt::Display,
|
|
|
|
) -> Result<Option<Message>, 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?,
|
|
|
|
))
|
|
|
|
} else if !cfg!(debug_assertions) {
|
|
|
|
Ok(Some(msg.channel_id.say(ctx, resp).await?))
|
|
|
|
} else {
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|