Fixed groups & their websocket support.
This commit is contained in:
@ -21,26 +21,27 @@ namespace TwitchChatTTS.Chat.Groups
|
||||
|
||||
public void Add(Group group)
|
||||
{
|
||||
_groups.Add(group.Name, group);
|
||||
_groups.Add(group.Id, group);
|
||||
}
|
||||
|
||||
public void Add(long chatter, string groupId)
|
||||
public void Add(long chatterId, string groupId)
|
||||
{
|
||||
if (_chatters.TryGetValue(chatter, out var list))
|
||||
list.Add(groupId);
|
||||
if (_chatters.TryGetValue(chatterId, out var list))
|
||||
if (!list.Contains(groupId))
|
||||
list.Add(groupId);
|
||||
else
|
||||
_chatters.Add(chatter, new List<string>() { groupId });
|
||||
_chatters.Add(chatterId, new List<string>() { groupId });
|
||||
}
|
||||
|
||||
public void Add(long chatter, ICollection<string> groupNames)
|
||||
public void Add(long chatter, ICollection<string> groupIds)
|
||||
{
|
||||
if (_chatters.TryGetValue(chatter, out var list))
|
||||
{
|
||||
foreach (var group in groupNames)
|
||||
foreach (var group in groupIds)
|
||||
list.Add(group);
|
||||
}
|
||||
else
|
||||
_chatters.Add(chatter, groupNames);
|
||||
_chatters.Add(chatter, groupIds);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
@ -49,9 +50,9 @@ namespace TwitchChatTTS.Chat.Groups
|
||||
_chatters.Clear();
|
||||
}
|
||||
|
||||
public Group? Get(string groupName)
|
||||
public Group? Get(string groupId)
|
||||
{
|
||||
if (_groups.TryGetValue(groupName, out var group))
|
||||
if (_groups.TryGetValue(groupId, out var group))
|
||||
return group;
|
||||
return null;
|
||||
}
|
||||
@ -59,7 +60,9 @@ namespace TwitchChatTTS.Chat.Groups
|
||||
public IEnumerable<string> GetGroupNamesFor(long chatter)
|
||||
{
|
||||
if (_chatters.TryGetValue(chatter, out var groups))
|
||||
return groups.Select(g => _groups[g].Name);
|
||||
return groups.Select(g => _groups.TryGetValue(g, out var group) ? group.Name : null)
|
||||
.Where(g => g != null)
|
||||
.Cast<string>();
|
||||
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
@ -72,9 +75,9 @@ namespace TwitchChatTTS.Chat.Groups
|
||||
return GetPriorityFor(groups);
|
||||
}
|
||||
|
||||
public int GetPriorityFor(IEnumerable<string> groupNames)
|
||||
public int GetPriorityFor(IEnumerable<string> groupIds)
|
||||
{
|
||||
var values = groupNames.Select(g => _groups.TryGetValue(g, out var group) ? group : null).Where(g => g != null);
|
||||
var values = groupIds.Select(g => _groups.TryGetValue(g, out var group) ? group : null).Where(g => g != null);
|
||||
if (values.Any())
|
||||
return values.Max(g => g!.Priority);
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user