Made Veadotube redemptions more user friendly
This commit is contained in:
34
Veadotube/Handlers/FetchStatesHandler.cs
Normal file
34
Veadotube/Handlers/FetchStatesHandler.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.Text.Json;
|
||||
using Serilog;
|
||||
|
||||
namespace TwitchChatTTS.Veadotube.Handlers
|
||||
{
|
||||
public class FetchStatesHandler : IVeadotubeMessageHandler
|
||||
{
|
||||
private readonly JsonSerializerOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public string Name => "list";
|
||||
|
||||
public FetchStatesHandler(JsonSerializerOptions options, ILogger logger)
|
||||
{
|
||||
_options = options;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Handle(VeadoSocketClient client, VeadoPayloadMessage message)
|
||||
{
|
||||
_logger.Information("Triggered Veadotube handler.");
|
||||
var payload = JsonSerializer.Deserialize<VeadoNodeStateListMessage>(message.Payload.ToString()!, _options);
|
||||
if (payload == null)
|
||||
{
|
||||
_logger.Warning("Invalid message received from Veadotube for listing states.");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
var states = payload.States.ToDictionary(s => s.Name, s => s.Id);
|
||||
client.UpdateState(states);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
8
Veadotube/Handlers/IVeadotubeMessageHandler.cs
Normal file
8
Veadotube/Handlers/IVeadotubeMessageHandler.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace TwitchChatTTS.Veadotube.Handlers
|
||||
{
|
||||
public interface IVeadotubeMessageHandler
|
||||
{
|
||||
string Name { get; }
|
||||
Task Handle(VeadoSocketClient client, VeadoPayloadMessage message);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user