diff --git a/README.md b/README.md index ed8251ac..f03246ad 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,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, |bot: Bot, msg: Message| async move { + bot.send_dice(msg.chat.id).await?; Ok(()) }) .await; @@ -143,20 +143,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? } }; @@ -223,13 +218,13 @@ async fn main() { .await; } -async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn start(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { bot.send_message(msg.chat.id, "Let's start! What's your full name?").await?; dialogue.update(State::ReceiveFullName).await?; Ok(()) } -async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn receive_full_name(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { match msg.text() { Some(text) => { bot.send_message(msg.chat.id, "How old are you?").await?; @@ -245,9 +240,9 @@ async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> Hand async fn receive_age( bot: Bot, - msg: Message, dialogue: MyDialogue, full_name: String, // Available from `State::ReceiveAge`. + msg: Message, ) -> HandlerResult { match msg.text().map(|text| text.parse::()) { Some(Ok(age)) => { @@ -264,14 +259,14 @@ async fn receive_age( async fn receive_location( bot: Bot, - msg: Message, dialogue: MyDialogue, (full_name, age): (String, u8), // Available from `State::ReceiveLocation`. + msg: Message, ) -> 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/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..84b12ae1 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( + bot: Bot, + msg: Message, + 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?; } } } @@ -81,8 +85,8 @@ async fn message_handler(m: Message, bot: Bot, me: Me) -> Result<(), Box Result<(), Box> { let choose_debian_version = InlineQueryResultArticle::new( "0", @@ -101,7 +105,7 @@ async fn inline_query_handler( /// /// **IMPORTANT**: do not send privacy-sensitive data this way!!! /// Anyone can read data stored in the callback button. -async fn callback_handler(q: CallbackQuery, bot: Bot) -> Result<(), Box> { +async fn callback_handler(bot: Bot, q: CallbackQuery) -> Result<(), Box> { if let Some(version) = q.data { let text = format!("You chose: {version}"); 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/db_remember.rs b/examples/db_remember.rs index f1e5e4c9..c102cbe2 100644 --- a/examples/db_remember.rs +++ b/examples/db_remember.rs @@ -60,7 +60,7 @@ async fn main() { .await; } -async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn start(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { match msg.text().map(|text| text.parse::()) { Some(Ok(n)) => { dialogue.update(State::GotNumber(n)).await?; @@ -80,9 +80,9 @@ async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { async fn got_number( bot: Bot, - msg: Message, dialogue: MyDialogue, - num: i32, + num: i32, // Available from `State::GotNumber`. + msg: Message, cmd: Command, ) -> HandlerResult { match cmd { diff --git a/examples/dialogue.rs b/examples/dialogue.rs index 5fc54b3b..72ea6b2e 100644 --- a/examples/dialogue.rs +++ b/examples/dialogue.rs @@ -57,13 +57,13 @@ async fn main() { .await; } -async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn start(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { bot.send_message(msg.chat.id, "Let's start! What's your full name?").await?; dialogue.update(State::ReceiveFullName).await?; Ok(()) } -async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn receive_full_name(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { match msg.text() { Some(text) => { bot.send_message(msg.chat.id, "How old are you?").await?; @@ -79,9 +79,9 @@ async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> Hand async fn receive_age( bot: Bot, - msg: Message, dialogue: MyDialogue, full_name: String, // Available from `State::ReceiveAge`. + msg: Message, ) -> HandlerResult { match msg.text().map(|text| text.parse::()) { Some(Ok(age)) => { @@ -98,14 +98,14 @@ async fn receive_age( async fn receive_location( bot: Bot, - msg: Message, dialogue: MyDialogue, (full_name, age): (String, u8), // Available from `State::ReceiveLocation`. + msg: Message, ) -> 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/dispatching_features.rs b/examples/dispatching_features.rs index 1f34dc1d..e8ed5e16 100644 --- a/examples/dispatching_features.rs +++ b/examples/dispatching_features.rs @@ -33,7 +33,7 @@ async fn main() { ) .branch( // Filter a maintainer by a used ID. - dptree::filter(|msg: Message, cfg: ConfigParameters| { + dptree::filter(|cfg: ConfigParameters, msg: Message| { msg.from().map(|user| user.id == cfg.bot_maintainer).unwrap_or_default() }) .filter_command::() @@ -62,7 +62,7 @@ async fn main() { .branch( // There are some extension filtering functions on `Message`. The following filter will // filter only messages with dices. - Message::filter_dice().endpoint(|msg: Message, dice: Dice, bot: Bot| async move { + Message::filter_dice().endpoint(|bot: Bot, msg: Message, dice: Dice| async move { bot.send_message(msg.chat.id, format!("Dice value: {}", dice.value)) .reply_to_message_id(msg.id) .await?; @@ -114,11 +114,11 @@ enum MaintainerCommands { } async fn simple_commands_handler( - msg: Message, - bot: Bot, - cmd: SimpleCommand, cfg: ConfigParameters, + bot: Bot, me: teloxide::types::Me, + msg: Message, + cmd: SimpleCommand, ) -> Result<(), teloxide::RequestError> { let text = match cmd { SimpleCommand::Help => { diff --git a/examples/heroku_ping_pong.rs b/examples/heroku_ping_pong.rs index 1c104eb8..6fe50847 100644 --- a/examples/heroku_ping_pong.rs +++ b/examples/heroku_ping_pong.rs @@ -47,7 +47,7 @@ async fn main() { teloxide::repl_with_listener( bot, - |msg: Message, bot: Bot| async move { + |bot: Bot, msg: Message| async move { bot.send_message(msg.chat.id, "pong").await?; Ok(()) }, diff --git a/examples/inline.rs b/examples/inline.rs index f9536b02..444e7858 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 { + |bot: Bot, q: InlineQuery| 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/ngrok_ping_pong.rs b/examples/ngrok_ping_pong.rs index 21486810..3ea157ed 100644 --- a/examples/ngrok_ping_pong.rs +++ b/examples/ngrok_ping_pong.rs @@ -18,7 +18,7 @@ async fn main() { teloxide::repl_with_listener( bot, - |msg: Message, bot: Bot| async move { + |bot: Bot, msg: Message| async move { bot.send_message(msg.chat.id, "pong").await?; Ok(()) }, diff --git a/examples/purchase.rs b/examples/purchase.rs index 79b4e81c..89ec5654 100644 --- a/examples/purchase.rs +++ b/examples/purchase.rs @@ -83,7 +83,7 @@ fn schema() -> UpdateHandler> .branch(callback_query_handler) } -async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn start(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { bot.send_message(msg.chat.id, "Let's start! What's your full name?").await?; dialogue.update(State::ReceiveFullName).await?; Ok(()) @@ -94,7 +94,7 @@ async fn help(bot: Bot, msg: Message) -> HandlerResult { Ok(()) } -async fn cancel(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn cancel(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { bot.send_message(msg.chat.id, "Cancelling the dialogue.").await?; dialogue.exit().await?; Ok(()) @@ -106,7 +106,7 @@ async fn invalid_state(bot: Bot, msg: Message) -> HandlerResult { Ok(()) } -async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +async fn receive_full_name(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { match msg.text().map(ToOwned::to_owned) { Some(full_name) => { let products = ["Apple", "Banana", "Orange", "Potato"] @@ -127,9 +127,9 @@ async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> Hand async fn receive_product_selection( bot: Bot, - q: CallbackQuery, dialogue: MyDialogue, - full_name: String, + full_name: String, // Available from `State::ReceiveProductChoice`. + q: CallbackQuery, ) -> HandlerResult { if let Some(product) = &q.data { bot.send_message( diff --git a/examples/shared_state.rs b/examples/shared_state.rs index 4caf9995..bb8ef8fa 100644 --- a/examples/shared_state.rs +++ b/examples/shared_state.rs @@ -16,7 +16,7 @@ async fn main() { let messages_total = Arc::new(AtomicU64::new(0)); let handler = Update::filter_message().endpoint( - |msg: Message, bot: Bot, messages_total: Arc| async move { + |bot: Bot, messages_total: Arc, msg: Message| async move { let previous = messages_total.fetch_add(1, Ordering::Relaxed); bot.send_message(msg.chat.id, format!("I received {previous} messages in total.")) .await?; diff --git a/examples/throw_dice.rs b/examples/throw_dice.rs index 0de45aec..71f850a4 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, |bot: Bot, msg: Message| async move { + bot.send_dice(msg.chat.id).await?; Ok(()) }) .await; diff --git a/src/dispatching.rs b/src/dispatching.rs index 23a03268..c19b2b93 100644 --- a/src/dispatching.rs +++ b/src/dispatching.rs @@ -113,26 +113,26 @@ //! type MyDialogue = Dialogue>; //! type HandlerResult = Result<(), Box>; //! -//! async fn start(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +//! async fn start(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { //! todo!() //! } //! async fn help(bot: Bot, msg: Message) -> HandlerResult { //! todo!() //! } -//! async fn cancel(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +//! async fn cancel(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { //! todo!() //! } //! async fn invalid_state(bot: Bot, msg: Message) -> HandlerResult { //! todo!() //! } -//! async fn receive_full_name(bot: Bot, msg: Message, dialogue: MyDialogue) -> HandlerResult { +//! async fn receive_full_name(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { //! todo!() //! } //! async fn receive_product_selection( //! bot: Bot, -//! q: CallbackQuery, //! dialogue: MyDialogue, -//! full_name: String, +//! full_name: String, // Available from `State::ReceiveProductChoice`. +//! q: CallbackQuery, //! ) -> HandlerResult { //! todo!() //! } diff --git a/src/dispatching/dialogue.rs b/src/dispatching/dialogue.rs index 6f9aa824..c8d27896 100644 --- a/src/dispatching/dialogue.rs +++ b/src/dispatching/dialogue.rs @@ -39,9 +39,9 @@ //! # #[derive(Clone, Debug)] enum State { ReceiveLocation { full_name: String, age: u8 } } //! async fn receive_age( //! bot: Bot, -//! msg: Message, //! dialogue: MyDialogue, //! full_name: String, // Available from `State::ReceiveAge`. +//! msg: Message, //! ) -> HandlerResult { //! match msg.text().map(|text| text.parse::()) { //! Some(Ok(age)) => { @@ -71,9 +71,9 @@ //! # #[derive(Clone, Debug)] enum State {} //! async fn receive_location( //! bot: Bot, -//! msg: Message, //! dialogue: MyDialogue, //! (full_name, age): (String, u8), // Available from `State::ReceiveLocation`. +//! msg: Message, //! ) -> HandlerResult { //! match msg.text() { //! Some(location) => { diff --git a/src/lib.rs b/src/lib.rs index b262d957..80237a9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,8 +15,8 @@ //! //! let bot = Bot::from_env(); //! -//! teloxide::repl(bot, |message: Message, bot: Bot| async move { -//! bot.send_dice(message.chat.id).await?; +//! teloxide::repl(bot, |bot: Bot, msg: Message| async move { +//! bot.send_dice(msg.chat.id).await?; //! Ok(()) //! }) //! .await;