using Serilog; using TwitchChatTTS.Twitch.Redemptions; using TwitchLib.Client.Models; namespace TwitchChatTTS.Chat.Commands { public class RefreshTTSDataCommand : ChatCommand { private readonly User _user; private readonly RedemptionManager _redemptionManager; private readonly HermesApiClient _hermesApi; private readonly ILogger _logger; public RefreshTTSDataCommand(User user, RedemptionManager redemptionManager, HermesApiClient hermesApi, ILogger logger) : base("refresh", "Refreshes certain TTS related data on the client.") { _user = user; _redemptionManager = redemptionManager; _hermesApi = hermesApi; _logger = logger; } public override async Task CheckPermissions(ChatMessage message, long broadcasterId) { return message.IsModerator || message.IsBroadcaster; } public override async Task Execute(IList args, ChatMessage message, long broadcasterId) { var service = args.FirstOrDefault(); if (service == null) return; switch (service) { case "tts_voice_enabled": var voicesEnabled = await _hermesApi.FetchTTSEnabledVoices(); if (voicesEnabled == null || !voicesEnabled.Any()) _user.VoicesEnabled = new HashSet(["Brian"]); else _user.VoicesEnabled = new HashSet(voicesEnabled.Select(v => v)); _logger.Information($"{_user.VoicesEnabled.Count} TTS voices have been enabled."); break; case "word_filters": var wordFilters = await _hermesApi.FetchTTSWordFilters(); _user.RegexFilters = wordFilters.ToList(); _logger.Information($"{_user.RegexFilters.Count()} TTS word filters."); break; case "username_filters": var usernameFilters = await _hermesApi.FetchTTSUsernameFilters(); _user.ChatterFilters = usernameFilters.ToDictionary(e => e.Username, e => e); _logger.Information($"{_user.ChatterFilters.Where(f => f.Value.Tag == "blacklisted").Count()} username(s) have been blocked."); _logger.Information($"{_user.ChatterFilters.Where(f => f.Value.Tag == "priority").Count()} user(s) have been prioritized."); break; case "default_voice": _user.DefaultTTSVoice = await _hermesApi.FetchTTSDefaultVoice(); _logger.Information("TTS Default Voice: " + _user.DefaultTTSVoice); break; case "redemptions": var redemptionActions = await _hermesApi.FetchRedeemableActions(); var redemptions = await _hermesApi.FetchRedemptions(); _redemptionManager.Initialize(redemptions, redemptionActions.ToDictionary(a => a.Name, a => a)); _logger.Information($"Redemption Manager has been refreshed with {redemptionActions.Count()} actions & {redemptions.Count()} redemptions."); break; } } } }