feat: telegram bot for moderation (allow/deny commands)

This commit is contained in:
Lewis Wynne 2026-04-09 12:39:45 +01:00
parent 660c02d63f
commit 37d2a2b99e
2 changed files with 87 additions and 1 deletions

View file

@ -1,9 +1,11 @@
mod config;
mod entries;
mod render;
mod telegram;
mod web;
use std::sync::Arc;
use teloxide::prelude::*;
#[tokio::main]
async fn main() {
@ -11,12 +13,28 @@ async fn main() {
let config = config::Config::load("config.toml").expect("failed to load config.toml");
let listen = config.listen.clone();
let entries_dir = config.data_dir.join("entries");
let chat_id = ChatId(config.telegram_chat_id);
let (tx, _rx) = tokio::sync::mpsc::channel(32);
std::fs::create_dir_all(&entries_dir).ok();
let bot = Bot::new(&config.telegram_bot_token);
let (tx, rx) = tokio::sync::mpsc::channel(32);
let state = Arc::new(web::AppState { config, tx });
let app = web::router(state);
// Spawn telegram notification sender
let notify_bot = bot.clone();
tokio::spawn(telegram::notification_task(notify_bot, chat_id, rx));
// Spawn telegram command listener
let cmd_bot = bot.clone();
let cmd_entries_dir = entries_dir.clone();
tokio::spawn(telegram::bot_task(cmd_bot, chat_id, cmd_entries_dir));
// Run web server
tracing::info!("listening on {listen}");
let listener = tokio::net::TcpListener::bind(&listen).await.unwrap();
axum::serve(listener, app).await.unwrap();