mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Merge pull request #572 from teloxide/beautify-string-literals
Capture identifiers in format strings
This commit is contained in:
commit
140141f6fc
8 changed files with 15 additions and 15 deletions
|
@ -160,12 +160,12 @@ async fn answer(
|
|||
bot.send_message(message.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(message.chat.id, format!("Your username is @{username}.")).await?
|
||||
}
|
||||
Command::UsernameAndAge { username, age } => {
|
||||
bot.send_message(
|
||||
message.chat.id,
|
||||
format!("Your username is @{} and age is {}.", username, age),
|
||||
format!("Your username is @{username} and age is {age}."),
|
||||
)
|
||||
.await?
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ async fn receive_age(
|
|||
bot: AutoSend<Bot>,
|
||||
msg: Message,
|
||||
dialogue: MyDialogue,
|
||||
(full_name,): (String,), // Available from `State::ReceiveAge`.
|
||||
full_name: String, // Available from `State::ReceiveAge`.
|
||||
) -> HandlerResult {
|
||||
match msg.text().map(|text| text.parse::<u8>()) {
|
||||
Some(Ok(age)) => {
|
||||
|
@ -288,7 +288,7 @@ async fn receive_location(
|
|||
) -> HandlerResult {
|
||||
match msg.text() {
|
||||
Some(location) => {
|
||||
let message = format!("Full name: {}\nAge: {}\nLocation: {}", full_name, age, location);
|
||||
let message = format!("Full name: {full_name}\nAge: {age}\nLocation: {location}");
|
||||
bot.send_message(msg.chat.id, message).await?;
|
||||
dialogue.exit().await?;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ async fn callback_handler(
|
|||
bot: AutoSend<Bot>,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
if let Some(version) = q.data {
|
||||
let text = format!("You chose: {}", version);
|
||||
let text = format!("You chose: {version}");
|
||||
|
||||
match q.message {
|
||||
Some(Message { id, chat, .. }) => {
|
||||
|
|
|
@ -71,7 +71,7 @@ async fn start(bot: AutoSend<Bot>, msg: Message, dialogue: MyDialogue) -> Handle
|
|||
dialogue.update(State::GotNumber(n)).await?;
|
||||
bot.send_message(
|
||||
msg.chat.id,
|
||||
format!("Remembered number {}. Now use /get or /reset.", n),
|
||||
format!("Remembered number {n}. Now use /get or /reset."),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ async fn got_number(
|
|||
) -> HandlerResult {
|
||||
match cmd {
|
||||
Command::Get => {
|
||||
bot.send_message(msg.chat.id, format!("Here is your number: {}.", num)).await?;
|
||||
bot.send_message(msg.chat.id, format!("Here is your number: {num}.")).await?;
|
||||
}
|
||||
Command::Reset => {
|
||||
dialogue.reset().await?;
|
||||
|
|
|
@ -109,7 +109,7 @@ async fn receive_location(
|
|||
) -> HandlerResult {
|
||||
match msg.text() {
|
||||
Some(location) => {
|
||||
let message = format!("Full name: {}\nAge: {}\nLocation: {}", full_name, age, location);
|
||||
let message = format!("Full name: {full_name}\nAge: {age}\nLocation: {location}");
|
||||
bot.send_message(msg.chat.id, message).await?;
|
||||
dialogue.exit().await?;
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ async fn simple_commands_handler(
|
|||
if msg.from().unwrap().id == cfg.bot_maintainer {
|
||||
"Maintainer is you!".into()
|
||||
} else if let Some(username) = cfg.maintainer_username {
|
||||
format!("Maintainer is @{}", username)
|
||||
format!("Maintainer is @{username}")
|
||||
} else {
|
||||
format!("Maintainer ID is {}", cfg.bot_maintainer)
|
||||
}
|
||||
|
|
|
@ -66,8 +66,8 @@ pub async fn webhook(bot: AutoSend<Bot>) -> impl update_listeners::UpdateListene
|
|||
.expect("PORT value to be integer");
|
||||
// Heroku host example .: "heroku-ping-pong-bot.herokuapp.com"
|
||||
let host = env::var("HOST").expect("have HOST env variable");
|
||||
let path = format!("bot{}", teloxide_token);
|
||||
let url = Url::parse(&format!("https://{}/{}", host, path)).unwrap();
|
||||
let path = format!("bot{teloxide_token}");
|
||||
let url = Url::parse(&format!("https://{host}/{path}")).unwrap();
|
||||
|
||||
bot.set_webhook(url).await.expect("Cannot setup a webhook");
|
||||
|
||||
|
@ -85,7 +85,7 @@ pub async fn webhook(bot: AutoSend<Bot>) -> impl update_listeners::UpdateListene
|
|||
|
||||
let (stop_token, stop_flag) = AsyncStopToken::new_pair();
|
||||
|
||||
let addr = format!("0.0.0.0:{}", port).parse::<SocketAddr>().unwrap();
|
||||
let addr = format!("0.0.0.0:{port}").parse::<SocketAddr>().unwrap();
|
||||
let server = warp::serve(server);
|
||||
let (_addr, fut) = server.bind_with_graceful_shutdown(addr, stop_flag);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ async fn main() {
|
|||
let handler = Update::filter_message().branch(dptree::endpoint(
|
||||
|msg: Message, bot: AutoSend<Bot>| async move {
|
||||
let previous = MESSAGES_TOTAL.fetch_add(1, Ordering::Relaxed);
|
||||
bot.send_message(msg.chat.id, format!("I received {} messages in total.", previous))
|
||||
bot.send_message(msg.chat.id, format!("I received {previous} messages in total."))
|
||||
.await?;
|
||||
respond(())
|
||||
},
|
||||
|
|
|
@ -33,12 +33,12 @@ async fn answer(
|
|||
bot.send_message(message.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(message.chat.id, format!("Your username is @{username}.")).await?
|
||||
}
|
||||
Command::UsernameAndAge { username, age } => {
|
||||
bot.send_message(
|
||||
message.chat.id,
|
||||
format!("Your username is @{} and age is {}.", username, age),
|
||||
format!("Your username is @{username} and age is {age}."),
|
||||
)
|
||||
.await?
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue