2024-06-16 20:19:31 -04:00
|
|
|
using Serilog;
|
2024-07-16 00:48:55 -04:00
|
|
|
using TwitchChatTTS.Hermes.Socket;
|
2024-03-15 08:27:35 -04:00
|
|
|
using TwitchLib.Client.Models;
|
2024-07-19 12:56:41 -04:00
|
|
|
using static TwitchChatTTS.Chat.Commands.TTSCommands;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
|
|
|
namespace TwitchChatTTS.Chat.Commands
|
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
public class VoiceCommand : IChatCommand
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
private readonly User _user;
|
|
|
|
private readonly ILogger _logger;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
public VoiceCommand(User user, ILogger logger)
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
_user = user;
|
2024-03-15 08:27:35 -04:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
public string Name => "voice";
|
|
|
|
|
|
|
|
public void Build(ICommandBuilder builder)
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
builder.CreateCommandTree(Name, b =>
|
|
|
|
{
|
|
|
|
b.CreateVoiceNameParameter("voiceName", true)
|
|
|
|
.CreateCommand(new TTSVoiceSelector(_user, _logger));
|
|
|
|
});
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
private sealed class TTSVoiceSelector : IChatPartialCommand
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
private readonly User _user;
|
|
|
|
private readonly ILogger _logger;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
public bool AcceptCustomPermission { get => true; }
|
2024-03-15 08:27:35 -04:00
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
public TTSVoiceSelector(User user, ILogger logger)
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
_user = user;
|
|
|
|
_logger = logger;
|
2024-07-16 00:48:55 -04:00
|
|
|
}
|
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
|
|
|
|
public bool CheckDefaultPermissions(ChatMessage message)
|
2024-07-16 00:48:55 -04:00
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
return message.IsModerator || message.IsBroadcaster || message.IsSubscriber || message.Bits >= 100;
|
2024-07-16 00:48:55 -04:00
|
|
|
}
|
2024-07-19 12:56:41 -04:00
|
|
|
|
|
|
|
public async Task Execute(IDictionary<string, string> values, ChatMessage message, HermesSocketClient client)
|
2024-07-16 00:48:55 -04:00
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
if (_user == null || _user.VoicesSelected == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
long chatterId = long.Parse(message.UserId);
|
|
|
|
var voiceName = values["voiceName"];
|
|
|
|
var voiceNameLower = voiceName.ToLower();
|
|
|
|
var voice = _user.VoicesAvailable.First(v => v.Value.ToLower() == voiceNameLower);
|
|
|
|
|
|
|
|
if (_user.VoicesSelected.ContainsKey(chatterId))
|
|
|
|
{
|
|
|
|
await client.UpdateTTSUser(chatterId, voice.Key);
|
|
|
|
_logger.Debug($"Sent request to create chat TTS voice [voice: {voice.Value}][username: {message.Username}][reason: command]");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
await client.CreateTTSUser(chatterId, voice.Key);
|
|
|
|
_logger.Debug($"Sent request to update chat TTS voice [voice: {voice.Value}][username: {message.Username}][reason: command]");
|
|
|
|
}
|
2024-07-06 23:42:33 -04:00
|
|
|
}
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|