Cleaned up request acks. Added internal service bus for internal messaging.
This commit is contained in:
43
Hermes/Socket/Requests/DeletePolicyAck.cs
Normal file
43
Hermes/Socket/Requests/DeletePolicyAck.cs
Normal 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}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user