From 07169f0837741de8e070f96ddd49db1f4e7ed95f Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sun, 10 May 2026 11:23:38 -0500 Subject: [PATCH] Updated mines to hopefully fix a timing bug introduced by the 15 second delay. Extended the schedule auto delete functionality so that it can apply to any message, even ones not owned by the bot. --- KfChatDotNetBot/ChatBot.cs | 27 +++++++++++++++++++++++++ KfChatDotNetBot/Services/KasinoMines.cs | 7 +++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/KfChatDotNetBot/ChatBot.cs b/KfChatDotNetBot/ChatBot.cs index bacd736..3fcb682 100644 --- a/KfChatDotNetBot/ChatBot.cs +++ b/KfChatDotNetBot/ChatBot.cs @@ -657,6 +657,33 @@ public class ChatBot DeleteAt = DateTimeOffset.UtcNow.Add(deleteAfter) }); } + + /// + /// Exposes the private task used to delete messages based on a TimeSpan in case you want to use it on-demand + /// e.g. for cleaning up a gambling message only after the game has finished + /// + /// The message you want to delete where you only have a message UUID + /// NOTE: The bot doesn't check against its sent message tracker, so you can use this with messages + /// the bot was not responsible for sending or were lost due to a restart. + /// When you want it deleted + public void ScheduleMessageAutoDelete(string messageUuid, TimeSpan deleteAfter) + { + _scheduledDeletions.Add(new ScheduledAutoDeleteModel + { + Message = new SentMessageTrackerModel + { + ChatMessageUuid = messageUuid, + Delay = TimeSpan.Zero, + LastEdited = DateTimeOffset.UtcNow, + Message = "placeholder because I'm nigger rigging this shit big time", + Reference = Guid.NewGuid().ToString(), + SentAt = DateTimeOffset.UtcNow, + Status = SentMessageTrackerStatus.ResponseReceived, + Type = SentMessageType.ChatMessage + }, + DeleteAt = DateTimeOffset.UtcNow.Add(deleteAfter) + }); + } /// /// Non-async method which wraps the async method for sending a chat message diff --git a/KfChatDotNetBot/Services/KasinoMines.cs b/KfChatDotNetBot/Services/KasinoMines.cs index e2a8187..b4e103f 100644 --- a/KfChatDotNetBot/Services/KasinoMines.cs +++ b/KfChatDotNetBot/Services/KasinoMines.cs @@ -298,7 +298,11 @@ public class KasinoMines { await GetSavedGames(gamblerId); //attempt to delete the message if its there - if (ActiveGames[gamblerId].LastMessageId != null) await _kfChatBot.KfClient.DeleteMessageAsync(ActiveGames[gamblerId].LastMessageId!); + var lastMsgId = ActiveGames[gamblerId].LastMessageId; + if (lastMsgId != null) + { + _kfChatBot.ScheduleMessageAutoDelete(lastMsgId, TimeSpan.FromSeconds(15)); + } ActiveGames.Remove(gamblerId); await SaveActiveGames(gamblerId); } @@ -337,7 +341,6 @@ public class KasinoMines await _kfChatBot.SendChatMessageAsync( $"{game.Creator.User.FormatUsername()}, you won {await payout.FormatKasinoCurrencyAsync()} from your {await game.Wager.FormatKasinoCurrencyAsync()} bet on mines, collecting {game.BetsPlaced.Count} gems while avoiding {game.Mines} mines. Net: {await net.FormatKasinoCurrencyAsync()}. Balance: {await newBalance.FormatKasinoCurrencyAsync()}", true, autoDeleteAfter: TimeSpan.FromSeconds(15)); - await Task.Delay(TimeSpan.FromSeconds(15)); await RemoveGame(game.Creator.Id); }