moover_rust/src/utils/debug.rs

50 lines
1.4 KiB
Rust
Raw Normal View History

use std::sync::Arc;
2024-02-14 12:22:29 +00:00
use serenity::http::Http;
2024-02-14 12:22:29 +00:00
2024-10-03 20:52:38 +00:00
pub async fn send_error(_http: Arc<Http>, msg: String) -> anyhow::Result<()> {
println!("ERROR: {msg}");
2024-02-16 21:06:12 +00:00
#[cfg(feature="RELEASE")] {
use serenity::all::ChannelId;
use std::process::exit;
2024-10-06 12:02:24 +00:00
use std::env;
2024-10-03 20:52:38 +00:00
use anyhow::Context;
2024-10-06 12:02:24 +00:00
let channel_id: String = env::var("DEBUG_CHANNEL_ID").context("DEBUG_CHANNEL_ID not found in env file")?;
2024-10-03 20:52:38 +00:00
match ChannelId::new(channel_id.parse::<u64>().unwrap())
.say(_http, msg).await {
Ok(_) => { return Ok(()); }
2024-02-16 21:06:12 +00:00
Err(_) => { exit(-1) }
2024-10-03 20:52:38 +00:00
};
}
2024-10-03 20:52:38 +00:00
Ok(())
2024-02-16 21:06:12 +00:00
}
#[cfg(feature="RELEASE")]
2024-10-03 20:52:38 +00:00
pub async fn hello(http: Arc<Http>) -> anyhow::Result<()> {
2024-02-16 21:06:12 +00:00
use serenity::all::ChannelId;
2024-10-03 20:52:38 +00:00
use anyhow::Context;
2024-10-06 12:02:24 +00:00
use std::env;
2024-02-14 12:22:29 +00:00
let messages = [
"AAAAAAAAAAAAAAAAAAAA",
"Henlooo",
"Good day y'all!",
"May have crashed...",
"MOOOooo",
"Heyyyyy!",
"I'm baaaaack!",
"Whom'st have summoned the ancient one?",
];
let num = rand::random::<usize>() % messages.len();
2024-10-06 12:02:24 +00:00
let channel_id: String = env::var("DEBUG_CHANNEL_ID").context("DEBUG_CHANNEL_ID not found in env file")?;
2024-10-03 20:52:38 +00:00
let channel = ChannelId::new(channel_id.parse::<u64>().unwrap());
2024-02-14 12:22:29 +00:00
if let Err(why) = channel.say(http, messages[num]).await {
print!("Error sending message: {:?}", why);
};
2024-10-03 20:52:38 +00:00
Ok(())
2024-02-14 12:22:29 +00:00
}