Added chat message to redemptions. Added Subscription End to Twitch. Added more variables to certain redemptions.
This commit is contained in:
52
Twitch/Socket/Handlers/ChannelSubscriptionEndHandler.cs
Normal file
52
Twitch/Socket/Handlers/ChannelSubscriptionEndHandler.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Serilog;
|
||||
using TwitchChatTTS.Twitch.Redemptions;
|
||||
using TwitchChatTTS.Twitch.Socket.Messages;
|
||||
|
||||
namespace TwitchChatTTS.Twitch.Socket.Handlers
|
||||
{
|
||||
public class ChannelSubscriptionEndHandler : ITwitchSocketHandler
|
||||
{
|
||||
public string Name => "channel.subscription.end";
|
||||
|
||||
private readonly IRedemptionManager _redemptionManager;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public ChannelSubscriptionEndHandler(IRedemptionManager redemptionManager, ILogger logger)
|
||||
{
|
||||
_redemptionManager = redemptionManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task Execute(TwitchWebsocketClient sender, object data)
|
||||
{
|
||||
if (data is not ChannelSubscriptionEndMessage message)
|
||||
return;
|
||||
|
||||
_logger.Information($"Subscription ended [chatter: {message.UserLogin}][chatter id: {message.UserId}][Tier: {message.Tier}]");
|
||||
try
|
||||
{
|
||||
var actions = _redemptionManager.Get("subscription.end");
|
||||
if (!actions.Any())
|
||||
{
|
||||
_logger.Debug($"No redeemable actions for this subscription was found [subscriber: {message.UserLogin}][subscriber id: {message.UserId}]");
|
||||
return;
|
||||
}
|
||||
_logger.Debug($"Found {actions.Count()} actions for this Twitch subscription [subscriber: {message.UserLogin}][subscriber id: {message.UserId}]");
|
||||
|
||||
foreach (var action in actions)
|
||||
try
|
||||
{
|
||||
await _redemptionManager.Execute(action, message.UserName!, long.Parse(message.UserId!), string.Empty);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, $"Failed to execute redeemable action [action: {action.Name}][action type: {action.Type}][redeem: subscription][subscriber: {message.UserLogin}][subscriber id: {message.UserId}]");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, $"Failed to fetch the redeemable actions for subscription [subscriber: {message.UserLogin}][subscriber id: {message.UserId}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user