mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-11-04 16:44:28 -05:00
Early behavior fixups:
- Priorities are now higher number -> higher priority - Priorities are now actually respected - Early behaviors now print custom messages when they perform an action (Filter trigger, blacklist, poll vote, etc) - small cleanup
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Db;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
@@ -17,9 +18,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
private readonly IPubSub _pubSub;
|
||||
private readonly IBotCredentials _creds;
|
||||
private IReadOnlyList<BlacklistEntry> _blacklist;
|
||||
public int Priority => -100;
|
||||
|
||||
public ModuleBehaviorType BehaviorType => ModuleBehaviorType.Blocker;
|
||||
public int Priority => int.MaxValue;
|
||||
|
||||
private readonly TypedKey<BlacklistEntry[]> blPubKey = new TypedKey<BlacklistEntry[]>("blacklist.reload");
|
||||
public BlacklistService(DbService db, IPubSub pubSub, IBotCredentials creds)
|
||||
@@ -43,13 +42,31 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
foreach (var bl in _blacklist)
|
||||
{
|
||||
if (guild != null && bl.Type == BlacklistType.Server && bl.ItemId == guild.Id)
|
||||
{
|
||||
Log.Information("Blocked input from blacklisted guild: {GuildName} [{GuildId}]",
|
||||
guild.Name,
|
||||
guild.Id);
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
if (bl.Type == BlacklistType.Channel && bl.ItemId == usrMsg.Channel.Id)
|
||||
{
|
||||
Log.Information("Blocked input from blacklisted channel: {ChannelName} [{ChannelId}]",
|
||||
usrMsg.Channel.Name,
|
||||
usrMsg.Channel.Id);
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
if (bl.Type == BlacklistType.User && bl.ItemId == usrMsg.Author.Id)
|
||||
{
|
||||
Log.Information("Blocked input from blacklisted user: {UserName} [{UserId}]",
|
||||
usrMsg.Author.ToString(),
|
||||
usrMsg.Author.Id);
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.FromResult(false);
|
||||
|
||||
@@ -17,7 +17,7 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
public class FilterService : IEarlyBehavior
|
||||
public sealed class FilterService : IEarlyBehavior
|
||||
{
|
||||
private readonly DbService _db;
|
||||
|
||||
@@ -33,8 +33,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
public ConcurrentHashSet<ulong> LinkFilteringChannels { get; }
|
||||
public ConcurrentHashSet<ulong> LinkFilteringServers { get; }
|
||||
|
||||
public int Priority => -50;
|
||||
public ModuleBehaviorType BehaviorType => ModuleBehaviorType.Blocker;
|
||||
public int Priority => int.MaxValue - 1;
|
||||
|
||||
public ConcurrentHashSet<string> FilteredWordsForChannel(ulong channelId, ulong guildId)
|
||||
{
|
||||
@@ -136,7 +135,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
return results.Any(x => x);
|
||||
}
|
||||
|
||||
public async Task<bool> FilterWords(IGuild guild, IUserMessage usrMsg)
|
||||
private async Task<bool> FilterWords(IGuild guild, IUserMessage usrMsg)
|
||||
{
|
||||
if (guild is null)
|
||||
return false;
|
||||
@@ -153,6 +152,11 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
if (filteredChannelWords.Contains(word) ||
|
||||
filteredServerWords.Contains(word))
|
||||
{
|
||||
Log.Information("User {UserName} [{UserId}] used a filtered word in {ChannelId} channel",
|
||||
usrMsg.Author.ToString(),
|
||||
usrMsg.Author.Id,
|
||||
usrMsg.Channel.Id);
|
||||
|
||||
try
|
||||
{
|
||||
await usrMsg.DeleteAsync().ConfigureAwait(false);
|
||||
@@ -168,7 +172,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> FilterInvites(IGuild guild, IUserMessage usrMsg)
|
||||
private async Task<bool> FilterInvites(IGuild guild, IUserMessage usrMsg)
|
||||
{
|
||||
if (guild is null)
|
||||
return false;
|
||||
@@ -179,6 +183,11 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
|| InviteFilteringServers.Contains(guild.Id))
|
||||
&& usrMsg.Content.IsDiscordInvite())
|
||||
{
|
||||
Log.Information("User {UserName} [{UserId}] sent a filtered invite to {ChannelId} channel",
|
||||
usrMsg.Author.ToString(),
|
||||
usrMsg.Author.Id,
|
||||
usrMsg.Channel.Id);
|
||||
|
||||
try
|
||||
{
|
||||
await usrMsg.DeleteAsync().ConfigureAwait(false);
|
||||
@@ -193,7 +202,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> FilterLinks(IGuild guild, IUserMessage usrMsg)
|
||||
private async Task<bool> FilterLinks(IGuild guild, IUserMessage usrMsg)
|
||||
{
|
||||
if (guild is null)
|
||||
return false;
|
||||
@@ -204,6 +213,11 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
|| LinkFilteringServers.Contains(guild.Id))
|
||||
&& usrMsg.Content.TryGetUrlPath(out _))
|
||||
{
|
||||
Log.Information("User {UserName} [{UserId}] sent a filtered link to {ChannelId} channel",
|
||||
usrMsg.Author.ToString(),
|
||||
usrMsg.Author.Id,
|
||||
usrMsg.Channel.Id);
|
||||
|
||||
try
|
||||
{
|
||||
await usrMsg.DeleteAsync().ConfigureAwait(false);
|
||||
|
||||
Reference in New Issue
Block a user