From 5ed005211eab93a548c612ab2622c98f5c13e43c Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 5 May 2022 23:12:49 +0200 Subject: [PATCH] Added bank information to .economy --- CHANGELOG.md | 3 ++- src/NadekoBot/Modules/Gambling/Gambling.cs | 5 +++-- src/NadekoBot/Modules/Gambling/GamblingService.cs | 12 ++++++++++-- .../data/strings/responses/responses.en-US.json | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39666618a..f05b7d255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog. ### Added - Added support for embed arrays in commands such as .say, .greet, .bye, etc... - - Website to create them is live at eb2.nadeko.bot (it will soon be replacing eb.nadeko.bot) + - Website to create them is live at eb.nadeko.bot (old one is moved to oldeb.nadeko.bot) - Embed arrays don't have a plainText property (it's renamed to 'content') - Embed arrays use color hex values instead of an integer - Old embed format will still work @@ -21,6 +21,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog. - Added `.h ` - Using this command will list all commands in the specified group - Atm only .bank is a proper group (`.h bank`) +- Added "Bank Accounts" entry to `.economy` ### Changed diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index a9cd4c7ec..30fe72937 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -77,7 +77,7 @@ public partial class Gambling : GamblingModule [Cmd] public async partial Task Economy() { - var ec = _service.GetEconomy(); + var ec = await _service.GetEconomyAsync(); decimal onePercent = 0; // This stops the top 1% from owning more than 100% of the money @@ -94,7 +94,8 @@ public partial class Gambling : GamblingModule .AddField(GetText(strs.currency_planted), N(ec.Planted)) .AddField(GetText(strs.owned_waifus_total), N(ec.Waifus)) .AddField(GetText(strs.bot_currency), N(ec.Bot)) - .AddField(GetText(strs.total), N(ec.Cash + ec.Planted + ec.Waifus)) + .AddField(GetText(strs.bank_accounts), N(ec.Bank)) + .AddField(GetText(strs.total), N(ec.Cash + ec.Planted + ec.Waifus + ec.Bank)) .WithOkColor(); // ec.Cash already contains ec.Bot as it's the total of all values in the CurrencyAmount column of the DiscordUser table diff --git a/src/NadekoBot/Modules/Gambling/GamblingService.cs b/src/NadekoBot/Modules/Gambling/GamblingService.cs index 729e4535a..f09385bc6 100644 --- a/src/NadekoBot/Modules/Gambling/GamblingService.cs +++ b/src/NadekoBot/Modules/Gambling/GamblingService.cs @@ -1,8 +1,11 @@ #nullable disable using LinqToDB; +using LinqToDB.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Db; +using NadekoBot.Db.Models; +using NadekoBot.Migrations; using NadekoBot.Modules.Gambling.Common; using NadekoBot.Modules.Gambling.Common.Connect4; using NadekoBot.Modules.Gambling.Common.Slot; @@ -158,7 +161,7 @@ public class GamblingService : INService, IReadyExecutor return toReturn; } - public EconomyResult GetEconomy() + public async Task GetEconomyAsync() { if (_cache.TryGetEconomy(out var data)) { @@ -173,6 +176,7 @@ public class GamblingService : INService, IReadyExecutor decimal onePercent; decimal planted; decimal waifus; + decimal bank; long bot; using (var uow = _db.GetDbContext()) @@ -182,6 +186,8 @@ public class GamblingService : INService, IReadyExecutor planted = uow.PlantedCurrency.AsQueryable().Sum(x => x.Amount); waifus = uow.WaifuInfo.GetTotalValue(); bot = uow.DiscordUser.GetUserCurrency(_client.CurrentUser.Id); + bank = await uow.GetTable() + .SumAsyncLinqToDB(x => x.Balance); } var result = new EconomyResult @@ -190,7 +196,8 @@ public class GamblingService : INService, IReadyExecutor Planted = planted, Bot = bot, Waifus = waifus, - OnePercent = onePercent + OnePercent = onePercent, + Bank = bank }; _cache.SetEconomy(JsonConvert.SerializeObject(result)); @@ -207,6 +214,7 @@ public class GamblingService : INService, IReadyExecutor public decimal Planted { get; set; } public decimal Waifus { get; set; } public decimal OnePercent { get; set; } + public decimal Bank { get; set; } public long Bot { get; set; } } } \ No newline at end of file diff --git a/src/NadekoBot/data/strings/responses/responses.en-US.json b/src/NadekoBot/data/strings/responses/responses.en-US.json index b7726309d..9b5092d58 100644 --- a/src/NadekoBot/data/strings/responses/responses.en-US.json +++ b/src/NadekoBot/data/strings/responses/responses.en-US.json @@ -939,6 +939,7 @@ "owned_waifus_total": "Total value of owned waifus", "bot_currency": "Currency owned by the bot", "total": "Total", + "bank_accounts": "Bank Accounts", "no_invites": "No invites on this page.", "invite_deleted": "Invite {0} has been deleted.", "group_name_added": "Group #{0} now has a name: {1}",