Compare commits
4 Commits
5e33d594d2
...
c373af5281
| Author | SHA1 | Date | |
|---|---|---|---|
| c373af5281 | |||
| 9f884f71ae | |||
| a49e52a6bb | |||
| aed0421843 |
@@ -12,7 +12,7 @@ namespace TwitchChatTTS.Chat.Commands.Limits
|
|||||||
public UsagePolicy(ILogger logger)
|
public UsagePolicy(ILogger logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_root = new UsagePolicyNode<K>(string.Empty, null, null, logger);
|
_root = new UsagePolicyNode<K>(string.Empty, null, null, logger, root: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,9 +104,10 @@ namespace TwitchChatTTS.Chat.Commands.Limits
|
|||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
private object _lock { get; }
|
private object _lock { get; }
|
||||||
|
|
||||||
public UsagePolicyNode(string name, UsagePolicyLimit? data, UsagePolicyNode<T>? parent, ILogger logger)
|
public UsagePolicyNode(string name, UsagePolicyLimit? data, UsagePolicyNode<T>? parent, ILogger logger, bool root = false)
|
||||||
{
|
{
|
||||||
//ArgumentException.ThrowIfNullOrWhiteSpace(name, nameof(name));
|
if (!root)
|
||||||
|
ArgumentException.ThrowIfNullOrWhiteSpace(name, nameof(name));
|
||||||
Name = name;
|
Name = name;
|
||||||
Limit = data;
|
Limit = data;
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
|
|||||||
@@ -24,9 +24,12 @@ namespace TwitchChatTTS.Chat.Groups
|
|||||||
_groups.Add(group.Name, group);
|
_groups.Add(group.Name, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(long chatter, string groupName)
|
public void Add(long chatter, string groupId)
|
||||||
{
|
{
|
||||||
_chatters.Add(chatter, new List<string>() { groupName });
|
if (_chatters.TryGetValue(chatter, out var list))
|
||||||
|
list.Add(groupId);
|
||||||
|
else
|
||||||
|
_chatters.Add(chatter, new List<string>() { groupId });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(long chatter, ICollection<string> groupNames)
|
public void Add(long chatter, ICollection<string> groupNames)
|
||||||
@@ -77,6 +80,16 @@ namespace TwitchChatTTS.Chat.Groups
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Modify(Group group)
|
||||||
|
{
|
||||||
|
_groups[group.Name] = group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Remove(string groupId)
|
||||||
|
{
|
||||||
|
return _groups.Remove(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
public bool Remove(long chatterId, string groupId)
|
public bool Remove(long chatterId, string groupId)
|
||||||
{
|
{
|
||||||
if (_chatters.TryGetValue(chatterId, out var groups))
|
if (_chatters.TryGetValue(chatterId, out var groups))
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ namespace TwitchChatTTS.Chat.Groups
|
|||||||
IEnumerable<string> GetGroupNamesFor(long chatter);
|
IEnumerable<string> GetGroupNamesFor(long chatter);
|
||||||
int GetPriorityFor(long chatter);
|
int GetPriorityFor(long chatter);
|
||||||
int GetPriorityFor(IEnumerable<string> groupIds);
|
int GetPriorityFor(IEnumerable<string> groupIds);
|
||||||
|
void Modify(Group group);
|
||||||
|
bool Remove(string groupId);
|
||||||
bool Remove(long chatter, string groupId);
|
bool Remove(long chatter, string groupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
49
Hermes/Socket/Requests/CreateGroupAck.cs
Normal file
49
Hermes/Socket/Requests/CreateGroupAck.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using HermesSocketLibrary.Requests.Messages;
|
||||||
|
using Serilog;
|
||||||
|
using TwitchChatTTS.Chat.Groups;
|
||||||
|
|
||||||
|
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||||
|
{
|
||||||
|
public class CreateGroupAck : IRequestAck
|
||||||
|
{
|
||||||
|
public string Name => "create_group";
|
||||||
|
private readonly IChatterGroupManager _groups;
|
||||||
|
private readonly JsonSerializerOptions _options;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public CreateGroupAck(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 already exists [group id: {exists.Id}][group name: {exists.Name} / {group.Name}][group priority: {exists.Priority} / {group.Priority}]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug($"Adding group [group id: {group.Id}][group name: {group.Name}][group priority: {group.Priority}]");
|
||||||
|
_groups.Add(group);
|
||||||
|
_logger.Information($"Group has been created [group id: {group.Id}]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
Hermes/Socket/Requests/CreateGroupChatterAck.cs
Normal file
49
Hermes/Socket/Requests/CreateGroupChatterAck.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using HermesSocketLibrary.Requests.Messages;
|
||||||
|
using Serilog;
|
||||||
|
using TwitchChatTTS.Chat.Groups;
|
||||||
|
|
||||||
|
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||||
|
{
|
||||||
|
public class CreateGroupChatterAck : IRequestAck
|
||||||
|
{
|
||||||
|
public string Name => "create_group_chatter";
|
||||||
|
private readonly IChatterGroupManager _groups;
|
||||||
|
private readonly JsonSerializerOptions _options;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public CreateGroupChatterAck(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 Chatter JSON data is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var groupChatter = JsonSerializer.Deserialize<GroupChatter>(json, _options);
|
||||||
|
if (groupChatter == null)
|
||||||
|
{
|
||||||
|
_logger.Warning($"Group Chatter data is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var group = _groups.Get(groupChatter.GroupId);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
_logger.Warning($"Group id for chatter does not exists [group id: {groupChatter.GroupId}]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug($"Adding chatter to group [group id: {groupChatter.GroupId}][group name: {group.Name}][chatter id: {groupChatter.ChatterId}][chatter label: {groupChatter.ChatterLabel}]");
|
||||||
|
_groups.Add(groupChatter.ChatterId, groupChatter.GroupId);
|
||||||
|
_logger.Information($"Chatter has been added to group [group id: {groupChatter.GroupId}][group name: {group.Name}][chatter id: {groupChatter.ChatterId}][chatter label: {groupChatter.ChatterLabel}]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,10 +24,15 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
|||||||
|
|
||||||
public void Acknowledge(string requestId, string? json, IDictionary<string, object>? requestData)
|
public void Acknowledge(string requestId, string? json, IDictionary<string, object>? requestData)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(json)) {
|
||||||
|
_logger.Warning($"Policy JSON data is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var policy = JsonSerializer.Deserialize<Policy>(json, _options);
|
var policy = JsonSerializer.Deserialize<Policy>(json, _options);
|
||||||
if (policy == null)
|
if (policy == null)
|
||||||
{
|
{
|
||||||
_logger.Warning($"Policy JSON data is null.");
|
_logger.Warning($"Policy data is null.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
48
Hermes/Socket/Requests/DeleteGroupAck.cs
Normal file
48
Hermes/Socket/Requests/DeleteGroupAck.cs
Normal 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}]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
Hermes/Socket/Requests/DeleteGroupChatterAck.cs
Normal file
51
Hermes/Socket/Requests/DeleteGroupChatterAck.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using Serilog;
|
||||||
|
using TwitchChatTTS.Chat.Groups;
|
||||||
|
|
||||||
|
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||||
|
{
|
||||||
|
public class DeleteGroupChatterAck : IRequestAck
|
||||||
|
{
|
||||||
|
public string Name => "delete_group_chatter";
|
||||||
|
private readonly IChatterGroupManager _groups;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public DeleteGroupChatterAck(IChatterGroupManager groups, ILogger logger)
|
||||||
|
{
|
||||||
|
_groups = groups;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Acknowledge(string requestId, string? json, IDictionary<string, object>? requestData)
|
||||||
|
{
|
||||||
|
if (requestData == null)
|
||||||
|
{
|
||||||
|
_logger.Warning("Request data is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (long.TryParse(requestData["chatter"].ToString(), out var chatterId))
|
||||||
|
{
|
||||||
|
_logger.Warning($"Chatter Id is invalid [chatter id: {chatterId}]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var groupId = requestData["group"].ToString();
|
||||||
|
if (string.IsNullOrWhiteSpace(groupId))
|
||||||
|
{
|
||||||
|
_logger.Warning($"Group Id is invalid [group id: {groupId}]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var group = _groups.Get(groupId);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
_logger.Warning($"Group id does not exist [group id: {groupId}]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug($"Deleting chatter from group [group id: {group.Id}][chatter id: {chatterId}][group name: {group.Name}][group priority: {group.Priority}]");
|
||||||
|
_groups.Remove(chatterId, groupId);
|
||||||
|
_logger.Information($"Chatter has been deleted from group [group id: {group.Id}][chatter id: {chatterId}]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,12 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
|||||||
|
|
||||||
public void Acknowledge(string requestId, string? json, IDictionary<string, object>? requestData)
|
public void Acknowledge(string requestId, string? json, IDictionary<string, object>? requestData)
|
||||||
{
|
{
|
||||||
|
if (json == null)
|
||||||
|
{
|
||||||
|
_logger.Warning("Policy JSON data is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var data = json.Split('/');
|
var data = json.Split('/');
|
||||||
if (data.Length != 2)
|
if (data.Length != 2)
|
||||||
{
|
{
|
||||||
|
|||||||
49
Hermes/Socket/Requests/UpdateGroupAck.cs
Normal file
49
Hermes/Socket/Requests/UpdateGroupAck.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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 => "create_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}]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
Hermes/Socket/Requests/UpdateGroupChatterAck.cs
Normal file
40
Hermes/Socket/Requests/UpdateGroupChatterAck.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using HermesSocketLibrary.Requests.Messages;
|
||||||
|
using Serilog;
|
||||||
|
using TwitchChatTTS.Chat.Groups;
|
||||||
|
|
||||||
|
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||||
|
{
|
||||||
|
public class UpdateGroupChatterAck : IRequestAck
|
||||||
|
{
|
||||||
|
public string Name => "update_group_chatter";
|
||||||
|
private readonly IChatterGroupManager _groups;
|
||||||
|
private readonly JsonSerializerOptions _options;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public UpdateGroupChatterAck(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 Chatter JSON data is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var groupChatter = JsonSerializer.Deserialize<GroupChatter>(json, _options);
|
||||||
|
if (groupChatter == null)
|
||||||
|
{
|
||||||
|
_logger.Warning($"Group Chatter data is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_groups.Add(groupChatter.ChatterId, groupChatter.GroupId);
|
||||||
|
_logger.Information($"Chatter has been updated [chatter label: {groupChatter.ChatterLabel}]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,6 @@ namespace TwitchChatTTS.OBS.Socket.Data
|
|||||||
{
|
{
|
||||||
public required string EventType { get; set; }
|
public required string EventType { get; set; }
|
||||||
public int EventIntent { get; set; }
|
public int EventIntent { get; set; }
|
||||||
public required Dictionary<string, object> EventData { get; set; }
|
public Dictionary<string, object>? EventData { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,6 @@ namespace TwitchChatTTS.OBS.Socket.Data
|
|||||||
public required string RequestType { get; set; }
|
public required string RequestType { get; set; }
|
||||||
public required string RequestId { get; set; }
|
public required string RequestId { get; set; }
|
||||||
public required object RequestStatus { get; set; }
|
public required object RequestStatus { get; set; }
|
||||||
public required Dictionary<string, object> ResponseData { get; set; }
|
public Dictionary<string, object>? ResponseData { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ namespace TwitchChatTTS.OBS.Socket.Handlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
_logger.Debug($"Found the scene item by name [scene: {sceneName}][source: {sourceName}][id: {sceneItemId}][obs request id: {message.RequestId}].");
|
_logger.Debug($"Found the scene item by name [scene: {sceneName}][source: {sourceName}][id: {sceneItemId}][obs request id: {message.RequestId}].");
|
||||||
obs.AddSourceId(sourceName.ToString()!, (long)sceneItemId);
|
obs.AddSourceId(sourceName.ToString()!, long.Parse(sceneItemId.ToString()!));
|
||||||
|
|
||||||
requestData.ResponseValues = message.ResponseData;
|
requestData.ResponseValues = message.ResponseData;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user