mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-10-23 16:59:08 +00:00
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use teloxide::{Bot, prelude::*};
|
|
use tokio::sync::oneshot;
|
|
|
|
use crate::database::DatabaseManager;
|
|
use crate::config::AppConfig;
|
|
use super::handlers::{self, Command};
|
|
|
|
/// Run the bot polling loop
|
|
pub async fn run_polling(
|
|
bot: Bot,
|
|
db: DatabaseManager,
|
|
app_config: AppConfig,
|
|
mut shutdown_rx: oneshot::Receiver<()>,
|
|
) {
|
|
tracing::info!("Starting Telegram bot polling...");
|
|
|
|
let handler = dptree::entry()
|
|
.branch(
|
|
Update::filter_message()
|
|
.branch(
|
|
dptree::entry()
|
|
.filter_command::<Command>()
|
|
.endpoint(handlers::handle_command)
|
|
)
|
|
.branch(
|
|
dptree::endpoint(handlers::handle_message)
|
|
)
|
|
)
|
|
.branch(
|
|
Update::filter_callback_query()
|
|
.endpoint(handlers::handle_callback_query)
|
|
);
|
|
|
|
let mut dispatcher = Dispatcher::builder(bot.clone(), handler)
|
|
.dependencies(dptree::deps![db, app_config])
|
|
.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");
|
|
}
|
|
}
|
|
} |