From 4fdabbecc41cadccd9388e5af2a39425b5aa9ff3 Mon Sep 17 00:00:00 2001 From: minneelyyyy Date: Tue, 10 Dec 2024 15:31:36 -0500 Subject: [PATCH] create and commit transaction at slightly smarter times --- src/commands/gambling/shop.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/gambling/shop.rs b/src/commands/gambling/shop.rs index 32bd164..59d48cd 100644 --- a/src/commands/gambling/shop.rs +++ b/src/commands/gambling/shop.rs @@ -49,9 +49,9 @@ pub async fn buy(ctx: Context<'_>, return Ok(()); } - let mut tx = ctx.data().database.begin().await?; - if let Some((price, &ref item)) = ITEMS.get(item.as_str()) { + let mut tx = ctx.data().database.begin().await?; + let author = ctx.author(); let balance = super::get_balance(author.id, &mut *tx).await?; @@ -69,9 +69,9 @@ pub async fn buy(ctx: Context<'_>, } super::change_balance(author.id, balance - total, &mut *tx).await?; + tx.commit().await?; ctx.reply(format!("You have purchased {count}x {}.", item.name)).await?; - tx.commit().await?; } else { ctx.reply(format!("The item {item} is not available in this shop.")).await?; }