2024-03-15 08:27:35 -04:00
|
|
|
using CommonSocketLibrary.Abstract;
|
|
|
|
using CommonSocketLibrary.Common;
|
|
|
|
using HermesSocketLibrary.Socket.Data;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-06-16 20:19:31 -04:00
|
|
|
using Serilog;
|
2024-03-15 08:27:35 -04:00
|
|
|
using TwitchChatTTS.Chat.Commands.Parameters;
|
|
|
|
using TwitchLib.Client.Models;
|
|
|
|
|
|
|
|
namespace TwitchChatTTS.Chat.Commands
|
|
|
|
{
|
|
|
|
public class AddTTSVoiceCommand : ChatCommand
|
|
|
|
{
|
|
|
|
private IServiceProvider _serviceProvider;
|
2024-06-16 20:19:31 -04:00
|
|
|
private ILogger _logger;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
|
|
|
public AddTTSVoiceCommand(
|
|
|
|
[FromKeyedServices("parameter-unvalidated")] ChatCommandParameter ttsVoiceParameter,
|
|
|
|
IServiceProvider serviceProvider,
|
2024-06-16 20:19:31 -04:00
|
|
|
ILogger logger
|
|
|
|
) : base("addttsvoice", "Select a TTS voice as the default for that user.")
|
|
|
|
{
|
2024-03-15 08:27:35 -04:00
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
AddParameter(ttsVoiceParameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<bool> CheckPermissions(ChatMessage message, long broadcasterId)
|
|
|
|
{
|
2024-06-16 20:19:31 -04:00
|
|
|
return message.IsModerator || message.IsBroadcaster;
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task Execute(IList<string> args, ChatMessage message, long broadcasterId)
|
|
|
|
{
|
|
|
|
var client = _serviceProvider.GetRequiredKeyedService<SocketClient<WebSocketMessage>>("hermes");
|
|
|
|
if (client == null)
|
|
|
|
return;
|
|
|
|
var context = _serviceProvider.GetRequiredService<User>();
|
|
|
|
if (context == null || context.VoicesAvailable == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var voiceName = args.First();
|
|
|
|
var voiceNameLower = voiceName.ToLower();
|
|
|
|
var exists = context.VoicesAvailable.Any(v => v.Value.ToLower() == voiceNameLower);
|
|
|
|
if (exists)
|
|
|
|
return;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
|
|
|
await client.Send(3, new RequestMessage()
|
|
|
|
{
|
2024-03-15 08:27:35 -04:00
|
|
|
Type = "create_tts_voice",
|
2024-06-16 20:19:31 -04:00
|
|
|
Data = new Dictionary<string, object>() { { "voice", voiceName } }
|
2024-03-15 08:27:35 -04:00
|
|
|
});
|
2024-06-16 20:19:31 -04:00
|
|
|
_logger.Information($"Added a new TTS voice by {message.Username} (id: {message.UserId}): {voiceName}.");
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|