using System.Text.Json.Serialization; using System.Text.RegularExpressions; using HermesSocketLibrary.Requests.Messages; namespace TwitchChatTTS { public class User { // Hermes user id public string HermesUserId { get; set; } public string HermesUsername { get; set; } public long TwitchUserId { get; set; } public string TwitchUsername { get; set; } public string SevenEmoteSetId { get; set; } public string DefaultTTSVoice { get; set; } // voice id -> voice name public IDictionary VoicesAvailable { get => _voicesAvailable; set { _voicesAvailable = value; WordFilterRegex = GenerateEnabledVoicesRegex(); } } // chatter/twitch id -> voice name public IDictionary VoicesSelected { get; set; } // voice names public HashSet VoicesEnabled { get => _voicesEnabled; set { _voicesEnabled = value; WordFilterRegex = GenerateEnabledVoicesRegex(); } } public IDictionary ChatterFilters { get; set; } public IList RegexFilters { get; set; } [JsonIgnore] public Regex? WordFilterRegex { get; set; } private IDictionary _voicesAvailable; private HashSet _voicesEnabled; public User() { } private Regex? GenerateEnabledVoicesRegex() { if (VoicesAvailable == null || VoicesAvailable.Count() <= 0) return null; var enabledVoicesString = string.Join("|", VoicesAvailable.Where(v => VoicesEnabled == null || !VoicesEnabled.Any() || VoicesEnabled.Contains(v.Value)).Select(v => v.Value)); return new Regex($@"\b({enabledVoicesString})\:(.*?)(?=\Z|\b(?:{enabledVoicesString})\:)", RegexOptions.IgnoreCase); } } }