use a database :D

This commit is contained in:
2024-12-07 00:21:52 -05:00
parent 9fd85e38fb
commit 500c6a6eee
8 changed files with 112 additions and 65 deletions

View File

@@ -1,32 +1,32 @@
use crate::common::{Context, Error};
use super::get_user_wealth_mut;
/// Put forward an amount of tokens to either lose or earn
#[poise::command(slash_command, prefix_command)]
pub async fn wager(
ctx: Context<'_>,
#[min = 1]
amount: usize) -> Result<(), Error>
amount: i32) -> Result<(), Error>
{
let mut users = ctx.data().users.lock().await;
let data = ctx.data();
let mut wealth = super::get_balance(ctx.author().id, &data).await?;
let wealth = get_user_wealth_mut(&mut users, ctx.author().id);
if *wealth < amount {
if wealth < amount {
ctx.reply(format!("You do not have enough tokens (**{}**) to wager this amount.",
*wealth)).await?;
wealth)).await?;
return Ok(());
}
if rand::random() {
*wealth += amount;
wealth += amount;
ctx.reply(format!("You just gained **{}** token(s)! You now have **{}**.",
amount, *wealth)).await?;
amount, wealth)).await?;
} else {
*wealth -= amount;
wealth -= amount;
ctx.reply(format!("You've lost **{}** token(s), you now have **{}**.",
amount, *wealth)).await?;
amount, wealth)).await?;
}
super::change_balance(ctx.author().id, wealth, &data).await?;
Ok(())
}