Fixed TTS using StreamElements. Fixed several issues.

This commit is contained in:
Tom
2026-01-03 05:19:33 +00:00
parent fb04f4003f
commit aa89578297
16 changed files with 275 additions and 135 deletions

View File

@@ -5,33 +5,51 @@ namespace TwitchChatTTS.Chat.Groups.Permissions
{
public class GroupPermissionManager : IGroupPermissionManager
{
private PermissionNode _root;
private ILogger _logger;
private readonly PermissionNode _root;
private readonly ILogger _logger;
private readonly ReaderWriterLockSlim _rwls;
public GroupPermissionManager(ILogger logger)
{
_logger = logger;
_root = new PermissionNode(string.Empty, null, null);
_rwls = new ReaderWriterLockSlim();
}
public bool? CheckIfAllowed(string path)
{
var res = Get(path)!.Allow;
_logger.Debug($"Permission Node GET {path} = {res?.ToString() ?? "null"}");
return res;
_rwls.EnterReadLock();
try
{
var res = Get(path)!.Allow;
_logger.Debug($"Permission Node GET {path} = {res?.ToString() ?? "null"}");
return res;
}
finally
{
_rwls.ExitReadLock();
}
}
public bool? CheckIfDirectAllowed(string path)
{
var node = Get(path, nullIfMissing: true);
if (node == null)
return null;
var res = node.DirectAllow;
_logger.Debug($"Permission Node GET {path} = {res?.ToString() ?? "null"} [direct]");
return res;
_rwls.EnterReadLock();
try
{
var node = Get(path, nullIfMissing: true);
if (node == null)
return null;
var res = node.DirectAllow;
_logger.Debug($"Permission Node GET {path} = {res?.ToString() ?? "null"} [direct]");
return res;
}
finally
{
_rwls.ExitReadLock();
}
}
public bool? CheckIfAllowed(IEnumerable<string> groups, string path)
@@ -64,31 +82,63 @@ namespace TwitchChatTTS.Chat.Groups.Permissions
public void Clear()
{
_root.Clear();
_rwls.EnterWriteLock();
try
{
_root.Clear();
}
finally
{
_rwls.ExitWriteLock();
}
}
public bool Remove(string path)
{
var node = Get(path);
if (node == null || node.Parent == null)
return false;
var parts = path.Split('.');
var last = parts.Last();
if (parts.Length > 1 && parts[parts.Length - 1] == node.Parent.Name || parts.Length == 1 && node.Parent.Name == null)
_rwls.EnterUpgradeableReadLock();
try
{
node.Parent.Remove(last);
_logger.Debug($"Permission Node REMOVE priv {path}");
return true;
var node = Get(path);
if (node == null || node.Parent == null)
return false;
_rwls.EnterWriteLock();
try
{
var parts = path.Split('.');
var last = parts.Last();
if (parts.Length > 1 && parts[parts.Length - 1] == node.Parent.Name || parts.Length == 1 && node.Parent.Name == null)
{
node.Parent.Remove(last);
_logger.Debug($"Permission Node REMOVE priv {path}");
return true;
}
return false;
}
finally
{
_rwls.ExitWriteLock();
}
}
finally
{
_rwls.ExitUpgradeableReadLock();
}
return false;
}
public void Set(string path, bool? allow)
{
var node = Get(path, true);
node!.Allow = allow;
_logger.Debug($"Permission Node ADD {path} = {allow?.ToString() ?? "null"}");
_rwls.EnterWriteLock();
try
{
var node = Get(path, true);
node!.Allow = allow;
_logger.Debug($"Permission Node ADD {path} = {allow?.ToString() ?? "null"}");
}
finally
{
_rwls.ExitWriteLock();
}
}
private PermissionNode? Get(string path, bool edit = false, bool nullIfMissing = false)