Twitch connection now relies on events to connect. Added logging for when TTS filter is not a regex. Minor code clean up.

This commit is contained in:
Tom
2025-01-19 01:23:29 +00:00
parent 86fc6bc24d
commit cbdca1c008
9 changed files with 102 additions and 68 deletions

View File

@ -53,19 +53,24 @@ namespace TwitchChatTTS.Hermes.Socket.Handlers
_user.VoicesEnabled = new HashSet<string>(message.EnabledTTSVoices);
_user.TwitchConnection = message.Connections.FirstOrDefault(c => c.Default && c.Type == "twitch");
_user.NightbotConnection = message.Connections.FirstOrDefault(c => c.Default && c.Type == "nightbot");
_bus.Send(this, "twitch id", _user.TwitchUserId);
if (_user.TwitchConnection != null)
{
_logger.Information("Twitch connection: " + _user.TwitchConnection.Name + " / " + _user.TwitchConnection.AccessToken);
}
var filters = message.WordFilters.Where(f => f.Search != null && f.Replace != null).ToList();
foreach (var filter in filters)
{
try
{
var re = new Regex(filter.Search, ((RegexOptions) filter.Flag) | RegexOptions.Compiled);
var re = new Regex(filter.Search, ((RegexOptions)filter.Flag) | RegexOptions.Compiled);
re.Match(string.Empty);
filter.Regex = re;
}
catch (Exception) { }
catch (Exception)
{
_logger.Warning($"Failed to create a regular expression for a TTS filter [filter id: {filter.Search}]");
}
}
_user.RegexFilters = filters;
@ -93,6 +98,7 @@ namespace TwitchChatTTS.Hermes.Socket.Handlers
}
_logger.Information("TTS is now ready.");
_bus.Send(this, "tts_connected", _user);
client.Ready = true;
}
}

View File

@ -247,7 +247,7 @@ namespace TwitchChatTTS.Hermes.Socket
public void Initialize()
{
_logger.Information("Initializing Hermes websocket client.");
_logger.Information("Initializing Tom to Speech websocket client.");
OnConnected += async (sender, e) =>
{
@ -257,7 +257,7 @@ namespace TwitchChatTTS.Hermes.Socket
return;
Connected = true;
}
_logger.Information("Hermes websocket client connected.");
_logger.Information("Tom to Speech websocket client connected.");
_heartbeatTimer.Enabled = true;
LastHeartbeatReceived = DateTime.UtcNow;
@ -281,7 +281,7 @@ namespace TwitchChatTTS.Hermes.Socket
LoggedIn = false;
Ready = false;
_logger.Warning("Hermes websocket client disconnected.");
_logger.Warning("Tom to Speech websocket client disconnected.");
_heartbeatTimer.Enabled = false;
await Reconnect(_backoff);
@ -396,7 +396,7 @@ namespace TwitchChatTTS.Hermes.Socket
}
catch (Exception ex)
{
_logger.Error(ex, "Failed to send a heartbeat back to the Hermes websocket server.");
_logger.Error(ex, "Failed to send a heartbeat back to the Tom to Speech websocket server.");
}
}
else if (signalTime - LastHeartbeatReceived > TimeSpan.FromSeconds(120))
@ -407,7 +407,7 @@ namespace TwitchChatTTS.Hermes.Socket
}
catch (Exception ex)
{
_logger.Error(ex, "Failed to disconnect from Hermes websocket server.");
_logger.Error(ex, "Failed to disconnect from Tom to Speech websocket server.");
Ready = false;
LoggedIn = false;
Connected = false;
@ -423,7 +423,7 @@ namespace TwitchChatTTS.Hermes.Socket
{
if (!Connected)
{
_logger.Warning("Hermes websocket client is not connected. Not sending a message.");
_logger.Warning("Tom to Speech websocket client is not connected. Not sending a message.");
return;
}

View File

@ -48,7 +48,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
}
catch (Exception)
{
_logger.Warning($"Failed to generate a Regular Expression using '{filter.Search}' [filter id: {filter.Id}]");
_logger.Warning($"Failed to create a regular expression for a TTS filter [filter id: {filter.Search}]");
}
_logger.Debug($"Filter data [filter id: {filter.Id}][search: {filter.Search}][replace: {filter.Replace}]");

View File

@ -33,11 +33,14 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
{
try
{
var re = new Regex(filter.Search, ((RegexOptions) filter.Flag) | RegexOptions.Compiled);
var re = new Regex(filter.Search, ((RegexOptions)filter.Flag) | RegexOptions.Compiled);
re.Match(string.Empty);
filter.Regex = re;
}
catch (Exception) { }
catch (Exception)
{
_logger.Warning($"Failed to create a regular expression for a TTS filter [filter id: {filter.Search}]");
}
}
_user.RegexFilters = filters;
_logger.Information($"TTS word filters [count: {_user.RegexFilters.Count}] have been refreshed.");

View File

@ -52,7 +52,10 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
re.Match(string.Empty);
current.Regex = re;
}
catch (Exception) { }
catch (Exception)
{
_logger.Warning($"Failed to create a regular expression for a TTS filter [filter id: {filter.Search}]");
}
_logger.Information($"Filter has been updated [filter id: {filter.Id}]");
}