mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -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:
		@@ -48,8 +48,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
 | 
			
		||||
        private CustomReaction[] _globalReactions;
 | 
			
		||||
        private ConcurrentDictionary<ulong, CustomReaction[]> _newGuildReactions;
 | 
			
		||||
 | 
			
		||||
        public int Priority => -1;
 | 
			
		||||
        public ModuleBehaviorType BehaviorType => ModuleBehaviorType.Executor;
 | 
			
		||||
        public int Priority => 0;
 | 
			
		||||
 | 
			
		||||
        private readonly DbService _db;
 | 
			
		||||
        private readonly DiscordSocketClient _client;
 | 
			
		||||
@@ -395,6 +394,10 @@ namespace NadekoBot.Modules.CustomReactions.Services
 | 
			
		||||
            {
 | 
			
		||||
                if (_gperm.BlockedModules.Contains("ActualCustomReactions"))
 | 
			
		||||
                {
 | 
			
		||||
                    Log.Information("User {UserName} [{UserId}] tried to use a custom reaction but 'ActualCustomReactions' are globally disabled.",
 | 
			
		||||
                        msg.Author.ToString(),
 | 
			
		||||
                        msg.Author.Id);
 | 
			
		||||
                    
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@@ -454,6 +457,13 @@ namespace NadekoBot.Modules.CustomReactions.Services
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Log.Information("s: {GuildId} c: {ChannelId} u: {UserId} | {UserName} executed expression {Expr}",
 | 
			
		||||
                    guild.Id,
 | 
			
		||||
                    msg.Channel.Id,
 | 
			
		||||
                    msg.Author.Id,
 | 
			
		||||
                    msg.Author.ToString(),
 | 
			
		||||
                    cr.Trigger);
 | 
			
		||||
                
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
 
 | 
			
		||||
@@ -26,8 +26,7 @@ namespace NadekoBot.Modules.Games.Services
 | 
			
		||||
 | 
			
		||||
        public ConcurrentDictionary<ulong, Lazy<IChatterBotSession>> ChatterBotGuilds { get; }
 | 
			
		||||
 | 
			
		||||
        public int Priority => -1;
 | 
			
		||||
        public ModuleBehaviorType BehaviorType => ModuleBehaviorType.Executor;
 | 
			
		||||
        public int Priority => 1;
 | 
			
		||||
 | 
			
		||||
        public ChatterBotService(DiscordSocketClient client, PermissionService perms,
 | 
			
		||||
            Bot bot, CommandHandler cmd, IBotStrings strings, IHttpClientFactory factory,
 | 
			
		||||
 
 | 
			
		||||
@@ -19,8 +19,7 @@ namespace NadekoBot.Modules.Games.Services
 | 
			
		||||
    {
 | 
			
		||||
        public ConcurrentDictionary<ulong, PollRunner> ActivePolls { get; } = new ConcurrentDictionary<ulong, PollRunner>();
 | 
			
		||||
 | 
			
		||||
        public int Priority => -5;
 | 
			
		||||
        public ModuleBehaviorType BehaviorType => ModuleBehaviorType.Executor;
 | 
			
		||||
        public int Priority => 5;
 | 
			
		||||
 | 
			
		||||
        private readonly DbService _db;
 | 
			
		||||
        private readonly IBotStrings _strs;
 | 
			
		||||
@@ -115,7 +114,18 @@ namespace NadekoBot.Modules.Games.Services
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return await poll.TryVote(msg).ConfigureAwait(false);
 | 
			
		||||
                var voted = await poll.TryVote(msg).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
                if (voted)
 | 
			
		||||
                {
 | 
			
		||||
                    Log.Information("User {UserName} [{UserId}] voted in a poll on {GuildName} [{GuildId}] server",
 | 
			
		||||
                        msg.Author.ToString(),
 | 
			
		||||
                        msg.Author.Id,
 | 
			
		||||
                        guild.Name,
 | 
			
		||||
                        guild.Id);
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
                return voted;
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -11,20 +11,18 @@ using NadekoBot.Modules.Searches.Common.StreamNotifications;
 | 
			
		||||
using NadekoBot.Services;
 | 
			
		||||
using NadekoBot.Services.Database.Models;
 | 
			
		||||
using NadekoBot.Extensions;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using StackExchange.Redis;
 | 
			
		||||
using Discord;
 | 
			
		||||
using Discord.WebSocket;
 | 
			
		||||
using NadekoBot.Common.Collections;
 | 
			
		||||
using NadekoBot.Common.Replacements;
 | 
			
		||||
using NadekoBot.Db;
 | 
			
		||||
using NadekoBot.Modules.Administration;
 | 
			
		||||
using NadekoBot.Db.Models;
 | 
			
		||||
using Serilog;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Modules.Searches.Services
 | 
			
		||||
{
 | 
			
		||||
    public class StreamNotificationService : INService
 | 
			
		||||
    public sealed class StreamNotificationService : INService
 | 
			
		||||
    {
 | 
			
		||||
        private readonly DbService _db;
 | 
			
		||||
        private readonly IBotStrings _strings;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user