49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System.Text.Json;
|
|
using HermesSocketLibrary.Requests.Messages;
|
|
using Serilog;
|
|
using TwitchChatTTS.Chat.Groups;
|
|
|
|
namespace TwitchChatTTS.Hermes.Socket.Requests
|
|
{
|
|
public class UpdateGroupAck : IRequestAck
|
|
{
|
|
public string Name => "update_group";
|
|
private readonly IChatterGroupManager _groups;
|
|
private readonly JsonSerializerOptions _options;
|
|
private readonly ILogger _logger;
|
|
|
|
public UpdateGroupAck(IChatterGroupManager groups, JsonSerializerOptions options, ILogger logger)
|
|
{
|
|
_groups = groups;
|
|
_options = options;
|
|
_logger = logger;
|
|
}
|
|
|
|
public void Acknowledge(string requestId, string? json, IDictionary<string, object>? requestData)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(json))
|
|
{
|
|
_logger.Warning($"Group JSON data is null.");
|
|
return;
|
|
}
|
|
|
|
var group = JsonSerializer.Deserialize<Group>(json, _options);
|
|
if (group == null)
|
|
{
|
|
_logger.Warning($"Group data is null.");
|
|
return;
|
|
}
|
|
|
|
var exists = _groups.Get(group.Id);
|
|
if (exists == null)
|
|
{
|
|
_logger.Warning($"Group id does not exist [group id: {group.Id}][group name: {group.Name}][group priority: {group.Priority}]");
|
|
return;
|
|
}
|
|
|
|
_logger.Debug($"Updating group [group id: {group.Id}][group name: {group.Name}][group priority: {group.Priority}]");
|
|
_groups.Modify(group);
|
|
_logger.Information($"Group has been updated [group id: {group.Id}]");
|
|
}
|
|
}
|
|
} |