Cleaned up code

This commit is contained in:
Tom
2024-08-14 18:19:18 +00:00
parent 36ae613736
commit 9fd43502f5
7 changed files with 13 additions and 183 deletions

View File

@ -44,9 +44,9 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
_messageTypes.Add("channel.subscription.gift", typeof(ChannelSubscriptionGiftMessage));
}
public async Task Execute(TwitchWebsocketClient sender, object data)
public Task Execute(TwitchWebsocketClient sender, object data)
{
Task.Run(async () =>
return Task.Run(() =>
{
if (sender == null)
return;
@ -66,6 +66,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
}
var d = JsonSerializer.Deserialize(message.Event.ToString()!, type, _options);
ArgumentNullException.ThrowIfNull(d);
Task.Run(async () => await handler.Execute(sender, d));
});
}

View File

@ -78,21 +78,19 @@ namespace TwitchChatTTS.Twitch.Socket
{
if (_identified?.UID == client.UID)
{
_logger.Warning($"Identified Twitch client has disconnected [client: {client.UID}][main: {_identified.UID}][backup: {_backup?.UID}]");
_logger.Debug($"Identified Twitch client has disconnected [client: {client.UID}][main: {_identified.UID}][backup: {_backup?.UID}]");
_identified = null;
reconnecting = true;
}
else if (_backup?.UID == client.UID)
{
_logger.Warning($"Backup Twitch client has disconnected [client: {client.UID}][main: {_identified?.UID}][backup: {_backup.UID}]");
_logger.Debug($"Backup Twitch client has disconnected [client: {client.UID}][main: {_identified?.UID}][backup: {_backup.UID}]");
_backup = null;
}
else if (client.ReceivedReconnecting)
{
_logger.Debug($"Twitch client disconnected due to reconnection [client: {client.UID}][main: {_identified?.UID}][backup: {_backup?.UID}]");
}
else
_logger.Error($"Twitch client disconnected from unknown source [client: {client.UID}][main: {_identified?.UID}][backup: {_backup?.UID}]");
_logger.Warning($"Twitch client disconnected from unknown source [client: {client.UID}][main: {_identified?.UID}][backup: {_backup?.UID}]");
}
if (reconnecting)
@ -111,7 +109,7 @@ namespace TwitchChatTTS.Twitch.Socket
{
if (_backup != null && _backup.UID == client.UID)
{
_logger.Information($"Twitch client has been identified [client: {client.UID}][main: {_identified?.UID}][backup: {_backup.UID}]");
_logger.Debug($"Twitch client has been identified [client: {client.UID}][main: {_identified?.UID}][backup: {_backup.UID}]");
_identified = _backup;
_backup = null;
}
@ -120,7 +118,7 @@ namespace TwitchChatTTS.Twitch.Socket
}
else if (_identified.UID == client.UID)
{
_logger.Warning($"Twitch client has been re-identified [client: {client.UID}][main: {_identified.UID}][backup: {_backup?.UID}]");
_logger.Debug($"Twitch client has been re-identified [client: {client.UID}][main: {_identified.UID}][backup: {_backup?.UID}]");
}
else if (_backup == null || _backup.UID != client.UID)
{

View File

@ -17,7 +17,6 @@ namespace TwitchChatTTS.Twitch.Socket
private readonly IDictionary<string, string> _subscriptions;
private readonly IBackoff _backoff;
private readonly Configuration _configuration;
private DateTime _lastReceivedMessageTimestamp;
private bool _disconnected;
private readonly object _lock;
@ -157,8 +156,6 @@ namespace TwitchChatTTS.Twitch.Socket
return;
}
_lastReceivedMessageTimestamp = DateTime.UtcNow;
string content = message.Payload?.ToString() ?? string.Empty;
if (message.Metadata.MessageType != "session_keepalive")
_logger.Debug("Twitch RX #" + message.Metadata.MessageType + ": " + content);