From e9d871a47293af340f1b8f39631ee44237001e79 Mon Sep 17 00:00:00 2001 From: Ladislav Hano Date: Thu, 3 Oct 2024 22:52:38 +0200 Subject: [PATCH] feat: add channeld ids to env file --- src/message_handler.rs | 14 ++++++++++---- src/other/notice.rs | 4 ++-- src/util/debug.rs | 27 ++++++++++++++++++--------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/message_handler.rs b/src/message_handler.rs index e4a93b4..1183998 100644 --- a/src/message_handler.rs +++ b/src/message_handler.rs @@ -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::() % 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, 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, 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 } }; diff --git a/src/other/notice.rs b/src/other/notice.rs index 7ddbc4d..5e52bf4 100644 --- a/src/other/notice.rs +++ b/src/other/notice.rs @@ -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 } }; diff --git a/src/util/debug.rs b/src/util/debug.rs index 0cf34c4..3782029 100644 --- a/src/util/debug.rs +++ b/src/util/debug.rs @@ -2,25 +2,31 @@ use std::sync::Arc; use serenity::http::Http; -pub async fn send_error(_http: Arc, msg: String) { +pub async fn send_error(_http: Arc, 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::().unwrap()) + .say(_http, msg).await { + Ok(_) => { return Ok(()); } Err(_) => { exit(-1) } - }; + }; } + Ok(()) } #[cfg(feature="RELEASE")] -pub async fn hello(http: Arc) { +pub async fn hello(http: Arc) -> 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) { let num = rand::random::() % 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::().unwrap()); if let Err(why) = channel.say(http, messages[num]).await { print!("Error sending message: {:?}", why); }; + + Ok(()) } \ No newline at end of file