From d3d7cc2fa95258926d6311899f11f09290e2b0c4 Mon Sep 17 00:00:00 2001 From: Hirrolot Date: Mon, 3 Oct 2022 17:07:38 +0600 Subject: [PATCH] Use same identifiers across the examples Former-commit-id: a137b41ab27eed2db64737f099f606cb829fceb3 --- examples/admin.rs | 4 ++-- examples/buttons.rs | 14 +++++++++----- examples/command.rs | 17 ++++++----------- examples/dialogue.rs | 4 ++-- examples/inline.rs | 8 ++++---- examples/throw_dice.rs | 4 ++-- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/examples/admin.rs b/examples/admin.rs index a9d800e6..0a810d31 100644 --- a/examples/admin.rs +++ b/examples/admin.rs @@ -63,8 +63,8 @@ async fn main() { teloxide::commands_repl(bot, action, Command::ty()).await; } -async fn action(bot: Bot, msg: Message, command: Command) -> ResponseResult<()> { - match command { +async fn action(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> { + match cmd { Command::Help => { bot.send_message(msg.chat.id, Command::descriptions().to_string()).await?; } diff --git a/examples/buttons.rs b/examples/buttons.rs index f3bf3cba..40544197 100644 --- a/examples/buttons.rs +++ b/examples/buttons.rs @@ -58,21 +58,25 @@ fn make_keyboard() -> InlineKeyboardMarkup { /// Parse the text wrote on Telegram and check if that text is a valid command /// or not, then match the command. If the command is `/start` it writes a /// markup with the `InlineKeyboardMarkup`. -async fn message_handler(m: Message, bot: Bot, me: Me) -> Result<(), Box> { - if let Some(text) = m.text() { +async fn message_handler( + msg: Message, + bot: Bot, + me: Me, +) -> Result<(), Box> { + if let Some(text) = msg.text() { match BotCommands::parse(text, me.username()) { Ok(Command::Help) => { // Just send the description of all commands. - bot.send_message(m.chat.id, Command::descriptions().to_string()).await?; + bot.send_message(msg.chat.id, Command::descriptions().to_string()).await?; } Ok(Command::Start) => { // Create a list of buttons and send them. let keyboard = make_keyboard(); - bot.send_message(m.chat.id, "Debian versions:").reply_markup(keyboard).await?; + bot.send_message(msg.chat.id, "Debian versions:").reply_markup(keyboard).await?; } Err(_) => { - bot.send_message(m.chat.id, "Command not found!").await?; + bot.send_message(msg.chat.id, "Command not found!").await?; } } } diff --git a/examples/command.rs b/examples/command.rs index d0f671ec..901d3866 100644 --- a/examples/command.rs +++ b/examples/command.rs @@ -21,20 +21,15 @@ enum Command { UsernameAndAge { username: String, age: u8 }, } -async fn answer(bot: Bot, message: Message, command: Command) -> ResponseResult<()> { - match command { - Command::Help => { - bot.send_message(message.chat.id, Command::descriptions().to_string()).await? - } +async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> { + match cmd { + Command::Help => bot.send_message(msg.chat.id, Command::descriptions().to_string()).await?, Command::Username(username) => { - bot.send_message(message.chat.id, format!("Your username is @{username}.")).await? + bot.send_message(msg.chat.id, format!("Your username is @{username}.")).await? } Command::UsernameAndAge { username, age } => { - bot.send_message( - message.chat.id, - format!("Your username is @{username} and age is {age}."), - ) - .await? + bot.send_message(msg.chat.id, format!("Your username is @{username} and age is {age}.")) + .await? } }; diff --git a/examples/dialogue.rs b/examples/dialogue.rs index 5fc54b3b..a6180349 100644 --- a/examples/dialogue.rs +++ b/examples/dialogue.rs @@ -104,8 +104,8 @@ async fn receive_location( ) -> HandlerResult { match msg.text() { Some(location) => { - let message = format!("Full name: {full_name}\nAge: {age}\nLocation: {location}"); - bot.send_message(msg.chat.id, message).await?; + let report = format!("Full name: {full_name}\nAge: {age}\nLocation: {location}"); + bot.send_message(msg.chat.id, report).await?; dialogue.exit().await?; } None => { diff --git a/examples/inline.rs b/examples/inline.rs index f9536b02..819c7336 100644 --- a/examples/inline.rs +++ b/examples/inline.rs @@ -14,7 +14,7 @@ async fn main() { let bot = Bot::from_env(); let handler = Update::filter_inline_query().branch(dptree::endpoint( - |query: InlineQuery, bot: Bot| async move { + |q: InlineQuery, bot: Bot| async move { // First, create your actual response let google_search = InlineQueryResultArticle::new( // Each item needs a unique ID, as well as the response container for the @@ -26,7 +26,7 @@ async fn main() { // What message will be sent when clicked/tapped InputMessageContent::Text(InputMessageContentText::new(format!( "https://www.google.com/search?q={}", - query.query, + q.query, ))), ); // While constructing them from the struct itself is possible, it is preferred @@ -38,7 +38,7 @@ async fn main() { "DuckDuckGo Search".to_string(), InputMessageContent::Text(InputMessageContentText::new(format!( "https://duckduckgo.com/?q={}", - query.query + q.query ))), ) .description("DuckDuckGo Search") @@ -52,7 +52,7 @@ async fn main() { // Send it off! One thing to note -- the ID we use here must be of the query // we're responding to. - let response = bot.answer_inline_query(&query.id, results).send().await; + let response = bot.answer_inline_query(&q.id, results).send().await; if let Err(err) = response { log::error!("Error in handler: {:?}", err); } diff --git a/examples/throw_dice.rs b/examples/throw_dice.rs index 0de45aec..b0503e19 100644 --- a/examples/throw_dice.rs +++ b/examples/throw_dice.rs @@ -9,8 +9,8 @@ async fn main() { let bot = Bot::from_env(); - teloxide::repl(bot, |message: Message, bot: Bot| async move { - bot.send_dice(message.chat.id).await?; + teloxide::repl(bot, |msg: Message, bot: Bot| async move { + bot.send_dice(msg.chat.id).await?; Ok(()) }) .await;