mirror of
https://github.com/kristoferssolo/tg-relay-rs.git
synced 2025-12-20 11:04:41 +00:00
feat: add optional error messaging to bot admin
This commit is contained in:
parent
34b7ffd6b5
commit
74518da0bc
@ -1,10 +1,12 @@
|
|||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use std::{env, fmt::Debug, path::PathBuf, sync::OnceLock};
|
use std::{env, fmt::Debug, path::PathBuf, sync::OnceLock};
|
||||||
|
use teloxide::types::ChatId;
|
||||||
|
|
||||||
static GLOBAL_CONFIG: OnceLock<Config> = OnceLock::new();
|
static GLOBAL_CONFIG: OnceLock<Config> = OnceLock::new();
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
pub chat_id: Option<ChatId>,
|
||||||
pub youtube: YoutubeConfig,
|
pub youtube: YoutubeConfig,
|
||||||
pub instagram: InstagramConfig,
|
pub instagram: InstagramConfig,
|
||||||
pub tiktok: TiktokConfig,
|
pub tiktok: TiktokConfig,
|
||||||
@ -36,7 +38,11 @@ impl Config {
|
|||||||
/// Load configuration from environment variables.
|
/// Load configuration from environment variables.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn from_env() -> Self {
|
pub fn from_env() -> Self {
|
||||||
|
let chat_id: Option<ChatId> = env::var("CHAT_ID")
|
||||||
|
.ok()
|
||||||
|
.and_then(|id| id.parse::<i64>().ok().map(ChatId));
|
||||||
Self {
|
Self {
|
||||||
|
chat_id,
|
||||||
youtube: YoutubeConfig::from_env(),
|
youtube: YoutubeConfig::from_env(),
|
||||||
instagram: InstagramConfig::from_env(),
|
instagram: InstagramConfig::from_env(),
|
||||||
tiktok: TiktokConfig::from_env(),
|
tiktok: TiktokConfig::from_env(),
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use dotenv::dotenv;
|
|||||||
use teloxide::{prelude::*, respond};
|
use teloxide::{prelude::*, respond};
|
||||||
use tg_relay_rs::{
|
use tg_relay_rs::{
|
||||||
comments::Comments,
|
comments::Comments,
|
||||||
config::Config,
|
config::{Config, global_config},
|
||||||
handler::{Handler, create_handlers},
|
handler::{Handler, create_handlers},
|
||||||
telemetry::setup_logger,
|
telemetry::setup_logger,
|
||||||
};
|
};
|
||||||
@ -58,6 +58,9 @@ async fn process_message(bot: &Bot, msg: &Message, handlers: &[Handler]) {
|
|||||||
let _ = bot
|
let _ = bot
|
||||||
.send_message(msg.chat.id, "Failed to fetch media, you foking donkey.")
|
.send_message(msg.chat.id, "Failed to fetch media, you foking donkey.")
|
||||||
.await;
|
.await;
|
||||||
|
if let Some(chat_id) = global_config().chat_id {
|
||||||
|
let _ = bot.send_message(chat_id, format!("{err}")).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user