2024-03-15 08:27:35 -04:00
|
|
|
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;
|
2024-07-16 00:48:55 -04:00
|
|
|
using TwitchChatTTS.Hermes.Socket;
|
2024-03-15 08:27:35 -04:00
|
|
|
using TwitchLib.Client.Models;
|
|
|
|
|
|
|
|
namespace TwitchChatTTS.Chat.Commands
|
|
|
|
{
|
|
|
|
public class RemoveTTSVoiceCommand : ChatCommand
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
private readonly User _user;
|
2024-06-16 20:19:31 -04:00
|
|
|
private ILogger _logger;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
2024-07-12 13:36:09 -04:00
|
|
|
public new bool DefaultPermissionsOverwrite { get => true; }
|
|
|
|
|
2024-03-15 08:27:35 -04:00
|
|
|
public RemoveTTSVoiceCommand(
|
|
|
|
[FromKeyedServices("parameter-unvalidated")] ChatCommandParameter ttsVoiceParameter,
|
2024-06-24 18:11:36 -04:00
|
|
|
User user,
|
2024-06-16 20:19:31 -04:00
|
|
|
ILogger logger
|
|
|
|
) : base("removettsvoice", "Select a TTS voice as the default for that user.")
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
_user = user;
|
2024-03-15 08:27:35 -04:00
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
AddParameter(ttsVoiceParameter);
|
|
|
|
}
|
|
|
|
|
2024-07-16 00:48:55 -04:00
|
|
|
public override async Task<bool> CheckDefaultPermissions(ChatMessage message)
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-07-06 23:42:33 -04:00
|
|
|
return false;
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
|
2024-07-16 00:48:55 -04:00
|
|
|
public override async Task Execute(IList<string> args, ChatMessage message, HermesSocketClient client)
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
if (_user == null || _user.VoicesAvailable == null)
|
2024-07-16 00:48:55 -04:00
|
|
|
{
|
|
|
|
_logger.Debug($"Voices available are not loaded [chatter: {message.Username}][chatter id: {message.UserId}]");
|
2024-03-15 08:27:35 -04:00
|
|
|
return;
|
2024-07-16 00:48:55 -04:00
|
|
|
}
|
2024-03-15 08:27:35 -04:00
|
|
|
|
|
|
|
var voiceName = args.First().ToLower();
|
2024-06-24 18:11:36 -04:00
|
|
|
var exists = _user.VoicesAvailable.Any(v => v.Value.ToLower() == voiceName);
|
2024-03-15 08:27:35 -04:00
|
|
|
if (!exists)
|
2024-07-16 00:48:55 -04:00
|
|
|
{
|
|
|
|
_logger.Debug($"Voice does not exist [voice: {voiceName}][chatter: {message.Username}][chatter id: {message.UserId}]");
|
2024-03-15 08:27:35 -04:00
|
|
|
return;
|
2024-07-16 00:48:55 -04:00
|
|
|
}
|
2024-06-16 20:19:31 -04:00
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
var voiceId = _user.VoicesAvailable.FirstOrDefault(v => v.Value.ToLower() == voiceName).Key;
|
2024-07-16 00:48:55 -04:00
|
|
|
await client.DeleteTTSVoice(voiceId);
|
|
|
|
_logger.Information($"Deleted a TTS voice [voice: {voiceName}][chatter: {message.Username}][chatter id: {message.UserId}]");
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|