Fixed adding, modifying and fetching TTS filters.

This commit is contained in:
Tom
2025-01-16 01:12:49 +00:00
parent 5fc1b5f942
commit b8de9532e2
4 changed files with 26 additions and 6 deletions

View File

@ -56,7 +56,7 @@ namespace TwitchChatTTS.Hermes.Socket.Handlers
{
try
{
var re = new Regex(filter.Search!, RegexOptions.Compiled);
var re = new Regex(filter.Search!, ((RegexOptions) filter.Flag) | RegexOptions.Compiled);
re.Match(string.Empty);
filter.Regex = re;
}

View File

@ -1,4 +1,5 @@
using System.Text.Json;
using System.Text.RegularExpressions;
using HermesSocketLibrary.Requests.Messages;
using Serilog;
@ -33,6 +34,14 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
return;
}
try
{
var re = new Regex(filter.Search!, ((RegexOptions)filter.Flag) | RegexOptions.Compiled);
re.Match(string.Empty);
filter.Regex = re;
}
catch (Exception) { }
_logger.Debug($"Filter data [filter id: {filter.Id}][search: {filter.Search}][replace: {filter.Replace}]");
_user.RegexFilters.Add(filter);
_logger.Information($"Filter has been created [filter id: {filter.Id}]");

View File

@ -33,7 +33,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
{
try
{
var re = new Regex(filter.Search!, RegexOptions.Compiled);
var re = new Regex(filter.Search!, ((RegexOptions) filter.Flag) | RegexOptions.Compiled);
re.Match(string.Empty);
filter.Regex = re;
}

View File

@ -1,4 +1,5 @@
using System.Text.Json;
using System.Text.RegularExpressions;
using HermesSocketLibrary.Requests.Messages;
using Serilog;
@ -28,15 +29,25 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
}
_logger.Debug($"Filter data [filter id: {filter.Id}][search: {filter.Search}][group id: {filter.Replace}]");
var previous = _user.RegexFilters.FirstOrDefault(f => f.Id == filter.Id);
if (previous == null)
var current = _user.RegexFilters.FirstOrDefault(f => f.Id == filter.Id);
if (current == null)
{
_logger.Warning($"TTS Filter doest exist by id [filter id: {filter.Id}]");
return;
}
previous.Search = filter.Search;
previous.Replace = filter.Replace;
current.Search = filter.Search;
current.Replace = filter.Replace;
current.Flag = filter.Flag;
try
{
var re = new Regex(current.Search!, ((RegexOptions)current.Flag) | RegexOptions.Compiled);
re.Match(string.Empty);
current.Regex = re;
}
catch (Exception) { }
_logger.Information($"Filter has been updated [filter id: {filter.Id}]");
}
}