Fixed several issues

This commit is contained in:
Tom
2024-08-12 07:54:38 +00:00
parent 2056b2cd48
commit 658f5a9ce4
6 changed files with 73 additions and 57 deletions

View File

@@ -46,25 +46,28 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
public async Task Execute(TwitchWebsocketClient sender, object data)
{
if (sender == null)
return;
if (data is not NotificationMessage message)
return;
if (!_messageTypes.TryGetValue(message.Subscription.Type, out var type) || type == null)
Task.Run(async () =>
{
_logger.Warning($"Could not find Twitch notification type [message type: {message.Subscription.Type}]");
return;
}
if (sender == null)
return;
if (data is not NotificationMessage message)
return;
if (!_handlers.TryGetValue(message.Subscription.Type, out ITwitchSocketHandler? handler) || handler == null)
{
_logger.Warning($"Could not find Twitch notification handler [message type: {message.Subscription.Type}]");
return;
}
if (!_messageTypes.TryGetValue(message.Subscription.Type, out var type) || type == null)
{
_logger.Warning($"Could not find Twitch notification type [message type: {message.Subscription.Type}]");
return;
}
var d = JsonSerializer.Deserialize(message.Event.ToString()!, type, _options);
await handler.Execute(sender, d);
if (!_handlers.TryGetValue(message.Subscription.Type, out ITwitchSocketHandler? handler) || handler == null)
{
_logger.Warning($"Could not find Twitch notification handler [message type: {message.Subscription.Type}]");
return;
}
var d = JsonSerializer.Deserialize(message.Event.ToString()!, type, _options);
Task.Run(async () => await handler.Execute(sender, d));
});
}
}
}