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 SkipCommand : IChatCommand
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
private readonly TTSPlayer _player;
|
2024-06-24 18:11:36 -04:00
|
|
|
private readonly ILogger _logger;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
public SkipCommand(TTSPlayer ttsPlayer, ILogger logger)
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
_player = ttsPlayer;
|
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 =>
|
|
|
|
{
|
|
|
|
b.CreateCommand(new TTSPlayerSkipAllCommand(_player, _logger));
|
|
|
|
}).CreateCommand(new TTSPlayerSkipCommand(_player, _logger));
|
|
|
|
});
|
|
|
|
builder.CreateCommandTree("skipall", b => {
|
|
|
|
b.CreateCommand(new TTSPlayerSkipAllCommand(_player, _logger));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private sealed class TTSPlayerSkipCommand : IChatPartialCommand
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-07-19 12:56:41 -04:00
|
|
|
private readonly TTSPlayer _ttsPlayer;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
|
|
|
public TTSPlayerSkipCommand(TTSPlayer ttsPlayer, ILogger logger)
|
|
|
|
{
|
|
|
|
_ttsPlayer = ttsPlayer;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CheckDefaultPermissions(ChatMessage message)
|
|
|
|
{
|
|
|
|
return message.IsModerator || message.IsVip || message.IsBroadcaster;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task Execute(IDictionary<string, string> values, ChatMessage message, HermesSocketClient client)
|
|
|
|
{
|
|
|
|
if (_ttsPlayer.Playing == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AudioPlaybackEngine.Instance.RemoveMixerInput(_ttsPlayer.Playing);
|
|
|
|
_ttsPlayer.Playing = null;
|
|
|
|
|
|
|
|
_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-07-19 12:56:41 -04:00
|
|
|
private readonly TTSPlayer _ttsPlayer;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public bool AcceptCustomPermission { get => true; }
|
|
|
|
|
|
|
|
public TTSPlayerSkipAllCommand(TTSPlayer ttsPlayer, ILogger logger)
|
|
|
|
{
|
|
|
|
_ttsPlayer = ttsPlayer;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CheckDefaultPermissions(ChatMessage message)
|
|
|
|
{
|
|
|
|
return message.IsModerator || message.IsVip || message.IsBroadcaster;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task Execute(IDictionary<string, string> values, ChatMessage message, HermesSocketClient client)
|
|
|
|
{
|
|
|
|
_ttsPlayer.RemoveAll();
|
|
|
|
|
|
|
|
if (_ttsPlayer.Playing == null)
|
|
|
|
return;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
AudioPlaybackEngine.Instance.RemoveMixerInput(_ttsPlayer.Playing);
|
|
|
|
_ttsPlayer.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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|