Added missing websocket support for Redemptions and Actions. Fixed Ad Break actions. Cleaned some code.

This commit is contained in:
Tom
2025-01-07 15:30:13 +00:00
parent 77b37f04b6
commit 64cb0c1f6d
17 changed files with 227 additions and 36 deletions

View File

@@ -7,7 +7,6 @@ using org.mariuszgromada.math.mxparser;
using Serilog;
using TwitchChatTTS.Bus;
using TwitchChatTTS.Bus.Data;
using TwitchChatTTS.Hermes.Socket;
using TwitchChatTTS.OBS.Socket;
using TwitchChatTTS.OBS.Socket.Data;
using TwitchChatTTS.Veadotube;
@@ -23,7 +22,6 @@ namespace TwitchChatTTS.Twitch.Redemptions
private readonly ServiceBusCentral _bus;
private readonly User _user;
private readonly OBSSocketClient _obs;
private readonly HermesSocketClient _hermes;
private readonly VeadoSocketClient _veado;
private readonly NightbotApiClient _nightbot;
private readonly AudioPlaybackEngine _playback;
@@ -36,7 +34,6 @@ namespace TwitchChatTTS.Twitch.Redemptions
ServiceBusCentral bus,
User user,
[FromKeyedServices("obs")] SocketClient<WebSocketMessage> obs,
[FromKeyedServices("hermes")] SocketClient<WebSocketMessage> hermes,
[FromKeyedServices("veadotube")] SocketClient<object> veado,
NightbotApiClient nightbot,
AudioPlaybackEngine playback,
@@ -48,7 +45,6 @@ namespace TwitchChatTTS.Twitch.Redemptions
_bus = bus;
_user = user;
_obs = (obs as OBSSocketClient)!;
_hermes = (hermes as HermesSocketClient)!;
_veado = (veado as VeadoSocketClient)!;
_nightbot = nightbot;
_playback = playback;
@@ -284,12 +280,12 @@ namespace TwitchChatTTS.Twitch.Redemptions
if (_user.VoicesSelected.ContainsKey(senderId))
{
await _hermes.UpdateTTSUser(senderId, voiceId);
_bus.Send(this, "tts.user.voice.update", new Dictionary<string, object>() { { "chatter", senderId }, { "voice", voiceId } });
_logger.Debug($"Sent request to update chat TTS voice [voice: {voiceName}][chatter id: {senderId}][source: redemption][chatter: {senderDisplayName}][chatter id: {senderId}]");
}
else
{
await _hermes.CreateTTSUser(senderId, voiceId);
_bus.Send(this, "tts.user.voice.create", new Dictionary<string, object>() { { "chatter", senderId }, { "voice", voiceId } });
_logger.Debug($"Sent request to create chat TTS voice [voice: {voiceName}][chatter id: {senderId}][source: redemption][chatter: {senderDisplayName}][chatter id: {senderId}]");
}
break;

View File

@@ -25,14 +25,14 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
if (message.IsAutomatic)
_logger.Information($"Ad break has begun [duration: {message.DurationSeconds} seconds][automatic: true]");
else
_logger.Information($"Ad break has begun [duration: {message.DurationSeconds} seconds][requester: {message.RequesterUserLogin}][requester id: {message.RequesterUserId}]");
_logger.Information($"Ad break has begun [duration: {message.DurationSeconds} seconds][automatic: false][requester: {message.RequesterUserLogin}][requester id: {message.RequesterUserId}]");
try
{
var actions = _redemptionManager.Get("adbreak_begin");
if (!actions.Any())
if (actions.Any())
{
_logger.Debug($"Found {actions.Count()} actions for this Twitch ad break");
_logger.Debug($"Found {actions.Count()} actions for this Twitch ad break begin");
foreach (var action in actions)
try
@@ -46,20 +46,27 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
}
else
_logger.Debug($"No redeemable actions for ad break begin was found");
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to fetch the redeemable actions for ad break begin");
}
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
Task.Run(async () =>
Task.Run(async () =>
{
try
{
await Task.Delay(TimeSpan.FromSeconds(message.DurationSeconds));
if (message.IsAutomatic)
_logger.Information($"Ad break has ended [duration: {message.DurationSeconds} seconds][automatic: true]");
else
_logger.Information($"Ad break has ended [duration: {message.DurationSeconds} seconds][requester: {message.RequesterUserLogin}][requester id: {message.RequesterUserId}]");
actions = _redemptionManager.Get("adbreak_end");
if (!actions.Any())
_logger.Information($"Ad break has ended [duration: {message.DurationSeconds} seconds][automatic: false][requester: {message.RequesterUserLogin}][requester id: {message.RequesterUserId}]");
var actions = _redemptionManager.Get("adbreak_end");
if (actions.Any())
{
_logger.Debug($"Found {actions.Count()} actions for this Twitch ad break");
_logger.Debug($"Found {actions.Count()} actions for this Twitch ad break end");
foreach (var action in actions)
try
@@ -73,13 +80,13 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
}
else
_logger.Debug($"No redeemable actions for ad break end was found");
});
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to fetch the redeemable actions for ad break end");
}
});
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to fetch the redeemable actions for ad break begin");
}
}
}
}