mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Added a feature to shill the kasino almanac
This commit is contained in:
50
KfChatDotNetBot/Services/AlmanacShill.cs
Normal file
50
KfChatDotNetBot/Services/AlmanacShill.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user