2024-06-16 20:19:31 -04:00
|
|
|
using CommonSocketLibrary.Abstract;
|
|
|
|
using CommonSocketLibrary.Common;
|
|
|
|
using HermesSocketLibrary.Socket.Data;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Serilog;
|
|
|
|
using TwitchChatTTS.Chat.Commands.Parameters;
|
|
|
|
using TwitchLib.Client.Models;
|
|
|
|
|
|
|
|
namespace TwitchChatTTS.Chat.Commands
|
|
|
|
{
|
|
|
|
public class TTSCommand : ChatCommand
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
private readonly User _user;
|
|
|
|
private readonly SocketClient<WebSocketMessage> _hermesClient;
|
|
|
|
private readonly ILogger _logger;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
|
|
|
public TTSCommand(
|
|
|
|
[FromKeyedServices("parameter-ttsvoicename")] ChatCommandParameter ttsVoiceParameter,
|
|
|
|
[FromKeyedServices("parameter-unvalidated")] ChatCommandParameter unvalidatedParameter,
|
2024-06-24 18:11:36 -04:00
|
|
|
User user,
|
|
|
|
[FromKeyedServices("hermes")] SocketClient<WebSocketMessage> hermesClient,
|
2024-06-16 20:19:31 -04:00
|
|
|
ILogger logger
|
|
|
|
) : base("tts", "Various tts commands.")
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
_user = user;
|
|
|
|
_hermesClient = hermesClient;
|
2024-06-16 20:19:31 -04:00
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
AddParameter(ttsVoiceParameter);
|
|
|
|
AddParameter(unvalidatedParameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<bool> CheckPermissions(ChatMessage message, long broadcasterId)
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
return message.IsBroadcaster;
|
2024-06-16 20:19:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task Execute(IList<string> args, ChatMessage message, long broadcasterId)
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
if (_user == null || _user.VoicesAvailable == null)
|
2024-06-16 20:19:31 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
var voiceName = args[0].ToLower();
|
2024-06-24 18:11:36 -04:00
|
|
|
var voiceId = _user.VoicesAvailable.FirstOrDefault(v => v.Value.ToLower() == voiceName).Key;
|
2024-06-16 20:19:31 -04:00
|
|
|
var action = args[1].ToLower();
|
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
switch (action)
|
|
|
|
{
|
2024-06-16 20:19:31 -04:00
|
|
|
case "enable":
|
2024-06-24 18:11:36 -04:00
|
|
|
await _hermesClient.Send(3, new RequestMessage()
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
|
|
|
Type = "update_tts_voice_state",
|
|
|
|
Data = new Dictionary<string, object>() { { "voice", voiceId }, { "state", true } }
|
|
|
|
});
|
2024-06-24 18:11:36 -04:00
|
|
|
break;
|
2024-06-16 20:19:31 -04:00
|
|
|
case "disable":
|
2024-06-24 18:11:36 -04:00
|
|
|
await _hermesClient.Send(3, new RequestMessage()
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
|
|
|
Type = "update_tts_voice_state",
|
|
|
|
Data = new Dictionary<string, object>() { { "voice", voiceId }, { "state", false } }
|
|
|
|
});
|
2024-06-24 18:11:36 -04:00
|
|
|
break;
|
2024-06-16 20:19:31 -04:00
|
|
|
case "remove":
|
2024-06-24 18:11:36 -04:00
|
|
|
await _hermesClient.Send(3, new RequestMessage()
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
|
|
|
Type = "delete_tts_voice",
|
|
|
|
Data = new Dictionary<string, object>() { { "voice", voiceId } }
|
|
|
|
});
|
2024-06-24 18:11:36 -04:00
|
|
|
break;
|
2024-06-16 20:19:31 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
_logger.Information($"Added a new TTS voice [voice: {voiceName}][invoker: {message.Username}][id: {message.UserId}]");
|
2024-06-16 20:19:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|