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.

This commit is contained in:
barelyprofessional
2026-05-10 11:23:38 -05:00
parent 5e2dc25c77
commit 07169f0837
2 changed files with 32 additions and 2 deletions

View File

@@ -657,6 +657,33 @@ public class ChatBot
DeleteAt = DateTimeOffset.UtcNow.Add(deleteAfter)
});
}
/// <summary>
/// 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
/// </summary>
/// <param name="messageUuid">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.</param>
/// <param name="deleteAfter">When you want it deleted</param>
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)
});
}
/// <summary>
/// Non-async method which wraps the async method for sending a chat message

View File

@@ -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);
}