Fixed several issues
This commit is contained in:
@@ -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));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -40,11 +40,11 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
|
||||
}
|
||||
|
||||
_api.Initialize(_user.TwitchConnection.ClientId, _user.TwitchConnection.AccessToken);
|
||||
var span = DateTime.Now - _user.TwitchConnection.ExpiresAt;
|
||||
var timeLeft = span.TotalDays >= 2 ? Math.Floor(span.TotalDays) + " days" : (span.TotalHours >= 2 ? Math.Floor(span.TotalHours) + " hours" : Math.Floor(span.TotalMinutes) + " minutes");
|
||||
if (span.TotalDays >= 3)
|
||||
var span = _user.TwitchConnection.ExpiresAt - DateTime.Now;
|
||||
var timeLeft = span.Days >= 2 ? span.Days + " days" : (span.Hours >= 2 ? span.Hours + " hours" : span.Minutes + " minutes");
|
||||
if (span.Days >= 3)
|
||||
_logger.Information($"Twitch connection has {timeLeft} before it is revoked.");
|
||||
else if (span.TotalMinutes >= 0)
|
||||
else if (span.Minutes >= 0)
|
||||
_logger.Warning($"Twitch connection has {timeLeft} before it is revoked. Refreshing the token is soon required.");
|
||||
else {
|
||||
_logger.Error("Twitch connection has its permissions revoked. Refresh the token. Twith client will not be connecting.");
|
||||
|
Reference in New Issue
Block a user