From e99434f5dfa837f0439e723f64f1f166a467604b Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sun, 16 Nov 2025 00:45:41 -0600 Subject: [PATCH] Refactored and corrected compiler warnings on Keno and Planes --- .../Commands/Kasino/KenoCommand.cs | 11 +++- .../Commands/Kasino/PlanesCommand.cs | 57 ++++++++----------- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/KfChatDotNetBot/Commands/Kasino/KenoCommand.cs b/KfChatDotNetBot/Commands/Kasino/KenoCommand.cs index 928161b..0547baa 100644 --- a/KfChatDotNetBot/Commands/Kasino/KenoCommand.cs +++ b/KfChatDotNetBot/Commands/Kasino/KenoCommand.cs @@ -34,7 +34,7 @@ public class KenoCommand : ICommand private const string MatchRevealDisplay = "💠"; private const string BlankSpaceDisplay = "⬛"; - private SentMessageTrackerModel _kenoTable; + private SentMessageTrackerModel? _kenoTable; public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) @@ -97,7 +97,7 @@ public class KenoCommand : ICommand await botInstance.SendChatMessageAsync( $"{user.FormatUsername()}, you [color={colors[BuiltIn.Keys.KiwiFarmsRedColor].Value}]lost {await wager.FormatKasinoCurrencyAsync()}[/color]. Your balance is now: {await newBalance.FormatKasinoCurrencyAsync()}.", true, autoDeleteAfter: cleanupDelay); - botInstance.ScheduleMessageAutoDelete(_kenoTable, cleanupDelay); + botInstance.ScheduleMessageAutoDelete(_kenoTable ?? throw new Exception("Cannot clean up _kenoTable as it's null"), cleanupDelay); return; } @@ -109,7 +109,7 @@ public class KenoCommand : ICommand await botInstance.SendChatMessageAsync( $"{user.FormatUsername()}, you [color={colors[BuiltIn.Keys.KiwiFarmsGreenColor].Value}]won {await win.FormatKasinoCurrencyAsync()} with a {payoutMulti}x multi![/color]. Your balance is now: {await newBalance.FormatKasinoCurrencyAsync()}.", true, autoDeleteAfter: cleanupDelay); - botInstance.ScheduleMessageAutoDelete(_kenoTable, cleanupDelay); + botInstance.ScheduleMessageAutoDelete(_kenoTable ?? throw new Exception("Cannot clean up _kenotable as it's null"), cleanupDelay); } private async Task AnimatedDisplayTable(List playerNumbers, List casinoNumbers, List matches, ChatBot botInstance) @@ -141,6 +141,11 @@ public class KenoCommand : ICommand await Task.Delay(100); } + if (_kenoTable.ChatMessageId == null) + { + throw new Exception($"_kenoTable chat message ID never got populated. Tracker status is: {_kenoTable?.Status}"); + } + var frameDelay = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.KasinoKenoFrameDelay)).ToType(); //FIRST FRAME 11111111111111111111111111111 for (var frame = 0; frame < 10; frame++) //1 frame per casino number diff --git a/KfChatDotNetBot/Commands/Kasino/PlanesCommand.cs b/KfChatDotNetBot/Commands/Kasino/PlanesCommand.cs index b37bc69..725490b 100644 --- a/KfChatDotNetBot/Commands/Kasino/PlanesCommand.cs +++ b/KfChatDotNetBot/Commands/Kasino/PlanesCommand.cs @@ -39,8 +39,8 @@ public class Planes : ICommand private const string Water = "🌊"; private const string Air = "\u2B1C"; // White square private const string BlankSpace = "⠀"; //need 35? - private bool rigged = false; - private bool superRigged = false; + private bool _rigged; + private bool _superRigged; public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) { @@ -68,21 +68,19 @@ public class Planes : ICommand return; } - var carrierCount = 6; + const int carrierCount = 6; var planesBoard = CreatePlanesBoard(gambler,0); var planesBoard2 = CreatePlanesBoard(gambler); var planesBoard3 = CreatePlanesBoard(gambler); - if (rigged) + if (_rigged) { planesBoard2 = RigPlanesBoard(planesBoard2, carrierCount, 0); planesBoard3 = RigPlanesBoard(planesBoard3, carrierCount, 0); } - List planesBoards = new List(){planesBoard, planesBoard2, planesBoard3}; + List planesBoards = [planesBoard, planesBoard2, planesBoard3]; var plane = new Plane(gambler); - var frameLength = 1000.0; + const double frameLength = 1000.0; var fullCounter = 0; - bool firstBoard = true; - var counter = 0; var noseUp = true; var planesDisplay = GetPreGameBoard(-3, planesBoard2, plane, carrierCount, noseUp); var msgId = await botInstance.SendChatMessageAsync(planesDisplay, true); @@ -102,8 +100,7 @@ public class Planes : ICommand */ do { - if ((fullCounter-3) > 19) firstBoard = false; - counter = (fullCounter - 3) % 20; + var counter = (fullCounter - 3) % 20; await Task.Delay(TimeSpan.FromMilliseconds(frameLength / 3), ctx); @@ -217,20 +214,20 @@ public class Planes : ICommand plane.Gravity(); if ((fullCounter - 3) % 20 == 0 && fullCounter != 3)//removes old planesboard, adds new planeboard when necessary **********************************************************************NEEDS MORE UPDATES { - if (Money.GetRandomNumber(gambler, 0, 100) == 0 && settings[BuiltIn.Keys.KasinoPlanesRandomRiggeryEnabled].ToBoolean()) rigged = true; + if (Money.GetRandomNumber(gambler, 0, 100) == 0 && settings[BuiltIn.Keys.KasinoPlanesRandomRiggeryEnabled].ToBoolean()) _rigged = true; if (settings[BuiltIn.Keys.KasinoPlanesTargetedRiggeryEnabled].ToBoolean() && settings[BuiltIn.Keys.KasinoPlanesTargetedRiggeryVictims].JsonDeserialize>()!.Contains(user.KfId)) { - rigged = true; + _rigged = true; } logger.Info($"Switching planes boards. FullCounter: {fullCounter} | Counter: {counter}"); planesBoards.RemoveAt(0); planesBoards.Add(CreatePlanesBoard(gambler)); - if (rigged && Money.GetRandomNumber(gambler, 0, 100) == 0) { + if (_rigged && Money.GetRandomNumber(gambler, 0, 100) == 0) { planesBoards[1] = CreatePlanesBoard(gambler, 1); //1% chance to update to a board full of rockets if rigged - superRigged = true; + _superRigged = true; } - else if (rigged) + else if (_rigged) { planesBoards[1] = RigPlanesBoard(planesBoards[1], carrierCount, fullCounter); planesBoards[2] = RigPlanesBoard(planesBoards[2], carrierCount, fullCounter); @@ -334,8 +331,6 @@ public class Planes : ICommand private string GetGameBoard(int fullCounter, List planesBoards, Plane plane, int carrierCount, bool noseUp) { var output = ""; - int counter; - var logger = LogManager.GetCurrentClassLogger(); for (var row = 0; row < 8; row++) { @@ -344,6 +339,7 @@ public class Planes : ICommand column++) //plane starts out 3 space behind to give some space to the view, { var useBoard = 1; + int counter; if (fullCounter < 23) counter = fullCounter % 23 - 3; else counter = (fullCounter - 3) % 20; //--- @@ -404,7 +400,7 @@ public class Planes : ICommand } // Was https://i.postimg.cc/rmX59qtV/avelloonaircall2.webp previously - if (superRigged && row == 0) output += "[img]https://i.ddos.lgbt/u/6v8WJ5.webp[/img]"; + if (_superRigged && row == 0) output += "[img]https://i.ddos.lgbt/u/6v8WJ5.webp[/img]"; output += "[br]"; } return output; @@ -419,18 +415,13 @@ public class Planes : ICommand { var randomNum = Money.GetRandomNumber(gambler, 1, 100); if (forceTiles != -1) board[row, column] = forceTiles; - else if (randomNum < 49) - { - board[row, column] = 0; //neutral - } - else if (randomNum > 79) - { - board[row, column] = 1; //rocket - } else - { - board[row, column] = 2; //multi - } + board[row, column] = randomNum switch + { + < 49 => 0, + > 79 => 1, + _ => 2 + }; } } return board; @@ -438,11 +429,9 @@ public class Planes : ICommand private int[,] RigPlanesBoard(int[,] planesBoard, int carrierCount, int fullCounter) { - int[,] returnBoard = new int[6,20]; - int boardCounter = (fullCounter-3) / 20; - var spaceToUpdate = 0; - bool startUpdating = true; - spaceToUpdate = (fullCounter-3) % 20; //how far along is the game into the current board + var returnBoard = new int[6,20]; + bool startUpdating; + var spaceToUpdate = (fullCounter-3) % 20; //how far along is the game into the current board if (spaceToUpdate > 0) startUpdating = false; for (var row = 0; row < 6; row++)