fix: .verbose will now also be respected for expressions

This commit is contained in:
Kwoth
2024-05-18 15:34:16 +00:00
parent 8ac07ce6d7
commit 03fb1a5ca2

View File

@@ -6,6 +6,7 @@ using NadekoBot.Db;
using NadekoBot.Db.Models; using NadekoBot.Db.Models;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using LinqToDB.EntityFrameworkCore; using LinqToDB.EntityFrameworkCore;
using NadekoBot.Modules.Permissions.Services;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization.NamingConventions;
@@ -77,6 +78,7 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor
private bool ready; private bool ready;
private ConcurrentHashSet<ulong> _disabledGlobalExpressionGuilds; private ConcurrentHashSet<ulong> _disabledGlobalExpressionGuilds;
private readonly PermissionService _pc;
public NadekoExpressionsService( public NadekoExpressionsService(
DbService db, DbService db,
@@ -87,7 +89,8 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor
IPubSub pubSub, IPubSub pubSub,
IMessageSenderService sender, IMessageSenderService sender,
IReplacementService repSvc, IReplacementService repSvc,
IPermissionChecker permChecker) IPermissionChecker permChecker,
PermissionService pc)
{ {
_db = db; _db = db;
_client = client; _client = client;
@@ -98,6 +101,7 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor
_sender = sender; _sender = sender;
_repSvc = repSvc; _repSvc = repSvc;
_permChecker = permChecker; _permChecker = permChecker;
_pc = pc;
_rng = new NadekoRandom(); _rng = new NadekoRandom();
_pubSub.Sub(_exprsReloadedKey, OnExprsShouldReload); _pubSub.Sub(_exprsReloadedKey, OnExprsShouldReload);
@@ -138,6 +142,7 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor
var globalItems = uow.Set<NadekoExpression>() var globalItems = uow.Set<NadekoExpression>()
.AsNoTracking() .AsNoTracking()
.Where(x => x.GuildId == null || x.GuildId == 0) .Where(x => x.GuildId == null || x.GuildId == 0)
.Where(x => x.Trigger != null)
.AsEnumerable() .AsEnumerable()
.Select(x => .Select(x =>
{ {
@@ -256,6 +261,9 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor
); );
if (!result.IsAllowed) if (!result.IsAllowed)
{
var cache = _pc.GetCacheFor(guild.Id);
if (cache.Verbose)
{ {
if (result.TryPickT3(out var disallowed, out _)) if (result.TryPickT3(out var disallowed, out _))
{ {
@@ -275,6 +283,7 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor
Log.Information("{PermissionMessage}", permissionMessage); Log.Information("{PermissionMessage}", permissionMessage);
} }
}
return true; return true;
} }