From 80916c9b2d83208b586a128ee40afc3fa49b6b30 Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sun, 31 May 2026 13:14:12 -0500 Subject: [PATCH] deadTime was the wrong name for this stupid variable. Now updating the last reconnect attempt timestamp when reconnecting, considering both timestamps again for determining whether to exit and avoiding forced reconnects if within a minute of a previous reconnect attempt. Future plan is to basically disable automatic reconnection in the WS library and use the fast fail functionality instead since it just causes more problems than it's worth. --- KfChatDotNetBot/ChatBot.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/KfChatDotNetBot/ChatBot.cs b/KfChatDotNetBot/ChatBot.cs index 627cfd3..7a2b4dc 100644 --- a/KfChatDotNetBot/ChatBot.cs +++ b/KfChatDotNetBot/ChatBot.cs @@ -156,12 +156,13 @@ public class ChatBot _logger.Info("Not pinging the connection as we're currently disconnected"); } var inactivityTime = DateTime.UtcNow - KfClient.LastPacketReceived; + var lastReconnect = DateTime.UtcNow - _lastReconnectAttempt; + _logger.Debug($"Last KF event was {inactivityTime:g} ago"); var inactivityTimeout = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.KiwiFarmsInactivityTimeout)).ToType(); - if (inactivityTime.TotalSeconds > inactivityTimeout) + if (inactivityTime.TotalSeconds > inactivityTimeout && lastReconnect.TotalMinutes > 1) { - // Yeah, super dodgy - KfClient.LastPacketReceived = DateTime.UtcNow; + _lastReconnectAttempt = DateTime.UtcNow; _logger.Error("Forcing reconnect as bot is completely dead"); await KfClient.ReconnectAsync(); } @@ -178,7 +179,7 @@ public class ChatBot var deadTime = DateTime.UtcNow - _lastReconnectAttempt; // No connection and no successful reconnection attempt in the last 5 minutes // Either the site is completely dead or the bot got screwed by a nasty error and can't reconnect - if (inactivityTime > TimeSpan.FromMinutes(10) || deadTime > TimeSpan.FromMinutes(15)) + if (inactivityTime > TimeSpan.FromMinutes(10) && deadTime > TimeSpan.FromMinutes(15)) { var shouldExit = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.BotExitOnDeath)).ToBoolean(); _logger.Error("The bot as is dead beyond belief right now");