Added group support for websockets.

This commit is contained in:
Tom
2025-01-18 16:37:58 +00:00
parent aed0421843
commit a49e52a6bb
7 changed files with 164 additions and 2 deletions

View File

@@ -0,0 +1,48 @@
using System.Text.Json;
using Serilog;
using TwitchChatTTS.Chat.Groups;
namespace TwitchChatTTS.Hermes.Socket.Requests
{
public class DeleteGroupAck : IRequestAck
{
public string Name => "delete_group";
private readonly IChatterGroupManager _groups;
private readonly JsonSerializerOptions _options;
private readonly ILogger _logger;
public DeleteGroupAck(IChatterGroupManager groups, JsonSerializerOptions options, ILogger logger)
{
_groups = groups;
_options = options;
_logger = logger;
}
public void Acknowledge(string requestId, string? json, IDictionary<string, object>? requestData)
{
if (requestData == null)
{
_logger.Warning("Request data is null.");
return;
}
var groupId = requestData["group"].ToString();
if (string.IsNullOrEmpty(groupId))
{
_logger.Warning($"Action name is invalid [action name: {groupId}]");
return;
}
var exists = _groups.Get(groupId);
if (exists == null)
{
_logger.Warning($"Group id does not exist [group id: {exists}]");
return;
}
_logger.Debug($"Removing group [group id: {exists.Id}][group name: {exists.Name}][group priority: {exists.Priority}]");
_groups.Remove(exists.Id);
_logger.Information($"Group has been updated [group id: {exists.Id}]");
}
}
}