mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-10-24 17:29:08 +00:00
39 lines
1.0 KiB
Rust
39 lines
1.0 KiB
Rust
|
|
use teloxide::{Bot, prelude::*};
|
||
|
|
use tokio::sync::oneshot;
|
||
|
|
|
||
|
|
use crate::database::DatabaseManager;
|
||
|
|
use super::handlers;
|
||
|
|
|
||
|
|
/// Run the bot polling loop
|
||
|
|
pub async fn run_polling(
|
||
|
|
bot: Bot,
|
||
|
|
db: DatabaseManager,
|
||
|
|
mut shutdown_rx: oneshot::Receiver<()>,
|
||
|
|
) {
|
||
|
|
tracing::info!("Starting Telegram bot polling...");
|
||
|
|
|
||
|
|
let handler = Update::filter_message()
|
||
|
|
.branch(
|
||
|
|
dptree::entry()
|
||
|
|
.filter_command::<handlers::Command>()
|
||
|
|
.endpoint(handlers::handle_command)
|
||
|
|
)
|
||
|
|
.branch(
|
||
|
|
dptree::endpoint(handlers::handle_message)
|
||
|
|
);
|
||
|
|
|
||
|
|
let mut dispatcher = Dispatcher::builder(bot.clone(), handler)
|
||
|
|
.dependencies(dptree::deps![db])
|
||
|
|
.enable_ctrlc_handler()
|
||
|
|
.build();
|
||
|
|
|
||
|
|
// Run dispatcher with shutdown signal
|
||
|
|
tokio::select! {
|
||
|
|
_ = dispatcher.dispatch() => {
|
||
|
|
tracing::info!("Telegram bot polling stopped");
|
||
|
|
}
|
||
|
|
_ = shutdown_rx => {
|
||
|
|
tracing::info!("Telegram bot received shutdown signal");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|