2024-08-04 19:46:10 -04:00
using Serilog ;
using TwitchChatTTS.Twitch.Socket.Messages ;
namespace TwitchChatTTS.Twitch.Socket.Handlers
{
public class ChannelChatClearUserHandler : ITwitchSocketHandler
{
public string Name = > "channel.chat.clear_user_messages" ;
private readonly TTSPlayer _player ;
private readonly AudioPlaybackEngine _playback ;
private readonly ILogger _logger ;
public ChannelChatClearUserHandler ( 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 ChannelChatClearUserMessage message )
return Task . CompletedTask ;
2024-08-06 15:29:29 -04:00
long broadcasterId = long . Parse ( message . BroadcasterUserId ) ;
2024-08-04 19:46:10 -04:00
long chatterId = long . Parse ( message . TargetUserId ) ;
2024-08-06 15:29:29 -04:00
_player . RemoveAll ( broadcasterId , chatterId ) ;
if ( _player . Playing ! = null & & _player . Playing . RoomId = = broadcasterId & & _player . Playing . ChatterId = = chatterId )
{
2024-08-04 19:46:10 -04:00
_playback . RemoveMixerInput ( _player . Playing . Audio ! ) ;
_player . Playing = null ;
}
_logger . Information ( $"Cleared all messages by user [target chatter: {message.TargetUserLogin}][target chatter id: {chatterId}][broadcaster: {message.BroadcasterUserLogin}][broadcaster id: {message.BroadcasterUserId}]" ) ;
return Task . CompletedTask ;
}
}
}