feat: add channeld ids to env file

This commit is contained in:
Ladislav Hano 2024-10-03 22:52:38 +02:00
parent 6a9af83da2
commit 17dec64596
3 changed files with 30 additions and 15 deletions

View file

@ -41,7 +41,10 @@ pub async fn handle(ctx: Context, msg: Message) {
let new_content = format!("Sent by {}\n{}", msg.clone().author, lower_case_content.replace(site, fix));
match utilities::replace_msg(ctx.http.clone(), msg.clone(), new_content).await {
Ok(_) => {},
Err(e) => send_error(ctx.http.clone(), e.to_string()).await
Err(e) => {
let _ = send_error(ctx.http.clone(), e.to_string()).await;
return;
}
};
}
}
@ -50,7 +53,10 @@ pub async fn handle(ctx: Context, msg: Message) {
if random::<u16>() % 10000 == 666 {
match msg.reply(ctx.http(), "Povedz loď").await {
Ok(_) => {},
Err(e) => send_error(ctx.http.clone(), e.to_string()).await
Err(e) => {
let _ = send_error(ctx.http.clone(), e.to_string()).await;
return;
}
}
}
@ -78,7 +84,7 @@ async fn response(http: Arc<Http>, msg: Message) -> bool {
match msg.reply(http.clone(), RESPONSES[num]).await {
Ok(_) => { return true }
Err(e) => {
send_error(http, e.to_string()).await;
let _ = send_error(http, e.to_string()).await;
return false
}
};
@ -94,7 +100,7 @@ async fn henlo(http: Arc<Http>, msg: Message) -> bool {
match msg.reply(http.clone(), response).await {
Ok(_) => { return true }
Err(e) => {
send_error(http, e.to_string()).await;
let _ = send_error(http, e.to_string()).await;
return false
}
};

View file

@ -18,7 +18,7 @@ use tenorv2::{tenor, tenor_builder::Tenor, tenor_types::{ContentFilter, MediaFil
pub async fn notice_wrapper(ctx: Context) {
match notice(ctx.http.clone()).await {
Err(e) => {
send_error(ctx.http.clone(), e.to_string()).await;
let _ = send_error(ctx.http.clone(), e.to_string()).await;
return;
},
Result::Ok(_) => return
@ -63,7 +63,7 @@ async fn celebrate_birthday(guild_id: GuildId, user_id: UserId, nick: &str, http
let gif_url = match tenor::get_gif_url(MediaFilter::gif, tenor_response) {
Ok(urls) => Some(urls),
Err(e) => {
send_error(http.clone(), e.to_string()).await;
let _ = send_error(http.clone(), e.to_string()).await;
None
}
};

View file

@ -2,25 +2,31 @@ use std::sync::Arc;
use serenity::http::Http;
pub async fn send_error(_http: Arc<Http>, msg: String) {
pub async fn send_error(_http: Arc<Http>, msg: String) -> anyhow::Result<()> {
println!("ERROR: {msg}");
#[cfg(feature="RELEASE")] {
use serenity::all::ChannelId;
use serenity::all::CreateMessage;
use std::process::exit;
match ChannelId::new(1199495008416440491)
.send_message(_http, CreateMessage::new().content(msg)).await {
Ok(_) => { return; }
use super::security::dotenv_var;
use anyhow::Context;
let channel_id: String = dotenv_var("DEBUG_CHANNEL_ID").context("DEBUG_CHANNEL_ID not found in env file")?;
match ChannelId::new(channel_id.parse::<u64>().unwrap())
.say(_http, msg).await {
Ok(_) => { return Ok(()); }
Err(_) => { exit(-1) }
};
};
}
Ok(())
}
#[cfg(feature="RELEASE")]
pub async fn hello(http: Arc<Http>) {
pub async fn hello(http: Arc<Http>) -> anyhow::Result<()> {
use serenity::all::ChannelId;
use anyhow::Context;
use super::security::dotenv_var;
let messages = [
"AAAAAAAAAAAAAAAAAAAA",
@ -35,8 +41,11 @@ pub async fn hello(http: Arc<Http>) {
let num = rand::random::<usize>() % messages.len();
let channel = ChannelId::new(780439236867653635);
let channel_id: String = dotenv_var("DEBUG_CHANNEL_ID").context("DEBUG_CHANNEL_ID not found in env file")?;
let channel = ChannelId::new(channel_id.parse::<u64>().unwrap());
if let Err(why) = channel.say(http, messages[num]).await {
print!("Error sending message: {:?}", why);
};
Ok(())
}