Trying to deal with Money weirdness. Probably going to move away from extension methods for this as it's fraught with issues when dealing with EF

This commit is contained in:
barelyprofessional
2025-09-10 20:18:48 -05:00
parent 13294b4d07
commit 958286a1ea
2 changed files with 16 additions and 12 deletions

View File

@@ -8,6 +8,7 @@ using KfChatDotNetBot.Services;
using KfChatDotNetBot.Settings;
using KfChatDotNetWsClient.Models.Events;
using Microsoft.EntityFrameworkCore;
using NLog;
namespace KfChatDotNetBot.Commands;
@@ -77,12 +78,17 @@ public class SendJuiceCommand : ICommand
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx)
{
var logger = LogManager.GetCurrentClassLogger();
await using var db = new ApplicationDbContext();
var gambler = await user.GetGamblerEntity(ct: ctx);
db.Attach(gambler!);
var targetUser = await db.Users.FirstOrDefaultAsync(u => u.KfId == int.Parse(arguments["user_id"].Value), ctx);
var amount = decimal.Parse(arguments["amount"].Value);
if (gambler!.Balance < amount)
if (gambler == null)
{
logger.Error($"Caught a null when looking up {user.KfUsername}");
return;
}
if (gambler.Balance < amount)
{
await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, you don't have enough money to juice this much.", true);
return;