Added group chatters support to websocket.
This commit is contained in:
@ -24,9 +24,12 @@ namespace TwitchChatTTS.Chat.Groups
|
||||
_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)
|
||||
|
@ -21,7 +21,8 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
|
||||
public void Acknowledge(string requestId, string? json, IDictionary<string, object>? requestData)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json)) {
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
_logger.Warning($"Group JSON data is null.");
|
||||
return;
|
||||
}
|
||||
|
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}]");
|
||||
}
|
||||
}
|
||||
}
|
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)
|
||||
{
|
||||
if (json == null)
|
||||
{
|
||||
_logger.Warning("Policy JSON data is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
var data = json.Split('/');
|
||||
if (data.Length != 2)
|
||||
{
|
||||
|
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}]");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user