Merge pull request #572 from teloxide/beautify-string-literals

Capture identifiers in format strings
This commit is contained in:
Hirrolot 2022-04-03 03:35:56 -07:00 committed by GitHub
commit 140141f6fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 15 additions and 15 deletions

View file

@ -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?;
}

View file

@ -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, .. }) => {

View file

@ -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?;

View file

@ -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?;
}

View file

@ -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)
}

View file

@ -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);

View file

@ -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(())
},

View file

@ -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?
}