Cleaned up request acks. Added internal service bus for internal messaging.

This commit is contained in:
Tom
2024-11-08 15:32:42 +00:00
parent fe2eb86a08
commit 66f2bf7ec6
33 changed files with 1326 additions and 415 deletions

View File

@@ -0,0 +1,43 @@
using Serilog;
using TwitchChatTTS.Chat.Commands.Limits;
using TwitchChatTTS.Chat.Groups;
namespace TwitchChatTTS.Hermes.Socket.Requests
{
public class DeletePolicyAck : IRequestAck
{
public string Name => "delete_policy";
private readonly IChatterGroupManager _groups;
private readonly IUsagePolicy<long> _policies;
private readonly ILogger _logger;
public DeletePolicyAck(IChatterGroupManager groups, IUsagePolicy<long> policies, ILogger logger)
{
_groups = groups;
_policies = policies;
_logger = logger;
}
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
{
var data = json.Split('/');
if (data.Length != 2)
{
_logger.Error("Deleting a policy failed: data received is invalid.");
return;
}
var groupId = data[0];
var path = data[1];
var group = _groups.Get(groupId);
if (group == null)
{
_logger.Warning($"Deleting a policy failed: group id does not exist [group id: {groupId}][path: {path}]");
return;
}
_policies.Remove(group.Name, path);
_logger.Information($"Policy has been deleted [group id: {groupId}][path: {path}]");
}
}
}