message deletion and krash (#102)

* Update message deletion in BlackjackCommand

Refactor message deletion logic for non-whisper messages.

* Add message deletion for non-whisper coinflip

* Implement message deletion for non-whispers

Added a check to delete non-whisper messages if they have a MessageUuid.

* Delete non-whisper messages in KenoCommand

* Implement KrashBetCommand for betting functionality

* Lambchop message deletion

Lambchop message deletion

* limbo message deletion

limbo message deletion

* Delete message if not a whisper mines

Delete message if not a whisper mines

* planes message dleete

planes message dleete

* plinko message delete

plinko message delete

* Add message deletion for non-whisper messages roulette

Delete the message if it's not a whisper and has a UUID.

* add message deletion for non-whisper slots

add message deletion for non-whisper slots

* Implement message deletion for WheelCommand

Add message deletion for non-whisper messages.

* Add KasinoKrash service initialization

* Add KasinoKrash service for game management

Implement KasinoKrash service for managing the Krash game, including state management, betting, and payout logic.

* Update message formatting in KasinoMines.cs

add buttons

* Update MinesCommand.cs

allow more mines spam since message will be deleted anyways, spam will be supported via button
This commit is contained in:
alogindtractor
2026-04-06 18:30:49 -07:00
committed by GitHub
parent d97d4f7fad
commit 26e0b1f49f
16 changed files with 409 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
using System.Text.Json;
using System.Text.Json;
using System.Text.RegularExpressions;
using KfChatDotNetBot.Extensions;
using KfChatDotNetBot.Models;
@@ -61,6 +61,11 @@ public class BlackjackCommand : ICommand
true, autoDeleteAfter: gameDisabledCleanupDelay);
return;
}
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
var cleanupDelay = TimeSpan.FromMilliseconds(settings[BuiltIn.Keys.KasinoBlackjackCleanupDelay].ToType<int>());
@@ -801,4 +806,4 @@ internal record HandResultData(
List<Card> Hand,
int PlayerValue,
HandOutcome Outcome,
decimal Effect);
decimal Effect);

View File

@@ -51,6 +51,11 @@ public class CoinflipCommand : ICommand
true, autoDeleteAfter: gameDisabledCleanupDelay);
return;
}
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
var cleanupDelay = TimeSpan.FromMilliseconds(settings[BuiltIn.Keys.KasinoCoinflipCleanupDelay].ToType<int>());
@@ -145,4 +150,4 @@ public class CoinflipCommand : ICommand
return $"{baseUrl}/bossmancoin-{choiceStr}.webp?{unixTime}";
}
}
}

View File

@@ -1,4 +1,4 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using KfChatDotNetBot.Extensions;
using KfChatDotNetBot.Models;
using KfChatDotNetBot.Models.DbModels;
@@ -36,6 +36,11 @@ public class DiceCommand : ICommand
BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay, BuiltIn.Keys.KasinoDiceCleanupDelay,
BuiltIn.Keys.KasinoDiceEnabled
]);
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
// Check if dice is enabled
var diceEnabled = (settings[BuiltIn.Keys.KasinoDiceEnabled]).ToBoolean();
@@ -155,4 +160,4 @@ public class DiceCommand : ICommand
}
return $"{diceDisplayShifted}\n{diceMeter}";
}
}
}

View File

@@ -47,7 +47,10 @@ public class KenoCommand : ICommand
BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay, BuiltIn.Keys.KasinoKenoCleanupDelay,
BuiltIn.Keys.KasinoKenoFrameDelay, BuiltIn.Keys.KasinoKenoEnabled
]);
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
// Check if keno is enabled
var kenoEnabled = (settings[BuiltIn.Keys.KasinoKenoEnabled]).ToBoolean();
if (!kenoEnabled)

View File

@@ -0,0 +1,81 @@
using System.Text.RegularExpressions;
using KfChatDotNetBot.Extensions;
using KfChatDotNetBot.Models;
using KfChatDotNetBot.Models.DbModels;
using KfChatDotNetBot.Services;
using KfChatDotNetBot.Settings;
using KfChatDotNetWsClient.Models.Events;
namespace KfChatDotNetBot.Commands.Kasino;
[KasinoCommand]
[WagerCommand]
public class KrashBetCommand : ICommand
{
public List<Regex> Patterns => [
new Regex(@"^krash (?<amount>\d+(?:\.\d+)?) (?<multi>\d+(?:\.\d+)?)$", RegexOptions.IgnoreCase),
new Regex(@"^krash (?<amount>\d+(?:\.\d+)?)$", RegexOptions.IgnoreCase),
new Regex(@"^krash", RegexOptions.IgnoreCase)
];
public string? HelpText => "!rain <amount> to start a rain, !rain to join all active rains";
public UserRight RequiredRight => UserRight.Loser;
public TimeSpan Timeout => TimeSpan.FromSeconds(90);
public RateLimitOptionsModel? RateLimitOptions => null;
public bool WhisperCanInvoke => false;
public async Task RunCommand(ChatBot botInstance, BotCommandMessageModel message, UserDbModel user,
GroupCollection arguments,
CancellationToken ctx)
{
var cleanupDelay = TimeSpan.FromSeconds(10);
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
var gambler = await Money.GetGamblerEntityAsync(user.Id, ct: ctx);
if (gambler == null)
throw new InvalidOperationException($"Caught a null when retrieving gambler for {user.KfUsername}");
if (botInstance.BotServices.KasinoKrash == null)
{
await botInstance.SendChatMessageAsync("Krash is not currently running.", true, autoDeleteAfter: cleanupDelay);
return;
}
decimal multi;
decimal wager;
if (!arguments.TryGetValue("amount", out var amountGroup))
{
//attempt to cash out a currently running game
await botInstance.BotServices.KasinoKrash.AttemptKrash(gambler);
}
if (!arguments.TryGetValue("multi", out var multiGroup))
{
multi = -1;
}
else
{
multi = Convert.ToDecimal(multiGroup.Value);
}
wager = Convert.ToDecimal(amountGroup.Value);
if (wager > gambler.Balance)
{
await botInstance.SendChatMessageAsync(
$"{user.FormatUsername()}, your balance of {gambler.Balance} is not enough to bet {wager} on krash.",
true, autoDeleteAfter: TimeSpan.FromSeconds(5));
return;
}
if (botInstance.BotServices.KasinoKrash.theGame == null)
{
//start a new game
await botInstance.BotServices.KasinoKrash.StartGame(gambler, wager, multi);
}
else
{
//add to the existing game
await botInstance.BotServices.KasinoKrash.AddParticipant(gambler, wager, multi);
}
}
}

View File

@@ -1,4 +1,4 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using KfChatDotNetBot.Extensions;
using KfChatDotNetBot.Models;
using KfChatDotNetBot.Models.DbModels;
@@ -66,7 +66,10 @@ public class LambchopCommand : ICommand
BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay, BuiltIn.Keys.KasinoLambchopCleanupDelay,
BuiltIn.Keys.KasinoLambchopEnabled
]);
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
// Check if lambchop is enabled
var lambchopEnabled = (settings[BuiltIn.Keys.KasinoLambchopEnabled]).ToBoolean();
if (!lambchopEnabled)
@@ -453,4 +456,4 @@ public class LambchopCommand : ICommand
return (decimal)lambChopMultis[targetTile];
}
}
}

View File

@@ -42,7 +42,10 @@ public class LimboCommand : ICommand
BuiltIn.Keys.KasinoLimboCleanupDelay, BuiltIn.Keys.KasinoLimboEnabled,
BuiltIn.Keys.KiwiFarmsGreenColor, BuiltIn.Keys.KiwiFarmsRedColor
]);
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
// Check if limbo is enabled
var limboEnabled = (settings[BuiltIn.Keys.KasinoLimboEnabled]).ToBoolean();
if (!limboEnabled)

View File

@@ -39,7 +39,7 @@ public class MinesCommand : ICommand
public RateLimitOptionsModel? RateLimitOptions => new RateLimitOptionsModel
{
MaxInvocations = 3,
MaxInvocations = 10,
Window = TimeSpan.FromSeconds(10)
};
public bool WhisperCanInvoke => false;
@@ -56,6 +56,10 @@ public class MinesCommand : ICommand
BuiltIn.Keys.KasinoMinesEnabled, BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay
]);
var cleanupDelay = TimeSpan.FromMilliseconds(settings[BuiltIn.Keys.KasinoMinesCleanupDelay].ToType<int>());
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
if (!settings[BuiltIn.Keys.KasinoMinesEnabled].ToBoolean())
{
var gameDisabledCleanupDelay= TimeSpan.FromMilliseconds(settings[BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay].ToType<int>());

View File

@@ -51,7 +51,10 @@ public class Planes : ICommand
BuiltIn.Keys.KasinoPlanesCleanupDelay, BuiltIn.Keys.KasinoPlanesRandomRiggeryEnabled,
BuiltIn.Keys.KasinoPlanesTargetedRiggeryEnabled, BuiltIn.Keys.KasinoPlanesTargetedRiggeryVictims
]);
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
// Check if planes is enabled
var planesEnabled = (settings[BuiltIn.Keys.KasinoPlanesEnabled]).ToBoolean();
if (!planesEnabled)

View File

@@ -72,7 +72,10 @@ public class PlinkoCommand : ICommand
VACUUM += 1 - (double)HOUSE_EDGE;
validPositions = new List<(int row, int col)>() { (0, DIFFICULTY-1) };
validColumnsForRow = new Dictionary<int, List<int>>(){{0, new List<int>(){DIFFICULTY-1}}};
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
//calculate all the valid positions for the difficulty
for (int i = 1; i < DIFFICULTY; i++)
{

View File

@@ -1,4 +1,4 @@
using System.Net.Http.Headers;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Text.RegularExpressions;
using KfChatDotNetBot.Extensions;
@@ -126,6 +126,10 @@ public class RouletteCommand : ICommand
}
await PlaceBet(botInstance, user, amountGroup.Value, betGroup.Value.Trim(), countdownDuration, ctx);
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
}
private async Task PlaceBet(ChatBot botInstance, UserDbModel user, string amountStr, string betStr,
@@ -1035,4 +1039,4 @@ public static class RouletteAnimationGenerator
return img;
}
}
}

View File

@@ -49,7 +49,10 @@ public class SlotsCommand : ICommand
var settings = await SettingsProvider.GetMultipleValuesAsync([
BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay, BuiltIn.Keys.KasinoSlotsEnabled
]);
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
// Check if slots is enabled
var slotsEnabled = (settings[BuiltIn.Keys.KasinoSlotsEnabled]).ToBoolean();
if (!slotsEnabled)

View File

@@ -1,4 +1,4 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using System.Globalization;
using KfChatDotNetBot.Extensions;
using KfChatDotNetBot.Models;
@@ -69,7 +69,10 @@ public class WheelCommand : ICommand
BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay, BuiltIn.Keys.KasinoWheelCleanupDelay,
BuiltIn.Keys.KasinoWheelEnabled
]);
if (message is { IsWhisper: false, MessageUuid: not null })
{
await botInstance.KfClient.DeleteMessageAsync(message.MessageUuid);
}
// Check if wheel is enabled
var wheelEnabled = (settings[BuiltIn.Keys.KasinoWheelEnabled]).ToBoolean();
if (!wheelEnabled)
@@ -281,4 +284,4 @@ public class Wheel
string bottom = string.Concat(reversedBottom);
return $"{top}\n{middle}\n{bottom}";
}
}
}