Added bank information to .economy

This commit is contained in:
Kwoth
2022-05-05 23:12:49 +02:00
parent d80cbb4647
commit 5ed005211e
4 changed files with 16 additions and 5 deletions

View File

@@ -77,7 +77,7 @@ public partial class Gambling : GamblingModule<GamblingService>
[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<GamblingService>
.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

View File

@@ -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<EconomyResult> 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<BankUser>()
.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; }
}
}