From 74518da0bcf79d9e4b4cf5a6f4841661ef68ef12 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 13 Nov 2025 11:02:15 +0200 Subject: [PATCH] feat: add optional error messaging to bot admin --- src/config.rs | 6 ++++++ src/main.rs | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 1641853..89e689a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,10 +1,12 @@ use crate::error::{Error, Result}; use std::{env, fmt::Debug, path::PathBuf, sync::OnceLock}; +use teloxide::types::ChatId; static GLOBAL_CONFIG: OnceLock = OnceLock::new(); #[derive(Debug, Clone, Default)] pub struct Config { + pub chat_id: Option, pub youtube: YoutubeConfig, pub instagram: InstagramConfig, pub tiktok: TiktokConfig, @@ -36,7 +38,11 @@ impl Config { /// Load configuration from environment variables. #[must_use] pub fn from_env() -> Self { + let chat_id: Option = env::var("CHAT_ID") + .ok() + .and_then(|id| id.parse::().ok().map(ChatId)); Self { + chat_id, youtube: YoutubeConfig::from_env(), instagram: InstagramConfig::from_env(), tiktok: TiktokConfig::from_env(), diff --git a/src/main.rs b/src/main.rs index 5a6ed77..dfa330a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use dotenv::dotenv; use teloxide::{prelude::*, respond}; use tg_relay_rs::{ comments::Comments, - config::Config, + config::{Config, global_config}, handler::{Handler, create_handlers}, telemetry::setup_logger, }; @@ -58,6 +58,9 @@ async fn process_message(bot: &Bot, msg: &Message, handlers: &[Handler]) { let _ = bot .send_message(msg.chat.id, "Failed to fetch media, you foking donkey.") .await; + if let Some(chat_id) = global_config().chat_id { + let _ = bot.send_message(chat_id, format!("{err}")).await; + } } return; }