2024-08-04 19:46:10 -04:00
|
|
|
using Serilog;
|
2024-08-12 01:44:31 -04:00
|
|
|
using TwitchChatTTS.Chat.Soeech;
|
2024-08-04 19:46:10 -04:00
|
|
|
using TwitchChatTTS.Twitch.Socket.Messages;
|
|
|
|
|
|
|
|
namespace TwitchChatTTS.Twitch.Socket.Handlers
|
|
|
|
{
|
|
|
|
public class ChannelChatClearHandler : ITwitchSocketHandler
|
|
|
|
{
|
|
|
|
public string Name => "channel.chat.clear";
|
|
|
|
|
|
|
|
private readonly TTSPlayer _player;
|
|
|
|
private readonly AudioPlaybackEngine _playback;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public ChannelChatClearHandler(TTSPlayer player, AudioPlaybackEngine playback, ILogger logger)
|
|
|
|
{
|
|
|
|
_player = player;
|
|
|
|
_playback = playback;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
public Task Execute(TwitchWebsocketClient sender, object data)
|
2024-08-04 19:46:10 -04:00
|
|
|
{
|
|
|
|
if (data is not ChannelChatClearMessage message)
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
|
|
_player.RemoveAll();
|
|
|
|
if (_player.Playing != null)
|
|
|
|
{
|
|
|
|
_playback.RemoveMixerInput(_player.Playing.Audio!);
|
|
|
|
_player.Playing = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.Information($"Chat cleared [broadcaster: {message.BroadcasterUserLogin}][broadcaster id: {message.BroadcasterUserId}]");
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|