mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Added a feature to schedule message deletion. Changed the kasino games to use them so planes doesn't get deleted mid-run.
Also increased Planes timeout to 120 seconds as some games run on very long.
This commit is contained in:
@@ -421,6 +421,17 @@ public class ChatBot
|
|||||||
return messageTracker;
|
return messageTracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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="message">The message you want to delete</param>
|
||||||
|
/// <param name="deleteAfter">When you want it deleted</param>
|
||||||
|
public async Task ScheduleMessageAutoDelete(SentMessageTrackerModel message, TimeSpan deleteAfter)
|
||||||
|
{
|
||||||
|
_ = SendChatMessageAsyncAutoDeleteTask(message, deleteAfter);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task SendChatMessageAsyncAutoDeleteTask(SentMessageTrackerModel message, TimeSpan deleteAfter)
|
private async Task SendChatMessageAsyncAutoDeleteTask(SentMessageTrackerModel message, TimeSpan deleteAfter)
|
||||||
{
|
{
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ public class KenoCommand : ICommand
|
|||||||
private const string MatchRevealDisplay = "💠";
|
private const string MatchRevealDisplay = "💠";
|
||||||
private const string BlankSpaceDisplay = "⬛";
|
private const string BlankSpaceDisplay = "⬛";
|
||||||
|
|
||||||
|
private SentMessageTrackerModel _kenoTable;
|
||||||
|
|
||||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
|
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
|
||||||
CancellationToken ctx)
|
CancellationToken ctx)
|
||||||
@@ -175,6 +176,7 @@ public class KenoCommand : ICommand
|
|||||||
await botInstance.SendChatMessageAsync(
|
await botInstance.SendChatMessageAsync(
|
||||||
$"{user.FormatUsername()}, you [color={colors[BuiltIn.Keys.KiwiFarmsGreenColor].Value}]won {await win.FormatKasinoCurrencyAsync()} with a {payoutMulti}x multi![/color]. Your balance is now: {await newBalance.FormatKasinoCurrencyAsync()}.",
|
$"{user.FormatUsername()}, you [color={colors[BuiltIn.Keys.KiwiFarmsGreenColor].Value}]won {await win.FormatKasinoCurrencyAsync()} with a {payoutMulti}x multi![/color]. Your balance is now: {await newBalance.FormatKasinoCurrencyAsync()}.",
|
||||||
true, autoDeleteAfter: cleanupDelay);
|
true, autoDeleteAfter: cleanupDelay);
|
||||||
|
await botInstance.ScheduleMessageAutoDelete(_kenoTable, cleanupDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AnimatedDisplayTable(List<int> playerNumbers, List<int> casinoNumbers, List<int> matches, ChatBot botInstance)
|
private async Task AnimatedDisplayTable(List<int> playerNumbers, List<int> casinoNumbers, List<int> matches, ChatBot botInstance)
|
||||||
@@ -196,12 +198,12 @@ public class KenoCommand : ICommand
|
|||||||
displayMessage += "[br]";
|
displayMessage += "[br]";
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg = await botInstance.SendChatMessageAsync(displayMessage, true, autoDeleteAfter: cleanupDelay);
|
_kenoTable = await botInstance.SendChatMessageAsync(displayMessage, true);
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (msg.ChatMessageId == null)
|
while (_kenoTable.ChatMessageId == null)
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
if (msg.Status is SentMessageTrackerStatus.NotSending or SentMessageTrackerStatus.Lost) return;
|
if (_kenoTable.Status is SentMessageTrackerStatus.NotSending or SentMessageTrackerStatus.Lost) return;
|
||||||
if (i > 60) return;
|
if (i > 60) return;
|
||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
}
|
}
|
||||||
@@ -235,14 +237,14 @@ public class KenoCommand : ICommand
|
|||||||
}
|
}
|
||||||
displayMessage += "[br]";
|
displayMessage += "[br]";
|
||||||
}
|
}
|
||||||
await botInstance.KfClient.EditMessageAsync(msg.ChatMessageId!.Value, displayMessage);
|
await botInstance.KfClient.EditMessageAsync(_kenoTable.ChatMessageId!.Value, displayMessage);
|
||||||
await Task.Delay(frameDelay);
|
await Task.Delay(frameDelay);
|
||||||
if (displayMessage.Length <= 79 && displayMessage.Contains(BlankSpaceDisplay) &&
|
if (displayMessage.Length <= 79 && displayMessage.Contains(BlankSpaceDisplay) &&
|
||||||
(displayMessage.Contains(CasinoNumberDisplay) || displayMessage.Contains(MatchRevealDisplay) ||
|
(displayMessage.Contains(CasinoNumberDisplay) || displayMessage.Contains(MatchRevealDisplay) ||
|
||||||
frame == 9)) continue; //every board should have blank spaces and casino numbers or matches. player numbers might be hidden by matches
|
frame == 9)) continue; //every board should have blank spaces and casino numbers or matches. player numbers might be hidden by matches
|
||||||
logger.Error($"Casino numbers: {string.Join(",", casinoNumbers)} | Player Numbers: {string.Join(",", playerNumbers)} | Matches: {string.Join(",", matches)} | Frame: {frame - 1} | Display Board:");
|
logger.Error($"Casino numbers: {string.Join(",", casinoNumbers)} | Player Numbers: {string.Join(",", playerNumbers)} | Matches: {string.Join(",", matches)} | Frame: {frame - 1} | Display Board:");
|
||||||
logger.Error(displayMessage);
|
logger.Error(displayMessage);
|
||||||
await botInstance.SendChatMessageAsync($"Keno is bugged dewd, died on frame {frame} :bossman:", true);
|
await botInstance.SendChatMessageAsync($"Keno is bugged dewd, died on frame {frame} :bossman:", true, autoDeleteAfter: cleanupDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +278,7 @@ public class Planes : ICommand
|
|||||||
];
|
];
|
||||||
public string? HelpText => "!planes <bet amount>";
|
public string? HelpText => "!planes <bet amount>";
|
||||||
public UserRight RequiredRight => UserRight.Loser;
|
public UserRight RequiredRight => UserRight.Loser;
|
||||||
public TimeSpan Timeout => TimeSpan.FromSeconds(60);
|
public TimeSpan Timeout => TimeSpan.FromSeconds(120);
|
||||||
public RateLimitOptionsModel? RateLimitOptions => new()
|
public RateLimitOptionsModel? RateLimitOptions => new()
|
||||||
{
|
{
|
||||||
MaxInvocations = 3,
|
MaxInvocations = 3,
|
||||||
@@ -329,7 +331,7 @@ public class Planes : ICommand
|
|||||||
var counter = 0;
|
var counter = 0;
|
||||||
var noseUp = true;
|
var noseUp = true;
|
||||||
var planesDisplay = GetPreGameBoard(-3, planesBoard2, plane, carrierCount, noseUp);
|
var planesDisplay = GetPreGameBoard(-3, planesBoard2, plane, carrierCount, noseUp);
|
||||||
var msgId = await botInstance.SendChatMessageAsync(planesDisplay, true, autoDeleteAfter: cleanupDelay);
|
var msgId = await botInstance.SendChatMessageAsync(planesDisplay, true);
|
||||||
var num = 0;
|
var num = 0;
|
||||||
while (msgId.ChatMessageId == null)
|
while (msgId.ChatMessageId == null)
|
||||||
{
|
{
|
||||||
@@ -492,6 +494,7 @@ public class Planes : ICommand
|
|||||||
await botInstance.SendChatMessageAsync(
|
await botInstance.SendChatMessageAsync(
|
||||||
$"{user.FormatUsername()}, you [color={colors[BuiltIn.Keys.KiwiFarmsRedColor].Value}]crashed![/color] Your balance is now: {await newBalance.FormatKasinoCurrencyAsync()}",
|
$"{user.FormatUsername()}, you [color={colors[BuiltIn.Keys.KiwiFarmsRedColor].Value}]crashed![/color] Your balance is now: {await newBalance.FormatKasinoCurrencyAsync()}",
|
||||||
true, autoDeleteAfter: cleanupDelay);
|
true, autoDeleteAfter: cleanupDelay);
|
||||||
|
await botInstance.ScheduleMessageAutoDelete(msgId, cleanupDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetPreGameBoard(int fullCounter, int[,] planesBoard, Plane plane, int carrierCount, bool noseUp)
|
private string GetPreGameBoard(int fullCounter, int[,] planesBoard, Plane plane, int carrierCount, bool noseUp)
|
||||||
|
|||||||
Reference in New Issue
Block a user