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;
}
}