From 7777aadf6aad400e3b020e379add3f7397a9ccdd Mon Sep 17 00:00:00 2001 From: Akulij Date: Thu, 3 Apr 2025 22:06:58 +0900 Subject: [PATCH] create edit msg handler --- src/main.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main.rs b/src/main.rs index b5a6397..999cadc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,6 +56,14 @@ async fn main() -> Result<(), Box> { eprintln!("{u:#?}"); // Print the update to the console with inspect }) .branch(command_handler(config)) + .branch(Update::filter_message() + .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(|msg: Message| msg == "edit") + .endpoint(edit_msg_handler) + ) .branch(Update::filter_message().endpoint(echo)); Dispatcher::builder(bot, handler) @@ -68,6 +76,19 @@ async fn main() -> Result<(), Box> { Ok(()) } +async fn edit_msg_handler(bot: Bot, msg: Message) -> Result<(), teloxide::RequestError> { + match msg.reply_to_message() { + Some(replied) => { + let msgid = replied.id; + // look for message in db and set text + }, + None => { + bot.send_message(msg.chat.id, "You have to reply to message to edit it").await?; + } + }; + Ok(()) +} + fn command_handler(config: Config) -> Handler<'static, DependencyMap, Result<(), teloxide::RequestError>, teloxide::dispatching::DpHandlerDescription> { Update::filter_message() .branch(