Skip to content

Commit

Permalink
Use username is display message
Browse files Browse the repository at this point in the history
  • Loading branch information
will-lynas committed Oct 15, 2024
1 parent b887796 commit f9695dd
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -137,18 +138,26 @@ 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);
}

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(())
Expand Down

0 comments on commit f9695dd

Please sign in to comment.