discord-kurante/src/util/mod.rs

37 lines
1.0 KiB
Rust
Raw Normal View History

2020-05-02 18:37:34 +00:00
use lazy_static::lazy_static;
use serenity::{http::Http, model::channel::Message};
use std::env::var;
2020-05-02 02:41:29 +00:00
pub mod db;
2020-05-02 05:04:51 +00:00
pub mod error;
2020-05-02 18:37:34 +00: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)
}
}