From f9695dd991c1a2af1bec20da2ec8b7381ed3c683 Mon Sep 17 00:00:00 2001 From: Will Lynas <43895423+will-lynas@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:27:22 +0100 Subject: [PATCH] Use username is display message --- src/main.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 17de5e7..61e9f51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,8 +126,9 @@ async fn help(bot: Bot, msg: Message) -> HandlerResult { async fn display(bot: Bot, msg: Message, pool: SqlitePool) -> HandlerResult { let chat_id = msg.chat.id.0; + let db = DB::new(&pool); - let transactions = DB::new(&pool).get_transactions(chat_id).await; + let transactions = db.get_transactions(chat_id).await; if transactions.is_empty() { bot.send_message(msg.chat.id, "No transactions found") @@ -137,10 +138,15 @@ async fn display(bot: Bot, msg: Message, pool: SqlitePool) -> HandlerResult { let mut lines = Vec::new(); for tx in transactions { + let username = db + .get_username(tx.user_id) + .await + .unwrap_or_else(|| tx.user_id.to_string()); let line = format!( - "🏷️ {}\t 💰 {}\t 🥷{}", - tx.title, - format_pounds(tx.amount), + "🏷️ {}\t 💰 {}\t 🥷 [{}](tg://user?id={})", + markdown::escape(&tx.title), + markdown::escape(&format_pounds(tx.amount)), + markdown::escape(&username), tx.user_id ); lines.push(line); @@ -148,7 +154,10 @@ async fn display(bot: Bot, msg: Message, pool: SqlitePool) -> HandlerResult { let response = lines.join("\n"); - bot.send_message(msg.chat.id, response).await.unwrap(); + bot.send_message(msg.chat.id, response) + .parse_mode(MarkdownV2) + .await + .unwrap(); } Ok(())