Fixed 7tv & Twitch reconnection. Added adbreak, follow, subscription handlers for Twitch. Added multi-chat support. Added support to unsubscribe from Twitch event subs.
This commit is contained in:
@@ -12,62 +12,75 @@ namespace TwitchChatTTS.Chat.Groups
|
||||
private readonly ILogger _logger;
|
||||
|
||||
|
||||
public ChatterGroupManager(ILogger logger) {
|
||||
public ChatterGroupManager(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_groups = new ConcurrentDictionary<string, Group>();
|
||||
_chatters = new ConcurrentDictionary<long, ICollection<string>>();
|
||||
}
|
||||
|
||||
public void Add(Group group) {
|
||||
public void Add(Group group)
|
||||
{
|
||||
_groups.Add(group.Name, group);
|
||||
}
|
||||
|
||||
public void Add(long chatter, string groupName) {
|
||||
public void Add(long chatter, string groupName)
|
||||
{
|
||||
_chatters.Add(chatter, new List<string>() { groupName });
|
||||
}
|
||||
|
||||
public void Add(long chatter, ICollection<string> groupNames) {
|
||||
if (_chatters.TryGetValue(chatter, out var list)) {
|
||||
public void Add(long chatter, ICollection<string> groupNames)
|
||||
{
|
||||
if (_chatters.TryGetValue(chatter, out var list))
|
||||
{
|
||||
foreach (var group in groupNames)
|
||||
list.Add(group);
|
||||
} else
|
||||
}
|
||||
else
|
||||
_chatters.Add(chatter, groupNames);
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
public void Clear()
|
||||
{
|
||||
_groups.Clear();
|
||||
_chatters.Clear();
|
||||
}
|
||||
|
||||
public Group? Get(string groupName) {
|
||||
public Group? Get(string groupName)
|
||||
{
|
||||
if (_groups.TryGetValue(groupName, out var group))
|
||||
return group;
|
||||
return null;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetGroupNamesFor(long chatter) {
|
||||
public IEnumerable<string> GetGroupNamesFor(long chatter)
|
||||
{
|
||||
if (_chatters.TryGetValue(chatter, out var groups))
|
||||
return groups.Select(g => _groups[g].Name);
|
||||
|
||||
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
public int GetPriorityFor(long chatter) {
|
||||
public int GetPriorityFor(long chatter)
|
||||
{
|
||||
if (!_chatters.TryGetValue(chatter, out var groups))
|
||||
return 0;
|
||||
|
||||
|
||||
return GetPriorityFor(groups);
|
||||
}
|
||||
|
||||
public int GetPriorityFor(IEnumerable<string> groupNames) {
|
||||
public int GetPriorityFor(IEnumerable<string> groupNames)
|
||||
{
|
||||
var values = groupNames.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;
|
||||
}
|
||||
|
||||
public bool Remove(long chatterId, string groupId) {
|
||||
if (_chatters.TryGetValue(chatterId, out var groups)) {
|
||||
public bool Remove(long chatterId, string groupId)
|
||||
{
|
||||
if (_chatters.TryGetValue(chatterId, out var groups))
|
||||
{
|
||||
groups.Remove(groupId);
|
||||
_logger.Debug($"Removed chatter from group [chatter id: {chatterId}][group name: {_groups[groupId]}][group id: {groupId}]");
|
||||
return true;
|
||||
|
||||
@@ -23,6 +23,13 @@ namespace TwitchChatTTS.Chat.Groups.Permissions
|
||||
return res;
|
||||
}
|
||||
|
||||
public bool? CheckIfDirectAllowed(string path)
|
||||
{
|
||||
var res = Get(path)?.DirectAllow;
|
||||
_logger.Debug($"Permission Node GET {path} = {res?.ToString() ?? "null"} [direct]");
|
||||
return res;
|
||||
}
|
||||
|
||||
public bool? CheckIfAllowed(IEnumerable<string> groups, string path)
|
||||
{
|
||||
bool overall = false;
|
||||
@@ -37,6 +44,20 @@ namespace TwitchChatTTS.Chat.Groups.Permissions
|
||||
return overall ? true : null;
|
||||
}
|
||||
|
||||
public bool? CheckIfDirectAllowed(IEnumerable<string> groups, string path)
|
||||
{
|
||||
bool overall = false;
|
||||
foreach (var group in groups)
|
||||
{
|
||||
var result = CheckIfDirectAllowed($"{group}.{path}");
|
||||
if (result == false)
|
||||
return false;
|
||||
if (result == true)
|
||||
overall = true;
|
||||
}
|
||||
return overall ? true : null;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_root.Clear();
|
||||
@@ -104,6 +125,7 @@ namespace TwitchChatTTS.Chat.Groups.Permissions
|
||||
}
|
||||
set => _allow = value;
|
||||
}
|
||||
public bool? DirectAllow { get => _allow; }
|
||||
|
||||
internal PermissionNode? Parent { get => _parent; }
|
||||
public IList<PermissionNode>? Children { get => _children == null ? null : new ReadOnlyCollection<PermissionNode>(_children); }
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace TwitchChatTTS.Chat.Groups.Permissions
|
||||
void Set(string path, bool? allow);
|
||||
bool? CheckIfAllowed(string path);
|
||||
bool? CheckIfAllowed(IEnumerable<string> groups, string path);
|
||||
bool? CheckIfDirectAllowed(string path);
|
||||
bool? CheckIfDirectAllowed(IEnumerable<string> groups, string path);
|
||||
void Clear();
|
||||
bool Remove(string path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user