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:
		@@ -9,14 +9,6 @@ namespace NadekoBot.Common.ModuleBehaviors
 | 
			
		||||
    public interface IEarlyBehavior
 | 
			
		||||
    {
 | 
			
		||||
        int Priority { get; }
 | 
			
		||||
        ModuleBehaviorType BehaviorType { get; }
 | 
			
		||||
 | 
			
		||||
        Task<bool> RunBehavior(IGuild guild, IUserMessage msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public enum ModuleBehaviorType
 | 
			
		||||
    {
 | 
			
		||||
        Blocker,
 | 
			
		||||
        Executor,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -4,13 +4,12 @@ using System.Threading.Tasks;
 | 
			
		||||
using Discord.Commands;
 | 
			
		||||
using NadekoBot.Services;
 | 
			
		||||
using NadekoBot.Modules.CustomReactions.Services;
 | 
			
		||||
using NadekoBot.Common.TypeReaders;
 | 
			
		||||
using Discord.WebSocket;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Common.TypeReaders
 | 
			
		||||
{
 | 
			
		||||
    public class CommandTypeReader : NadekoTypeReader<CommandInfo>
 | 
			
		||||
    public sealed class CommandTypeReader : NadekoTypeReader<CommandInfo>
 | 
			
		||||
    {
 | 
			
		||||
        public CommandTypeReader(DiscordSocketClient client, CommandService cmds) : base(client, cmds)
 | 
			
		||||
        {
 | 
			
		||||
@@ -18,16 +17,17 @@ namespace NadekoBot.Common.TypeReaders
 | 
			
		||||
 | 
			
		||||
        public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
 | 
			
		||||
        {
 | 
			
		||||
            var _cmds = services.GetService<CommandService>();
 | 
			
		||||
            var _cmdHandler = services.GetService<CommandHandler>();
 | 
			
		||||
            var cmds = services.GetRequiredService<CommandService>();
 | 
			
		||||
            var cmdHandler = services.GetRequiredService<CommandHandler>();
 | 
			
		||||
            
 | 
			
		||||
            input = input.ToUpperInvariant();
 | 
			
		||||
            var prefix = _cmdHandler.GetPrefix(context.Guild);
 | 
			
		||||
            var prefix = cmdHandler.GetPrefix(context.Guild);
 | 
			
		||||
            if (!input.StartsWith(prefix.ToUpperInvariant(), StringComparison.InvariantCulture))
 | 
			
		||||
                return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such command found."));
 | 
			
		||||
 | 
			
		||||
            input = input.Substring(prefix.Length);
 | 
			
		||||
 | 
			
		||||
            var cmd = _cmds.Commands.FirstOrDefault(c =>
 | 
			
		||||
            var cmd = cmds.Commands.FirstOrDefault(c =>
 | 
			
		||||
                c.Aliases.Select(a => a.ToUpperInvariant()).Contains(input));
 | 
			
		||||
            if (cmd is null)
 | 
			
		||||
                return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such command found."));
 | 
			
		||||
@@ -36,7 +36,7 @@ namespace NadekoBot.Common.TypeReaders
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class CommandOrCrTypeReader : NadekoTypeReader<CommandOrCrInfo>
 | 
			
		||||
    public sealed class CommandOrCrTypeReader : NadekoTypeReader<CommandOrCrInfo>
 | 
			
		||||
    {
 | 
			
		||||
        private readonly DiscordSocketClient _client;
 | 
			
		||||
        private readonly CommandService _cmds;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user