Added group support for websockets.
This commit is contained in:
@ -77,6 +77,16 @@ namespace TwitchChatTTS.Chat.Groups
|
||||
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)
|
||||
{
|
||||
if (_chatters.TryGetValue(chatterId, out var groups))
|
||||
|
@ -12,6 +12,8 @@ namespace TwitchChatTTS.Chat.Groups
|
||||
IEnumerable<string> GetGroupNamesFor(long chatter);
|
||||
int GetPriorityFor(long chatter);
|
||||
int GetPriorityFor(IEnumerable<string> groupIds);
|
||||
void Modify(Group group);
|
||||
bool Remove(string groupId);
|
||||
bool Remove(long chatter, string groupId);
|
||||
}
|
||||
}
|
48
Hermes/Socket/Requests/CreateGroupAck.cs
Normal file
48
Hermes/Socket/Requests/CreateGroupAck.cs
Normal file
@ -0,0 +1,48 @@
|
||||
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}]");
|
||||
}
|
||||
}
|
||||
}
|
@ -24,10 +24,15 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
|
||||
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);
|
||||
if (policy == null)
|
||||
{
|
||||
_logger.Warning($"Policy JSON data is null.");
|
||||
_logger.Warning($"Policy data is null.");
|
||||
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}]");
|
||||
}
|
||||
}
|
||||
}
|
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}]");
|
||||
}
|
||||
}
|
||||
}
|
@ -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}].");
|
||||
obs.AddSourceId(sourceName.ToString()!, (long)sceneItemId);
|
||||
obs.AddSourceId(sourceName.ToString()!, long.Parse(sceneItemId.ToString()!));
|
||||
|
||||
requestData.ResponseValues = message.ResponseData;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user