Added a feature to shill the kasino almanac

This commit is contained in:
barelyprofessional
2025-03-22 20:17:26 +08:00
parent 908c0e6dc4
commit 94f8c8de08
5 changed files with 193 additions and 1 deletions

View File

@@ -0,0 +1,50 @@
using KfChatDotNetBot.Settings;
using NLog;
namespace KfChatDotNetBot.Services;
public class AlmanacShill(ChatBot kfChatBot) : IDisposable
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private Task? _almanacShillTask;
private CancellationTokenSource _almanacShillCts = new();
private async Task AlmanacShillTask()
{
var interval = await Helpers.GetValue(BuiltIn.Keys.BotAlmanacInterval);
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(Convert.ToInt32(interval.Value)));
while (await timer.WaitForNextTickAsync(_almanacShillCts.Token))
{
_logger.Info("Time to shill the almanac in chat");
var text = await Helpers.GetValue(BuiltIn.Keys.BotAlmanacText);
await kfChatBot.SendChatMessageAsync($":!: {text.Value}", true);
}
}
public bool IsShillTaskRunning()
{
if (_almanacShillTask == null) return false;
if (_almanacShillTask.Status != TaskStatus.Running) return false;
if (_almanacShillCts.IsCancellationRequested) return false;
return true;
}
public async Task StopShillTaskAsync()
{
await _almanacShillCts.CancelAsync();
_almanacShillTask?.Dispose();
}
public void StartShillTask()
{
_almanacShillCts = new CancellationTokenSource();
_almanacShillTask = Task.Run(AlmanacShillTask, _almanacShillCts.Token);
}
public void Dispose()
{
_almanacShillCts.Cancel();
_almanacShillTask?.Dispose();
GC.SuppressFinalize(this);
}
}

View File

@@ -28,6 +28,7 @@ public class BotServices
private Rainbet _rainbet;
private Chipsgg _chipsgg;
private Clashgg _clashgg;
public AlmanacShill AlmanacShill;
private Task? _websocketWatchdog;
private Task? _howlggGetUserTimer;
@@ -71,7 +72,8 @@ public class BotServices
BuildChipsgg(),
BuildKick(),
BuildTwitch(),
BuildClashgg()
BuildClashgg(),
BuildAlmanacShill()
];
try
{
@@ -240,6 +242,13 @@ public class BotServices
await _twitchChat.StartWsClient();
}
private async Task BuildAlmanacShill()
{
AlmanacShill = new AlmanacShill(_chatBot);
AlmanacShill.StartShillTask();
_logger.Info("Built the almanac shill task");
}
private async Task WebsocketWatchdog()
{
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(10));