From a133fb79ebc74a3c72bf9fbf112fce3d65e89b31 Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:47:53 +0800 Subject: [PATCH] Added a public field for getting the last packet received time and an async Disconnect method --- KfChatDotNetWsClient/ChatClient.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/KfChatDotNetWsClient/ChatClient.cs b/KfChatDotNetWsClient/ChatClient.cs index d97d543..db065bd 100644 --- a/KfChatDotNetWsClient/ChatClient.cs +++ b/KfChatDotNetWsClient/ChatClient.cs @@ -25,6 +25,7 @@ public class ChatClient private WebsocketClient _wsClient; private readonly Logger _logger = LogManager.GetCurrentClassLogger(); private ChatClientConfigModel _config; + public DateTime LastPacketReceived = DateTime.UtcNow; public ChatClient(ChatClientConfigModel config) { @@ -51,6 +52,14 @@ public class ChatClient _wsClient.Stop(WebSocketCloseStatus.NormalClosure, "Closing websocket").Wait(); } + // Bot is inconsistent with what methods are async and not but I don't want to change the Disconnect() method to be + // async as then it'll fuck up anyone not waiting for it. This is why there's an explicit async method for this but + // none for reconnect. + public async Task DisconnectAsync() + { + await _wsClient.Stop(WebSocketCloseStatus.NormalClosure, "Closing websocket"); + } + public async Task Reconnect() { await _wsClient.Reconnect(); @@ -114,6 +123,7 @@ public class ChatClient private void WsMessageReceived(ResponseMessage message) { + LastPacketReceived = DateTime.UtcNow; if (message.Text == null) { _logger.Info("Websocket message was null, ignoring packet");