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 ChannelChatDeleteMessageHandler : ITwitchSocketHandler
|
|
|
|
{
|
|
|
|
public string Name => "channel.chat.message_delete";
|
|
|
|
|
|
|
|
private readonly TTSPlayer _player;
|
|
|
|
private readonly AudioPlaybackEngine _playback;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public ChannelChatDeleteMessageHandler(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 ChannelChatDeleteMessage message)
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
|
|
if (_player.Playing?.MessageId == message.MessageId)
|
|
|
|
{
|
2024-08-12 01:44:31 -04:00
|
|
|
_playback.RemoveMixerInput(_player.Playing!.Audio!);
|
2024-08-04 19:46:10 -04:00
|
|
|
_player.Playing = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_player.RemoveMessage(message.MessageId);
|
|
|
|
|
|
|
|
|
|
|
|
_logger.Information($"Deleted chat message [message id: {message.MessageId}][target chatter: {message.TargetUserLogin}][target chatter id: {message.TargetUserId}][broadcaster: {message.BroadcasterUserLogin}][broadcaster id: {message.BroadcasterUserId}]");
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|