using System.Collections.Concurrent; namespace TwitchChatTTS.Seven { public class EmoteCounter { public IDictionary> Counters { get; set; } public EmoteCounter() { Counters = new ConcurrentDictionary>(); } public void Add(long userId, IEnumerable emoteIds) { foreach (var emote in emoteIds) { if (Counters.TryGetValue(emote, out IDictionary? subcounters)) { if (subcounters.TryGetValue(userId, out int counter)) subcounters[userId] = counter + 1; else subcounters.Add(userId, 1); } else { Counters.Add(emote, new ConcurrentDictionary()); Counters[emote].Add(userId, 1); } } } public void Clear() { Counters.Clear(); } public int Get(long userId, string emoteId) { if (Counters.TryGetValue(emoteId, out IDictionary? subcounters)) { if (subcounters.TryGetValue(userId, out int counter)) return counter; } return -1; } } public class EmoteDatabase { private IDictionary Emotes { get; } public EmoteDatabase() { Emotes = new Dictionary(); } public void Add(string emoteName, string emoteId) { if (Emotes.ContainsKey(emoteName)) Emotes[emoteName] = emoteId; else Emotes.Add(emoteName, emoteId); } public void Clear() { Emotes.Clear(); } public string? Get(string emoteName) { return Emotes.TryGetValue(emoteName, out string? emoteId) ? emoteId : null; } public void Remove(string emoteName) { if (Emotes.ContainsKey(emoteName)) Emotes.Remove(emoteName); } } public class EmoteSet { public string Id { get; set; } public string Name { get; set; } public int Flags { get; set; } public bool Immutable { get; set; } public bool Privileged { get; set; } public IList Emotes { get; set; } public int EmoteCount { get; set; } public int Capacity { get; set; } } public class Emote { public string Id { get; set; } public string Name { get; set; } public int Flags { get; set; } } }