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
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
private readonly User _user;
|
|
|
|
private readonly SocketClient<WebSocketMessage> _hermesClient;
|
|
|
|
private readonly ILogger _logger;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
|
|
|
public AddTTSVoiceCommand(
|
2024-06-24 18:11:36 -04:00
|
|
|
User user,
|
2024-03-15 08:27:35 -04:00
|
|
|
[FromKeyedServices("parameter-unvalidated")] ChatCommandParameter ttsVoiceParameter,
|
2024-06-24 18:11:36 -04:00
|
|
|
[FromKeyedServices("hermes")] SocketClient<WebSocketMessage> hermesClient,
|
2024-06-16 20:19:31 -04:00
|
|
|
ILogger logger
|
|
|
|
) : base("addttsvoice", "Select a TTS voice as the default for that user.")
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
_user = user;
|
|
|
|
_hermesClient = hermesClient;
|
2024-03-15 08:27:35 -04:00
|
|
|
_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)
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
//var HermesClient = _serviceProvider.GetRequiredKeyedService<SocketClient<WebSocketMessage>>("hermes");
|
|
|
|
if (_hermesClient == null)
|
2024-03-15 08:27:35 -04:00
|
|
|
return;
|
2024-06-24 18:11:36 -04:00
|
|
|
if (_user == null || _user.VoicesAvailable == null)
|
2024-03-15 08:27:35 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
var voiceName = args.First();
|
|
|
|
var voiceNameLower = voiceName.ToLower();
|
2024-06-24 18:11:36 -04:00
|
|
|
var exists = _user.VoicesAvailable.Any(v => v.Value.ToLower() == voiceNameLower);
|
2024-03-15 08:27:35 -04:00
|
|
|
if (exists)
|
|
|
|
return;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
await _hermesClient.Send(3, new RequestMessage()
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
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-24 18:11:36 -04:00
|
|
|
_logger.Information($"Added a new TTS voice by {message.Username} [voice: {voiceName}][id: {message.UserId}]");
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|