mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
updates message stuff (#72)
* Implement admin-only clear command for saved games Added 'clear' command for admin to reset saved games. * Refactor LastMessage handling in KasinoMines Refactor LastMessage handling in KasinoMines
This commit is contained in:
@@ -16,6 +16,8 @@ public class MinesCommand : ICommand
|
||||
new Regex(@"^mines\s+cashout$", RegexOptions.IgnoreCase),
|
||||
//refresh
|
||||
new Regex(@"^mines\s+refresh$", RegexOptions.IgnoreCase),
|
||||
//clear - admin only
|
||||
new Regex(@"^mines\s+clear$", RegexOptions.IgnoreCase),
|
||||
//start game with number of picks
|
||||
new Regex(@"^mines\s+(?<bet>\d+(?:\.\d+)?)\s+(?<size>\d+)\s+(?<mines>\d+)\s+(?<picks>\d+)(?:\s+(?<cashout>cashout))?$", RegexOptions.IgnoreCase),
|
||||
//start game with coordinate string (must contain comma)
|
||||
@@ -46,6 +48,7 @@ public class MinesCommand : ICommand
|
||||
CancellationToken ctx)
|
||||
{
|
||||
|
||||
|
||||
var settings = await SettingsProvider.GetMultipleValuesAsync([
|
||||
BuiltIn.Keys.KasinoMinesCleanupDelay, BuiltIn.Keys.KiwiFarmsGreenColor, BuiltIn.Keys.KiwiFarmsRedColor,
|
||||
BuiltIn.Keys.KasinoMinesEnabled, BuiltIn.Keys.KasinoGameDisabledMessageCleanupDelay
|
||||
@@ -64,6 +67,21 @@ public class MinesCommand : ICommand
|
||||
if (gambler == null)
|
||||
throw new InvalidOperationException($"Caught a null when retrieving gambler for {user.KfUsername}");
|
||||
KasinoMines = new KasinoMines(botInstance, gambler.Id);
|
||||
if (message.Message.Contains("clear"))
|
||||
{
|
||||
if (user.UserRight == UserRight.Admin || user.UserRight == UserRight.TrueAndHonest)
|
||||
{
|
||||
KasinoMines.GetSavedGames(gambler.Id);
|
||||
KasinoMines.ActiveGames.Clear();
|
||||
KasinoMines.SaveActiveGames(gambler.Id);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, you don't have permission to clear saved games.", true, autoDeleteAfter: cleanupDelay);
|
||||
return;
|
||||
}
|
||||
}
|
||||
bool cashout = false;
|
||||
if (arguments.TryGetValue("cashout", out var cashOut)||message.Message.Contains("cashout")) cashout = true;
|
||||
|
||||
@@ -239,7 +257,19 @@ public class MinesCommand : ICommand
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = KasinoMines.ActiveGames[gambler.Id].LastMessage;
|
||||
var lastmsg = KasinoMines.ActiveGames[gambler.Id].LastMessageId;
|
||||
SentMessageTrackerModel msg;
|
||||
if (lastmsg == 0)
|
||||
{
|
||||
msg = (await botInstance.SendChatMessageAsync($"{KasinoMines.ActiveGames[gambler.Id].ToString()}", true));
|
||||
await botInstance.WaitForChatMessageAsync(msg, ct: ctx);
|
||||
if (msg.ChatMessageId == null) throw new InvalidOperationException("Timed out waiting for the message");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = botInstance.GetSentMessageStatus(KasinoMines.ActiveGames[gambler.Id].LastMessageReference);
|
||||
}
|
||||
|
||||
if (pick == 0) //if using coordinates
|
||||
{
|
||||
var game = KasinoMines.ActiveGames[gambler.Id];
|
||||
|
||||
@@ -24,7 +24,8 @@ public class KasinoMines
|
||||
public int Size { get; set; }
|
||||
public int Mines { get; set; }
|
||||
public List<(int r, int c)> BetsPlaced;
|
||||
public SentMessageTrackerModel LastMessage = null!;
|
||||
public int LastMessageId = 0;
|
||||
public string LastMessageReference = "";
|
||||
|
||||
|
||||
public KasinoMinesGame(GamblerDbModel creator, decimal wager, int size, int mines)
|
||||
@@ -41,12 +42,13 @@ public class KasinoMines
|
||||
{
|
||||
_logger.Info("Resetting message");
|
||||
// 0 is the default for int
|
||||
if (LastMessage.ChatMessageId != null)
|
||||
if (LastMessageId != 0)
|
||||
{
|
||||
await _kfChatBot.KfClient.DeleteMessageAsync(LastMessage.ChatMessageId.Value);
|
||||
await _kfChatBot.KfClient.DeleteMessageAsync(LastMessageId);
|
||||
}
|
||||
if (msg.ChatMessageId == null) throw new InvalidOperationException($"ChatMessageId was null for {msg.Reference}");
|
||||
LastMessage = msg;
|
||||
LastMessageId = msg.ChatMessageId.Value;
|
||||
LastMessageReference = msg.Reference;
|
||||
}
|
||||
|
||||
public async Task RigBoard((int r, int c) coord) //moves one of the mines to a specified coordinate for house edge rigging
|
||||
@@ -79,7 +81,7 @@ public class KasinoMines
|
||||
}
|
||||
public async Task Explode((int r, int c) mineLocation, SentMessageTrackerModel msg)
|
||||
{
|
||||
if (LastMessage.ChatMessageId == null || LastMessage.ChatMessageId != msg.ChatMessageId)
|
||||
if (LastMessageId == 0 || LastMessageId != msg.ChatMessageId)
|
||||
{
|
||||
await ResetMessage(msg);
|
||||
}
|
||||
@@ -141,7 +143,7 @@ public class KasinoMines
|
||||
}
|
||||
|
||||
await Task.Delay(100);
|
||||
await _kfChatBot.KfClient.EditMessageAsync(LastMessage.ChatMessageId!.Value, $"{str}[br]{Creator.User.FormatUsername()}");
|
||||
await _kfChatBot.KfClient.EditMessageAsync(LastMessageId, $"{str}[br]{Creator.User.FormatUsername()}");
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(10));
|
||||
@@ -311,8 +313,9 @@ public class KasinoMines
|
||||
await GetSavedGames(gamblerId);
|
||||
var game = ActiveGames[gamblerId];
|
||||
game.LastInteracted = DateTimeOffset.UtcNow;
|
||||
if (game.LastMessage.ChatMessageId == null || game.LastMessage.ChatMessageId != msg.ChatMessageId)
|
||||
if (game.LastMessageId == 0 || game.LastMessageId != msg.ChatMessageId)
|
||||
{
|
||||
|
||||
await game.ResetMessage(msg);
|
||||
}
|
||||
List<(int r, int c)> betCoords = new();
|
||||
@@ -368,7 +371,7 @@ public class KasinoMines
|
||||
await GetSavedGames(gamblerId);
|
||||
var game = ActiveGames[gamblerId];
|
||||
game.LastInteracted = DateTimeOffset.UtcNow;
|
||||
if (game.LastMessage.ChatMessageId == null || game.LastMessage.ChatMessageId != msg.ChatMessageId)
|
||||
if (game.LastMessageId == 0 || game.LastMessageId != msg.ChatMessageId)
|
||||
{
|
||||
await game.ResetMessage(msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user