rain control (#98)

This commit is contained in:
CrackmaticSoftware
2026-03-12 02:12:23 +01:00
committed by GitHub
parent 9f9bdee61d
commit c065bf513b
2 changed files with 24 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ using KfChatDotNetBot.Extensions;
using KfChatDotNetBot.Models;
using KfChatDotNetBot.Models.DbModels;
using KfChatDotNetBot.Services;
using KfChatDotNetBot.Settings;
using KfChatDotNetWsClient.Models.Events;
namespace KfChatDotNetBot.Commands.Kasino;
@@ -23,6 +24,22 @@ public class RainCommand : ICommand
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx)
{
var settings = await SettingsProvider.GetMultipleValuesAsync([
BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay, BuiltIn.Keys.KasinoRainCountdownDuration,
BuiltIn.Keys.KasinoRainEnabled
]);
// Check if rain is enabled
var rainEnabled = (settings[BuiltIn.Keys.KasinoRainEnabled]).ToBoolean();
if (!rainEnabled)
{
var gameDisabledCleanupDelay= TimeSpan.FromMilliseconds(settings[BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay].ToType<int>());
await botInstance.SendChatMessageAsync(
$"{user.FormatUsername()}, rain is currently disabled.",
true, autoDeleteAfter: gameDisabledCleanupDelay);
return;
}
var cleanupDelay = TimeSpan.FromSeconds(30);
if (botInstance.BotServices.KasinoRain == null || !botInstance.BotServices.KasinoRain.IsInitialized())
{
@@ -116,7 +133,8 @@ public class RainCommand : ICommand
RainAmount = decAmount,
PayoutWhen = DateTimeOffset.MaxValue
};
var timer = 60;
var rainCountdown = settings[BuiltIn.Keys.KasinoRainCountdownDuration].ToType<int>();
var timer = rainCountdown;
var msg = await botInstance.SendChatMessageAsync(
$"🌧️🌧️ {user.FormatUsername()} is making it rain with {await decAmount.FormatKasinoCurrencyAsync()}! Type [ditto]!rain[/ditto] in the next {timer} seconds to join.",
true);
@@ -128,7 +146,7 @@ public class RainCommand : ICommand
// Wait to set a real payout deadline only when chyat echoes the message out of fairness
// (and also so the timer doesn't overlap with the payout deadline)
rain.PayoutWhen = DateTimeOffset.UtcNow.AddSeconds(60);
rain.PayoutWhen = DateTimeOffset.UtcNow.AddSeconds(rainCountdown);
await botInstance.BotServices.KasinoRain.SaveRainState(rain);
while (timer > 0)
{