move out command handler to separate function
This commit is contained in:
parent
5cadb2bd76
commit
d886a2459f
48
src/main.rs
48
src/main.rs
@ -56,29 +56,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.inspect(|u: Update| {
|
.inspect(|u: Update| {
|
||||||
eprintln!("{u:#?}"); // Print the update to the console with inspect
|
eprintln!("{u:#?}"); // Print the update to the console with inspect
|
||||||
})
|
})
|
||||||
.branch(
|
.branch(command_handler(config))
|
||||||
Update::filter_message()
|
|
||||||
.branch(
|
|
||||||
dptree::entry()
|
|
||||||
.filter_command::<UserCommands>()
|
|
||||||
.endpoint(user_command_handler),
|
|
||||||
)
|
|
||||||
.branch(
|
|
||||||
dptree::entry()
|
|
||||||
.filter_command::<SecretCommands>()
|
|
||||||
.map(move || config.admin_password.clone())
|
|
||||||
.endpoint(secret_command_handler),
|
|
||||||
)
|
|
||||||
.branch(
|
|
||||||
dptree::entry()
|
|
||||||
.filter_async(async |msg: Message, mut db: DB| {
|
|
||||||
let user = db.get_or_init_user(msg.from.unwrap().id.0 as i64).await;
|
|
||||||
user.is_admin
|
|
||||||
})
|
|
||||||
.filter_command::<AdminCommands>()
|
|
||||||
.endpoint(admin_command_handler),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.branch(Update::filter_message().endpoint(echo));
|
.branch(Update::filter_message().endpoint(echo));
|
||||||
|
|
||||||
Dispatcher::builder(bot, handler)
|
Dispatcher::builder(bot, handler)
|
||||||
@ -91,6 +69,30 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn command_handler(config: Config) -> Handler<'static, DependencyMap, Result<(), teloxide::RequestError>, teloxide::dispatching::DpHandlerDescription> {
|
||||||
|
Update::filter_message()
|
||||||
|
.branch(
|
||||||
|
dptree::entry()
|
||||||
|
.filter_command::<UserCommands>()
|
||||||
|
.endpoint(user_command_handler),
|
||||||
|
)
|
||||||
|
.branch(
|
||||||
|
dptree::entry()
|
||||||
|
.filter_command::<SecretCommands>()
|
||||||
|
.map(move || config.admin_password.clone())
|
||||||
|
.endpoint(secret_command_handler),
|
||||||
|
)
|
||||||
|
.branch(
|
||||||
|
dptree::entry()
|
||||||
|
.filter_async(async |msg: Message, mut db: DB| {
|
||||||
|
let user = db.get_or_init_user(msg.from.unwrap().id.0 as i64).await;
|
||||||
|
user.is_admin
|
||||||
|
})
|
||||||
|
.filter_command::<AdminCommands>()
|
||||||
|
.endpoint(admin_command_handler),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
async fn user_command_handler(
|
async fn user_command_handler(
|
||||||
mut db: DB,
|
mut db: DB,
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user