2024-06-16 20:19:31 -04:00
|
|
|
using Serilog;
|
2024-08-12 01:44:31 -04:00
|
|
|
using TwitchChatTTS.Chat.Soeech;
|
2024-07-16 00:48:55 -04:00
|
|
|
using TwitchChatTTS.Hermes.Socket;
|
2024-08-06 15:29:29 -04:00
|
|
|
using TwitchChatTTS.Twitch.Socket;
|
2024-08-04 19:46:10 -04:00
|
|
|
using TwitchChatTTS.Twitch.Socket.Messages;
|
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 SkipCommand : IChatCommand
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
private readonly TTSPlayer _player;
|
2024-08-04 19:46:10 -04:00
|
|
|
private readonly AudioPlaybackEngine _playback;
|
2024-06-24 18:11:36 -04:00
|
|
|
private readonly ILogger _logger;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
2024-08-04 19:46:10 -04:00
|
|
|
public SkipCommand(TTSPlayer player, AudioPlaybackEngine playback, ILogger logger)
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
2024-08-04 19:46:10 -04:00
|
|
|
_player = player;
|
|
|
|
_playback = playback;
|
2024-03-15 08:27:35 -04:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
public string Name => "skip";
|
|
|
|
|
|
|
|
public void Build(ICommandBuilder builder)
|
|
|
|
{
|
|
|
|
builder.CreateCommandTree(Name, b =>
|
|
|
|
{
|
|
|
|
b.CreateStaticInputParameter("all", b =>
|
|
|
|
{
|
2024-08-04 19:46:10 -04:00
|
|
|
b.CreateCommand(new TTSPlayerSkipAllCommand(_player, _playback, _logger));
|
|
|
|
}).CreateCommand(new TTSPlayerSkipCommand(_player, _playback, _logger));
|
2024-07-19 12:56:41 -04:00
|
|
|
});
|
2024-08-04 19:46:10 -04:00
|
|
|
builder.CreateCommandTree("skipall", b =>
|
|
|
|
{
|
|
|
|
b.CreateCommand(new TTSPlayerSkipAllCommand(_player, _playback, _logger));
|
2024-07-19 12:56:41 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private sealed class TTSPlayerSkipCommand : IChatPartialCommand
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-08-04 19:46:10 -04:00
|
|
|
private readonly TTSPlayer _player;
|
|
|
|
private readonly AudioPlaybackEngine _playback;
|
2024-07-19 12:56:41 -04:00
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
2024-08-04 19:46:10 -04:00
|
|
|
public TTSPlayerSkipCommand(TTSPlayer player, AudioPlaybackEngine playback, ILogger logger)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-04 19:46:10 -04:00
|
|
|
_player = player;
|
|
|
|
_playback = playback;
|
2024-07-19 12:56:41 -04:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public async Task Execute(IDictionary<string, string> values, ChannelChatMessage message, HermesSocketClient hermes)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-04 19:46:10 -04:00
|
|
|
if (_player.Playing == null)
|
2024-07-19 12:56:41 -04:00
|
|
|
return;
|
|
|
|
|
2024-08-04 19:46:10 -04:00
|
|
|
_playback.RemoveMixerInput(_player.Playing.Audio!);
|
|
|
|
_player.Playing = null;
|
2024-07-19 12:56:41 -04:00
|
|
|
|
|
|
|
_logger.Information("Skipped current tts.");
|
|
|
|
}
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
private sealed class TTSPlayerSkipAllCommand : IChatPartialCommand
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-08-04 19:46:10 -04:00
|
|
|
private readonly TTSPlayer _player;
|
|
|
|
private readonly AudioPlaybackEngine _playback;
|
2024-07-19 12:56:41 -04:00
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
2024-08-04 19:46:10 -04:00
|
|
|
public TTSPlayerSkipAllCommand(TTSPlayer player, AudioPlaybackEngine playback, ILogger logger)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-04 19:46:10 -04:00
|
|
|
_player = player;
|
|
|
|
_playback = playback;
|
2024-07-19 12:56:41 -04:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public async Task Execute(IDictionary<string, string> values, ChannelChatMessage message, HermesSocketClient hermes)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-08-04 19:46:10 -04:00
|
|
|
_player.RemoveAll();
|
2024-07-19 12:56:41 -04:00
|
|
|
|
2024-08-04 19:46:10 -04:00
|
|
|
if (_player.Playing == null)
|
2024-07-19 12:56:41 -04:00
|
|
|
return;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
2024-08-04 19:46:10 -04:00
|
|
|
_playback.RemoveMixerInput(_player.Playing.Audio!);
|
|
|
|
_player.Playing = null;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
_logger.Information("Skipped all queued and playing tts.");
|
|
|
|
}
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|