From 03e12e87e4eba4230178e13a816d292494a54715 Mon Sep 17 00:00:00 2001 From: Brazman Date: Thu, 16 Feb 2023 14:29:02 -0600 Subject: [PATCH] Economy fixes - Made balances bottom out at 0, making negative balances impossible. - Fixed bug with users being able to gamble with money they don't have. --- SuperMachoBot/Commands/EconomyCommands.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/SuperMachoBot/Commands/EconomyCommands.cs b/SuperMachoBot/Commands/EconomyCommands.cs index 94dcf67..1117415 100644 --- a/SuperMachoBot/Commands/EconomyCommands.cs +++ b/SuperMachoBot/Commands/EconomyCommands.cs @@ -105,6 +105,11 @@ namespace SuperMachoBot.Commands string json = File.ReadAllText(jsonFilePath); var userDataDict = JsonConvert.DeserializeObject>(json); + if(data.money < 0) //Check to prevent balances from entering the negatives + { + data.money = 0; + } + if (userDataDict.ContainsKey(userid)) { UserData userData = userDataDict[userid]; @@ -191,10 +196,12 @@ namespace SuperMachoBot.Commands if(amount < 0) { await ctx.CreateResponseAsync($"Invalid amount!"); + return; } if(amount > entry.money) { await ctx.CreateResponseAsync($"Invalid amount!"); + return; } int result = rnd.Next(0, 2); //Could massively reduce the amount of lines below, but I want custom messages dependent on all the outcomes, so COPE. @@ -240,9 +247,11 @@ namespace SuperMachoBot.Commands if (amount <= 0) { await ctx.CreateResponseAsync($"Invalid amount! Try again!"); + return; } else if(entry.money < amount) { await ctx.CreateResponseAsync($"YOU CANNOT AFFORD! TRY AGAIN!"); + return; } switch (roll) { @@ -272,9 +281,9 @@ namespace SuperMachoBot.Commands EditEconomyEntry(ctx.User.Id, new UserData { money = entry.money + (long)money, lastDaily = entry.lastDaily }, ctx.Guild.Id); if(money < 0) { - await ctx.CreateResponseAsync($"{ctx.User.Username} lost {money}$!"); + await ctx.CreateResponseAsync($"{ctx.User.Username} lost {money}$ with multiplier {multiplier}!"); } - await ctx.CreateResponseAsync($"{ctx.User.Username} gained {money}!"); + await ctx.CreateResponseAsync($"{ctx.User.Username} gained {money}$ with multiplier {multiplier}!"); } [SlashCommand("Daily", "Claim your daily 100$!")]