2024-07-19 12:56:41 -04:00
|
|
|
using CommonSocketLibrary.Abstract;
|
|
|
|
using CommonSocketLibrary.Common;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Serilog;
|
|
|
|
using TwitchChatTTS.Hermes.Socket;
|
|
|
|
using TwitchChatTTS.OBS.Socket;
|
2024-08-06 15:29:29 -04:00
|
|
|
using TwitchChatTTS.Twitch.Socket;
|
2024-08-04 19:46:10 -04:00
|
|
|
using TwitchChatTTS.Twitch.Socket.Messages;
|
2024-07-19 12:56:41 -04:00
|
|
|
using static TwitchChatTTS.Chat.Commands.TTSCommands;
|
|
|
|
|
|
|
|
namespace TwitchChatTTS.Chat.Commands
|
|
|
|
{
|
|
|
|
public class RefreshCommand : IChatCommand
|
|
|
|
{
|
|
|
|
private readonly OBSSocketClient _obs;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public string Name => "refresh";
|
|
|
|
|
|
|
|
public RefreshCommand(
|
|
|
|
[FromKeyedServices("obs")] SocketClient<WebSocketMessage> obs,
|
|
|
|
ILogger logger
|
|
|
|
)
|
|
|
|
{
|
|
|
|
_obs = (obs as OBSSocketClient)!;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Build(ICommandBuilder builder)
|
|
|
|
{
|
|
|
|
builder.CreateCommandTree(Name, b =>
|
|
|
|
{
|
|
|
|
b.CreateStaticInputParameter("tts_voice_enabled", b => b.CreateCommand(new RefreshTTSVoicesEnabled()))
|
|
|
|
.CreateStaticInputParameter("word_filters", b => b.CreateCommand(new RefreshTTSWordFilters()))
|
|
|
|
.CreateStaticInputParameter("selected_voices", b => b.CreateCommand(new RefreshTTSChatterVoices()))
|
|
|
|
.CreateStaticInputParameter("default_voice", b => b.CreateCommand(new RefreshTTSDefaultVoice()))
|
|
|
|
.CreateStaticInputParameter("redemptions", b => b.CreateCommand(new RefreshRedemptions()))
|
|
|
|
.CreateStaticInputParameter("obs_cache", b => b.CreateCommand(new RefreshObs(_obs, _logger)))
|
|
|
|
.CreateStaticInputParameter("permissions", b => b.CreateCommand(new RefreshPermissions()));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private sealed class RefreshTTSVoicesEnabled : IChatPartialCommand
|
|
|
|
{
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public async Task Execute(IDictionary<string, string> values, ChannelChatMessage message, HermesSocketClient hermes)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-06 15:29:29 -04:00
|
|
|
await hermes.FetchEnabledTTSVoices();
|
2024-07-19 12:56:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private sealed class RefreshTTSWordFilters : IChatPartialCommand
|
|
|
|
{
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public async Task Execute(IDictionary<string, string> values, ChannelChatMessage message, HermesSocketClient hermes)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-06 15:29:29 -04:00
|
|
|
await hermes.FetchTTSWordFilters();
|
2024-07-19 12:56:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private sealed class RefreshTTSChatterVoices : IChatPartialCommand
|
|
|
|
{
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public async Task Execute(IDictionary<string, string> values, ChannelChatMessage message, HermesSocketClient hermes)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-06 15:29:29 -04:00
|
|
|
await hermes.FetchTTSChatterVoices();
|
2024-07-19 12:56:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private sealed class RefreshTTSDefaultVoice : IChatPartialCommand
|
|
|
|
{
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public async Task Execute(IDictionary<string, string> values, ChannelChatMessage message, HermesSocketClient hermes)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-06 15:29:29 -04:00
|
|
|
await hermes.FetchDefaultTTSVoice();
|
2024-07-19 12:56:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private sealed class RefreshRedemptions : IChatPartialCommand
|
|
|
|
{
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public async Task Execute(IDictionary<string, string> values, ChannelChatMessage message, HermesSocketClient hermes)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-06 15:29:29 -04:00
|
|
|
await hermes.FetchRedemptions();
|
2024-07-19 12:56:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private sealed class RefreshObs : IChatPartialCommand
|
|
|
|
{
|
|
|
|
private readonly OBSSocketClient _obsManager;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public RefreshObs(OBSSocketClient obsManager, ILogger logger)
|
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
_obsManager = obsManager;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public async Task Execute(IDictionary<string, string> values, ChannelChatMessage message, HermesSocketClient hermes)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
|
|
|
_obsManager.ClearCache();
|
|
|
|
_logger.Information("Cleared the cache used for OBS.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private sealed class RefreshPermissions : IChatPartialCommand
|
|
|
|
{
|
|
|
|
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public async Task Execute(IDictionary<string, string> values, ChannelChatMessage message, HermesSocketClient hermes)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-06 15:29:29 -04:00
|
|
|
await hermes.FetchPermissions();
|
2024-07-19 12:56:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|