From 48ef59da3ce1fe9f38a4b9d736c6f6960e51ddb8 Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sat, 24 Aug 2024 13:32:42 +0800 Subject: [PATCH] Hopefully fix a bug where it gets trapped in a reconnection loop. The issue is the bot tries to reconnect too fast, this just resets the last event so it doesn't try again too soon. --- KfChatDotNetBot/ChatBot.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/KfChatDotNetBot/ChatBot.cs b/KfChatDotNetBot/ChatBot.cs index dc9ab60..8d66f16 100644 --- a/KfChatDotNetBot/ChatBot.cs +++ b/KfChatDotNetBot/ChatBot.cs @@ -36,7 +36,7 @@ public class ChatBot private string? _lastDiscordStatus; internal bool IsBmjLive = false; private bool _isBmjLiveSynced = false; - private DateTime _lastKfEvent = DateTime.Now; + private DateTime _lastKfEvent = DateTime.UtcNow; private BotCommands _botCommands; private string _bmjTwitchUsername; private Howlgg _howlgg; @@ -636,6 +636,7 @@ public class ChatBot _logger.Debug($"Last KF event was {inactivityTime:g} ago"); if (inactivityTime.TotalMinutes > 10) { + _lastKfEvent = DateTime.UtcNow; _logger.Error("Forcing reconnection as bot is completely dead"); KfClient.Reconnect().Wait(_cancellationToken); } @@ -673,7 +674,7 @@ public class ChatBot var settings = Helpers.GetMultipleValues([BuiltIn.Keys.GambaSeshDetectEnabled, BuiltIn.Keys.GambaSeshUserId, BuiltIn.Keys.KiwiFarmsUsername]) .Result; - _lastKfEvent = DateTime.Now; + _lastKfEvent = DateTime.UtcNow; _logger.Debug($"Received {messages.Count} message(s)"); foreach (var message in messages) { @@ -786,7 +787,7 @@ public class ChatBot { var settings = Helpers.GetMultipleValues([BuiltIn.Keys.GambaSeshUserId, BuiltIn.Keys.GambaSeshDetectEnabled]) .Result; - _lastKfEvent = DateTime.Now; + _lastKfEvent = DateTime.UtcNow; _logger.Debug($"Received {users.Count} user join events"); using var db = new ApplicationDbContext(); foreach (var user in users) @@ -821,7 +822,7 @@ public class ChatBot { var settings = Helpers.GetMultipleValues([BuiltIn.Keys.GambaSeshUserId, BuiltIn.Keys.GambaSeshDetectEnabled]) .Result; - _lastKfEvent = DateTime.Now; + _lastKfEvent = DateTime.UtcNow; if (userIds.Contains(settings[BuiltIn.Keys.GambaSeshUserId].ToType()) && settings[BuiltIn.Keys.GambaSeshDetectEnabled].ToBoolean()) { _logger.Info("GambaSesh is no longer present");