feat: telegram moderation is optional
This commit is contained in:
parent
75f1644cc1
commit
21cadb630b
6 changed files with 44 additions and 33 deletions
29
src/main.rs
29
src/main.rs
|
|
@ -15,26 +15,31 @@ async fn main() {
|
|||
let config = config::Config::from_env().expect("failed to load config");
|
||||
let listen = config.listen_addr();
|
||||
let entries_dir = config.data_dir.join("entries");
|
||||
let chat_id = ChatId(config.telegram_chat_id);
|
||||
|
||||
std::fs::create_dir_all(&entries_dir).ok();
|
||||
|
||||
let bot = Bot::new(&config.telegram_bot_token);
|
||||
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(32);
|
||||
|
||||
// Spawn telegram tasks if configured
|
||||
match (&config.telegram_bot_token, config.telegram_chat_id) {
|
||||
(Some(token), Some(chat_id)) => {
|
||||
let chat_id = ChatId(chat_id);
|
||||
let bot = Bot::new(token);
|
||||
|
||||
let notify_bot = bot.clone();
|
||||
tokio::spawn(telegram::notification_task(notify_bot, chat_id, rx));
|
||||
|
||||
let cmd_entries_dir = entries_dir.clone();
|
||||
tokio::spawn(telegram::bot_task(bot, chat_id, cmd_entries_dir));
|
||||
}
|
||||
_ => {
|
||||
tracing::info!("telegram not configured, moderation notifications disabled");
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue