Added missing websocket support for Redemptions and Actions. Fixed Ad Break actions. Cleaned some code.
This commit is contained in:
35
Hermes/Socket/Requests/CreateRedemptionAck.cs
Normal file
35
Hermes/Socket/Requests/CreateRedemptionAck.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Text.Json;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using Serilog;
|
||||
using TwitchChatTTS.Twitch.Redemptions;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
{
|
||||
public class CreateRedemptionAck : IRequestAck
|
||||
{
|
||||
public string Name => "create_redemption";
|
||||
private readonly IRedemptionManager _redemptions;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public CreateRedemptionAck(IRedemptionManager redemptions, JsonSerializerOptions options, ILogger logger)
|
||||
{
|
||||
_redemptions = redemptions;
|
||||
_options = options;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
||||
{
|
||||
var redemption = JsonSerializer.Deserialize<Redemption>(json, _options);
|
||||
if (redemption == null)
|
||||
{
|
||||
_logger.Warning($"Redemption data received is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
_redemptions.Add(redemption);
|
||||
_logger.Information($"A new redemption has been created [redemption id: {redemption.Id}][twitch redemption id: {redemption.TwitchRedemptionId}]");
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
_logger.Warning("Request data is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!long.TryParse(requestData["chatter"].ToString(), out long chatterId))
|
||||
{
|
||||
_logger.Warning($"Failed to parse chatter id [chatter id: {requestData["chatter"]}]");
|
||||
|
@ -21,7 +21,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
_logger.Warning("Request data is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var voice = requestData["voice"].ToString()!;
|
||||
var voiceId = json;
|
||||
if (string.IsNullOrEmpty(voice))
|
||||
|
39
Hermes/Socket/Requests/DeleteRedeemableActionAck.cs
Normal file
39
Hermes/Socket/Requests/DeleteRedeemableActionAck.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Serilog;
|
||||
using TwitchChatTTS.Twitch.Redemptions;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
{
|
||||
public class DeleteRedeemableActionAck : IRequestAck
|
||||
{
|
||||
public string Name => "delete_redeemable_action";
|
||||
private readonly IRedemptionManager _redemptions;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DeleteRedeemableActionAck(IRedemptionManager redemptions, ILogger logger)
|
||||
{
|
||||
_redemptions = redemptions;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
||||
{
|
||||
if (requestData == null)
|
||||
{
|
||||
_logger.Warning("Request data is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
var name = requestData["name"].ToString();
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
_logger.Warning($"Action name is invalid [action name: {name}]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_redemptions.RemoveAction(name))
|
||||
_logger.Information($"Deleted a redeemable action [action name: {name}]");
|
||||
else
|
||||
_logger.Warning($"Failed to delete a redeemable action [action name: {name}]");
|
||||
}
|
||||
}
|
||||
}
|
39
Hermes/Socket/Requests/DeleteRedemptionAck.cs
Normal file
39
Hermes/Socket/Requests/DeleteRedemptionAck.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Serilog;
|
||||
using TwitchChatTTS.Twitch.Redemptions;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
{
|
||||
public class DeleteRedemptionAck : IRequestAck
|
||||
{
|
||||
public string Name => "delete_redemption";
|
||||
private readonly IRedemptionManager _redemptions;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DeleteRedemptionAck(IRedemptionManager redemptions, ILogger logger)
|
||||
{
|
||||
_redemptions = redemptions;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
||||
{
|
||||
if (requestData == null)
|
||||
{
|
||||
_logger.Warning("Request data is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
var id = requestData["id"].ToString();
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
_logger.Warning($"Redemption Id is invalid [redemption id: {id}]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_redemptions.RemoveRedemption(id))
|
||||
_logger.Information($"Deleted a redemption [redemption id: {id}]");
|
||||
else
|
||||
_logger.Warning($"Failed to delete a redemption [redemption id: {id}]");
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
_logger.Warning("Request data is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var id = requestData["id"].ToString();
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
_logger.Warning("Request data is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var voice = requestData["voice"].ToString();
|
||||
if (string.IsNullOrEmpty(voice))
|
||||
{
|
||||
|
@ -46,7 +46,8 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
}
|
||||
|
||||
_logger.Information($"Redeemable actions loaded [count: {actions.Count()}]");
|
||||
_bus.Send(this, "redemptions_initiation", new RedemptionInitiation() {
|
||||
_bus.Send(this, "redemptions_initiation", new RedemptionInitiation()
|
||||
{
|
||||
Redemptions = redemptions,
|
||||
Actions = actions.ToDictionary(a => a.Name, a => a)
|
||||
});
|
||||
|
@ -27,7 +27,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
var temp = new ConcurrentDictionary<long, string>();
|
||||
foreach (var entry in users)
|
||||
temp.TryAdd(entry.Key, entry.Value);
|
||||
|
||||
|
||||
_user.VoicesSelected = temp;
|
||||
_logger.Information($"Updated chatters' selected voice [count: {temp.Count()}]");
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Fulfill(string type, string requestId, string? data, IDictionary<string, object>? requestData)
|
||||
public void Fulfill(string type, string requestId, string data, IDictionary<string, object>? requestData)
|
||||
{
|
||||
if (!_acknowledgements.TryGetValue(type, out var ack))
|
||||
{
|
||||
|
@ -28,8 +28,10 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
return;
|
||||
}
|
||||
|
||||
_redemptions.Update(action);
|
||||
_logger.Information($"A new redeemable action has been created [action name: {action.Name}]");
|
||||
if (_redemptions.Update(action))
|
||||
_logger.Information($"A redeemable action has been updated [action name: {action.Name}]");
|
||||
else
|
||||
_logger.Warning($"Failed to update an existing redeemable action [action name: {action.Name}]");
|
||||
}
|
||||
}
|
||||
}
|
37
Hermes/Socket/Requests/UpdateRedeemptionAck.cs
Normal file
37
Hermes/Socket/Requests/UpdateRedeemptionAck.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System.Text.Json;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using Serilog;
|
||||
using TwitchChatTTS.Twitch.Redemptions;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
{
|
||||
public class UpdateRedemptionAck : IRequestAck
|
||||
{
|
||||
public string Name => "update_redemption";
|
||||
private readonly IRedemptionManager _redemptions;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public UpdateRedemptionAck(IRedemptionManager redemptions, JsonSerializerOptions options, ILogger logger)
|
||||
{
|
||||
_redemptions = redemptions;
|
||||
_options = options;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
||||
{
|
||||
var redemption = JsonSerializer.Deserialize<Redemption>(json, _options);
|
||||
if (redemption == null)
|
||||
{
|
||||
_logger.Warning($"Redemption data received is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_redemptions.Update(redemption))
|
||||
_logger.Information($"A redemption has been updated [redemption id: {redemption.Id}][twitch redemption id: {redemption.TwitchRedemptionId}]");
|
||||
else
|
||||
_logger.Warning($"Failed to update an existing redemption [redemption id: {redemption.Id}][twitch redemption id: {redemption.TwitchRedemptionId}]");
|
||||
}
|
||||
}
|
||||
}
|
@ -26,14 +26,15 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
_logger.Warning($"TTS Filter data failed: null");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_logger.Debug($"Filter data [filter id: {filter.Id}][search: {filter.Search}][group id: {filter.Replace}]");
|
||||
var previous = _user.RegexFilters.FirstOrDefault(f => f.Id == filter.Id);
|
||||
if (previous == null) {
|
||||
if (previous == null)
|
||||
{
|
||||
_logger.Warning($"TTS Filter doest exist by id [filter id: {filter.Id}]");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
previous.Search = filter.Search;
|
||||
previous.Replace = filter.Replace;
|
||||
_logger.Information($"Filter has been updated [filter id: {filter.Id}]");
|
||||
|
Reference in New Issue
Block a user