move out command handler to separate function

This commit is contained in:
Akulij 2025-04-03 05:03:04 +09:00
parent 5cadb2bd76
commit d886a2459f

View File

@ -56,7 +56,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.inspect(|u: Update| {
eprintln!("{u:#?}"); // Print the update to the console with inspect
})
.branch(
.branch(command_handler(config))
.branch(Update::filter_message().endpoint(echo));
Dispatcher::builder(bot, handler)
.dependencies(dptree::deps![db])
.enable_ctrlc_handler()
.build()
.dispatch()
.await;
Ok(())
}
fn command_handler(config: Config) -> Handler<'static, DependencyMap, Result<(), teloxide::RequestError>, teloxide::dispatching::DpHandlerDescription> {
Update::filter_message()
.branch(
dptree::entry()
@ -77,18 +90,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
})
.filter_command::<AdminCommands>()
.endpoint(admin_command_handler),
),
)
.branch(Update::filter_message().endpoint(echo));
Dispatcher::builder(bot, handler)
.dependencies(dptree::deps![db])
.enable_ctrlc_handler()
.build()
.dispatch()
.await;
Ok(())
}
async fn user_command_handler(