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

@ -1,7 +1,6 @@
using Serilog; using Serilog;
using TwitchChatTTS.Chat.Soeech; using TwitchChatTTS.Chat.Soeech;
using TwitchChatTTS.Hermes.Socket; using TwitchChatTTS.Hermes.Socket;
using TwitchChatTTS.Twitch.Socket;
using TwitchChatTTS.Twitch.Socket.Messages; using TwitchChatTTS.Twitch.Socket.Messages;
using static TwitchChatTTS.Chat.Commands.TTSCommands; using static TwitchChatTTS.Chat.Commands.TTSCommands;

View File

@ -9,7 +9,6 @@ namespace TwitchChatTTS.Chat.Soeech
private readonly Mutex _mutex; private readonly Mutex _mutex;
private readonly Mutex _mutex2; private readonly Mutex _mutex2;
//public TTSGroupedMessage? PlayingGroup { get; set; }
public TTSGroupedMessage? Playing { get; set; } public TTSGroupedMessage? Playing { get; set; }
public TTSPlayer() public TTSPlayer()
@ -200,7 +199,6 @@ namespace TwitchChatTTS.Chat.Soeech
public DateTime Timestamp { get; set; } public DateTime Timestamp { get; set; }
public int Priority { get; set; } public int Priority { get; set; }
public IList<TTSMessage> Messages { get; set; } public IList<TTSMessage> Messages { get; set; }
//public IList<ISampleProvider> Audios { get; set; }
public ISampleProvider? Audio { get; set; } public ISampleProvider? Audio { get; set; }
@ -212,7 +210,6 @@ namespace TwitchChatTTS.Chat.Soeech
Messages = messages; Messages = messages;
Timestamp = timestamp; Timestamp = timestamp;
Priority = priority; Priority = priority;
//Audios = new List<ISampleProvider>();
} }
} }
} }

View File

@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using CommonSocketLibrary.Abstract; using CommonSocketLibrary.Abstract;
using CommonSocketLibrary.Common; using CommonSocketLibrary.Common;
using HermesSocketLibrary.Socket.Data; using HermesSocketLibrary.Socket.Data;
@ -42,11 +43,23 @@ namespace TwitchChatTTS.Hermes.Socket.Handlers
_user.OwnerId = message.OwnerId; _user.OwnerId = message.OwnerId;
_user.DefaultTTSVoice = message.DefaultTTSVoice; _user.DefaultTTSVoice = message.DefaultTTSVoice;
_user.VoicesAvailable = message.TTSVoicesAvailable; _user.VoicesAvailable = message.TTSVoicesAvailable;
_user.RegexFilters = message.WordFilters.ToArray();
_user.VoicesEnabled = new HashSet<string>(message.EnabledTTSVoices); _user.VoicesEnabled = new HashSet<string>(message.EnabledTTSVoices);
_user.TwitchConnection = message.Connections.FirstOrDefault(c => c.Default && c.Type == "twitch"); _user.TwitchConnection = message.Connections.FirstOrDefault(c => c.Default && c.Type == "twitch");
_user.NightbotConnection = message.Connections.FirstOrDefault(c => c.Default && c.Type == "nightbot"); _user.NightbotConnection = message.Connections.FirstOrDefault(c => c.Default && c.Type == "nightbot");
var filters = message.WordFilters.Where(f => f.Search != null && f.Replace != null).ToArray();
foreach (var filter in filters)
{
try
{
var re = new Regex(filter.Search!, RegexOptions.Compiled);
re.Match(string.Empty);
filter.Regex = re;
}
catch (Exception) { }
}
_user.RegexFilters = filters;
client.LoggedIn = true; client.LoggedIn = true;
_logger.Information($"Logged in as {_user.TwitchUsername} {(message.WebLogin ? "via web" : "via TTS app")}."); _logger.Information($"Logged in as {_user.TwitchUsername} {(message.WebLogin ? "via web" : "via TTS app")}.");
@ -56,13 +69,14 @@ namespace TwitchChatTTS.Hermes.Socket.Handlers
await client.FetchRedemptions(); await client.FetchRedemptions();
await client.FetchPermissions(); await client.FetchPermissions();
if (_user.NightbotConnection != null) { if (_user.NightbotConnection != null)
{
_nightbot.Initialize(_user.NightbotConnection.ClientId, _user.NightbotConnection.AccessToken); _nightbot.Initialize(_user.NightbotConnection.ClientId, _user.NightbotConnection.AccessToken);
var span = DateTime.Now - _user.NightbotConnection.ExpiresAt; var span = _user.NightbotConnection.ExpiresAt - DateTime.Now;
var timeLeft = span.TotalDays >= 2 ? Math.Floor(span.TotalDays) + " days" : (span.TotalHours >= 2 ? Math.Floor(span.TotalHours) + " hours" : Math.Floor(span.TotalMinutes) + " minutes"); var timeLeft = span.Days >= 2 ? span.Days + " days" : (span.Hours >= 2 ? span.Hours + " hours" : span.Minutes + " minutes");
if (span.TotalDays >= 3) if (span.Days >= 3)
_logger.Information($"Nightbot connection has {timeLeft} before it is revoked."); _logger.Information($"Nightbot connection has {timeLeft} before it is revoked.");
else if (span.TotalMinutes >= 0) else if (span.Minutes >= 0)
_logger.Warning($"Nightbot connection has {timeLeft} before it is revoked. Refreshing the token is soon required."); _logger.Warning($"Nightbot connection has {timeLeft} before it is revoked. Refreshing the token is soon required.");
else else
_logger.Error("Nightbot connection has its permissions revoked. Refresh the token. Anything related to Nightbot from this application will not work."); _logger.Error("Nightbot connection has its permissions revoked. Refresh the token. Anything related to Nightbot from this application will not work.");

View File

@ -45,6 +45,8 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
} }
public async Task Execute(TwitchWebsocketClient sender, object data) public async Task Execute(TwitchWebsocketClient sender, object data)
{
Task.Run(async () =>
{ {
if (sender == null) if (sender == null)
return; return;
@ -64,7 +66,8 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
} }
var d = JsonSerializer.Deserialize(message.Event.ToString()!, type, _options); var d = JsonSerializer.Deserialize(message.Event.ToString()!, type, _options);
await handler.Execute(sender, d); Task.Run(async () => await handler.Execute(sender, d));
});
} }
} }
} }

View File

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

View File

@ -144,7 +144,9 @@ namespace TwitchChatTTS.Twitch.Socket
}; };
} }
protected override async Task OnResponseReceived(TwitchWebsocketMessage? message) protected override Task OnResponseReceived(TwitchWebsocketMessage? message)
{
return Task.Run(async () =>
{ {
if (message == null || message.Metadata == null) if (message == null || message.Metadata == null)
{ {
@ -176,7 +178,8 @@ namespace TwitchChatTTS.Twitch.Socket
_logger.Warning("Twitch websocket message payload is null."); _logger.Warning("Twitch websocket message payload is null.");
return; return;
} }
await Task.Run(async () => await handler.Execute(this, data)); await handler.Execute(this, data);
});
} }
public async Task Send<T>(string type, T data) public async Task Send<T>(string type, T data)