more work
This commit is contained in:
		@@ -8,6 +8,7 @@ using Discord;
 | 
			
		||||
using NadekoBot.Services.Database.Models;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using NadekoBot.Extensions;
 | 
			
		||||
using Discord.WebSocket;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Modules.Permissions
 | 
			
		||||
{
 | 
			
		||||
@@ -102,7 +103,7 @@ namespace NadekoBot.Modules.Permissions
 | 
			
		||||
            {
 | 
			
		||||
                var perms = uow.GuildConfigs.PermissionsFor(Context.Guild.Id).RootPermission;
 | 
			
		||||
                var i = 1 + 20 * (page - 1);
 | 
			
		||||
                toSend = Format.Code($"📄 Permissions page {page}") + "\n\n" + String.Join("\n", perms.AsEnumerable().Skip((page - 1) * 20).Take(20).Select(p => $"`{(i++)}.` {(p.Next == null ? Format.Bold(p.GetCommand(Context.Guild) + " [uneditable]") : (p.GetCommand(Context.Guild)))}"));
 | 
			
		||||
                toSend = Format.Code($"📄 Permissions page {page}") + "\n\n" + String.Join("\n", perms.AsEnumerable().Skip((page - 1) * 20).Take(20).Select(p => $"`{(i++)}.` {(p.Next == null ? Format.Bold(p.GetCommand((SocketGuild)Context.Guild) + " [uneditable]") : (p.GetCommand((SocketGuild)Context.Guild)))}"));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            await Context.Channel.SendMessageAsync(toSend).ConfigureAwait(false);
 | 
			
		||||
@@ -148,7 +149,7 @@ namespace NadekoBot.Modules.Permissions
 | 
			
		||||
                    uow2._context.SaveChanges();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                await Context.Channel.SendConfirmAsync($"✅ {Context.User.Mention} removed permission **{p.GetCommand(Context.Guild)}** from position #{index + 1}.").ConfigureAwait(false);
 | 
			
		||||
                await Context.Channel.SendConfirmAsync($"✅ {Context.User.Mention} removed permission **{p.GetCommand((SocketGuild)Context.Guild)}** from position #{index + 1}.").ConfigureAwait(false);
 | 
			
		||||
            }
 | 
			
		||||
            catch (ArgumentOutOfRangeException)
 | 
			
		||||
            {
 | 
			
		||||
@@ -255,7 +256,7 @@ namespace NadekoBot.Modules.Permissions
 | 
			
		||||
                        }, (id, old) => { old.RootPermission = config.RootPermission; return old; });
 | 
			
		||||
                        await uow.CompleteAsync().ConfigureAwait(false);
 | 
			
		||||
                    }
 | 
			
		||||
                    await Context.Channel.SendConfirmAsync($"`Moved permission:` \"{fromPerm.GetCommand(Context.Guild)}\" `from #{++from} to #{++to}.`").ConfigureAwait(false);
 | 
			
		||||
                    await Context.Channel.SendConfirmAsync($"`Moved permission:` \"{fromPerm.GetCommand((SocketGuild)Context.Guild)}\" `from #{++from} to #{++to}.`").ConfigureAwait(false);
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                catch (Exception e) when (e is ArgumentOutOfRangeException || e is IndexOutOfRangeException)
 | 
			
		||||
 
 | 
			
		||||
@@ -83,7 +83,7 @@ namespace NadekoBot
 | 
			
		||||
            //setup typereaders
 | 
			
		||||
            CommandService.AddTypeReader<PermissionAction>(new PermissionActionTypeReader());
 | 
			
		||||
            CommandService.AddTypeReader<CommandInfo>(new CommandTypeReader());
 | 
			
		||||
            CommandService.AddTypeReader<Module>(new ModuleTypeReader());
 | 
			
		||||
            CommandService.AddTypeReader<ModuleInfo>(new ModuleTypeReader());
 | 
			
		||||
            CommandService.AddTypeReader<IGuild>(new GuildTypeReader());
 | 
			
		||||
 | 
			
		||||
            //connect
 | 
			
		||||
 
 | 
			
		||||
@@ -60,7 +60,7 @@ namespace NadekoBot.Services
 | 
			
		||||
 | 
			
		||||
        private async Task MessageReceivedHandler(SocketMessage msg)
 | 
			
		||||
        {
 | 
			
		||||
            var usrMsg = msg as SocketUserMessage;
 | 
			
		||||
           var usrMsg = msg as SocketUserMessage;
 | 
			
		||||
            if (usrMsg == null)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
@@ -140,7 +140,7 @@ namespace NadekoBot.Services
 | 
			
		||||
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, msg.Author, MultiMatchHandling.Best);
 | 
			
		||||
                    var t = await ExecuteCommand(new CommandContext(_client.MainClient, usrMsg), usrMsg.Content, DependencyMap.Empty, MultiMatchHandling.Best);
 | 
			
		||||
                    var command = t.Item1;
 | 
			
		||||
                    var permCache = t.Item2;
 | 
			
		||||
                    var result = t.Item3;
 | 
			
		||||
@@ -206,24 +206,27 @@ namespace NadekoBot.Services
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<Tuple<CommandInfo, PermissionCache, IResult>> ExecuteCommand(IUserMessage message, string input, SocketGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {
 | 
			
		||||
            var searchResult = _commandService.Search(message, input);
 | 
			
		||||
        public async Task<Tuple<CommandInfo, PermissionCache, IResult>> ExecuteCommand(CommandContext context, string input, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
 | 
			
		||||
        {
 | 
			
		||||
            dependencyMap = dependencyMap ?? DependencyMap.Empty;
 | 
			
		||||
 | 
			
		||||
            var searchResult = _commandService.Search(context, input);
 | 
			
		||||
            if (!searchResult.IsSuccess)
 | 
			
		||||
                return new Tuple<CommandInfo, PermissionCache, IResult>(null, null, searchResult);
 | 
			
		||||
 | 
			
		||||
            var commands = searchResult.Commands;
 | 
			
		||||
            for (int i = commands.Count - 1; i >= 0; i--)
 | 
			
		||||
            {
 | 
			
		||||
                var preconditionResult = await commands[i].CheckPreconditions(message);
 | 
			
		||||
                var preconditionResult = await commands[i].CheckPreconditionsAsync(context).ConfigureAwait(false);
 | 
			
		||||
                if (!preconditionResult.IsSuccess)
 | 
			
		||||
                {
 | 
			
		||||
                    if (commands.Count == 1)
 | 
			
		||||
                        return new Tuple<CommandInfo, PermissionCache, IResult>(null, null, searchResult);
 | 
			
		||||
                        return new Tuple<CommandInfo, PermissionCache, IResult>(null, null, preconditionResult);
 | 
			
		||||
                    else
 | 
			
		||||
                        continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var parseResult = await commands[i].Parse(message, searchResult, preconditionResult);
 | 
			
		||||
                var parseResult = await commands[i].ParseAsync(context, searchResult, preconditionResult).ConfigureAwait(false);
 | 
			
		||||
                if (!parseResult.IsSuccess)
 | 
			
		||||
                {
 | 
			
		||||
                    if (parseResult.Error == CommandError.MultipleMatches)
 | 
			
		||||
@@ -251,13 +254,13 @@ namespace NadekoBot.Services
 | 
			
		||||
                var cmd = commands[i];
 | 
			
		||||
                bool resetCommand = cmd.Name == "ResetPermissions";
 | 
			
		||||
                PermissionCache pc;
 | 
			
		||||
                if (guild != null)
 | 
			
		||||
                if (context.Guild != null)
 | 
			
		||||
                {
 | 
			
		||||
                    pc = Permissions.Cache.GetOrAdd(guild.Id, (id) =>
 | 
			
		||||
                    pc = Permissions.Cache.GetOrAdd(context.Guild.Id, (id) =>
 | 
			
		||||
                    {
 | 
			
		||||
                        using (var uow = DbHandler.UnitOfWork())
 | 
			
		||||
                        {
 | 
			
		||||
                            var config = uow.GuildConfigs.PermissionsFor(guild.Id);
 | 
			
		||||
                            var config = uow.GuildConfigs.PermissionsFor(context.Guild.Id);
 | 
			
		||||
                            return new PermissionCache()
 | 
			
		||||
                            {
 | 
			
		||||
                                Verbose = config.VerbosePermissions,
 | 
			
		||||
@@ -267,16 +270,16 @@ namespace NadekoBot.Services
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                    int index;
 | 
			
		||||
                    if (!resetCommand && !pc.RootPermission.AsEnumerable().CheckPermissions(message, cmd.Aliases.First(), cmd.Module.Name, out index))
 | 
			
		||||
                    if (!resetCommand && !pc.RootPermission.AsEnumerable().CheckPermissions(context.Message, cmd.Aliases.First(), cmd.Module.Name, out index))
 | 
			
		||||
                    {
 | 
			
		||||
                        var returnMsg = $"Permission number #{index + 1} **{pc.RootPermission.GetAt(index).GetCommand(guild)}** is preventing this action.";
 | 
			
		||||
                        var returnMsg = $"Permission number #{index + 1} **{pc.RootPermission.GetAt(index).GetCommand((SocketGuild)context.Guild)}** is preventing this action.";
 | 
			
		||||
                        return new Tuple<CommandInfo, PermissionCache, IResult>(cmd, pc, SearchResult.FromError(CommandError.Exception, returnMsg));
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                    if (cmd.Module.Name == typeof(Permissions).Name)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (!((IGuildUser)user).GetRoles().Any(r => r.Name.Trim().ToLowerInvariant() == pc.PermRole.Trim().ToLowerInvariant()))
 | 
			
		||||
                        if (!((IGuildUser)context.User).GetRoles().Any(r => r.Name.Trim().ToLowerInvariant() == pc.PermRole.Trim().ToLowerInvariant()))
 | 
			
		||||
                        {
 | 
			
		||||
                            return new Tuple<CommandInfo, PermissionCache, IResult>(cmd, pc, SearchResult.FromError(CommandError.Exception, $"You need the **{pc.PermRole}** role in order to use permission commands."));
 | 
			
		||||
                        }
 | 
			
		||||
@@ -284,10 +287,10 @@ namespace NadekoBot.Services
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                if (CmdCdsCommands.HasCooldown(cmd, guild, user))
 | 
			
		||||
                if (CmdCdsCommands.HasCooldown(cmd, context.Guild, context.User))
 | 
			
		||||
                    return new Tuple<CommandInfo, PermissionCache, IResult>(cmd, null, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you."));
 | 
			
		||||
 | 
			
		||||
                return new Tuple<CommandInfo, PermissionCache, IResult>(commands[i], null, await commands[i].Execute(message, parseResult));
 | 
			
		||||
                return new Tuple<CommandInfo, PermissionCache, IResult>(commands[i], null, await commands[i].Execute(context, parseResult, dependencyMap));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return new Tuple<CommandInfo, PermissionCache, IResult>(null, null, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."));
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
        private ShardedDiscordClient client;
 | 
			
		||||
        private DateTime started;
 | 
			
		||||
 | 
			
		||||
        public const string BotVersion = "1.0-rc2";
 | 
			
		||||
        public const string BotVersion = "1.0-rc3";
 | 
			
		||||
 | 
			
		||||
        public string Author => "Kwoth#2560";
 | 
			
		||||
        public string Library => "Discord.Net";
 | 
			
		||||
 
 | 
			
		||||
@@ -60,11 +60,11 @@ namespace NadekoBot
 | 
			
		||||
            Clients = clientList.AsReadOnly();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public ISelfUser CurrentUser() =>
 | 
			
		||||
            Clients[0].CurrentUser;
 | 
			
		||||
        public DiscordSocketClient MainClient =>
 | 
			
		||||
            Clients[0];
 | 
			
		||||
 | 
			
		||||
        public ISelfUser[] GetAllCurrentUsers() =>
 | 
			
		||||
            Clients.Select(c => c.CurrentUser).ToArray();
 | 
			
		||||
        public SocketSelfUser CurrentUser() =>
 | 
			
		||||
            Clients[0].CurrentUser;
 | 
			
		||||
 | 
			
		||||
        public IReadOnlyCollection<SocketGuild> GetGuilds() =>
 | 
			
		||||
            Clients.SelectMany(c => c.Guilds).ToList();
 | 
			
		||||
 
 | 
			
		||||
@@ -39,8 +39,14 @@
 | 
			
		||||
    "NLog": "5.0.0-beta03",
 | 
			
		||||
    "System.Diagnostics.Contracts": "4.3.0",
 | 
			
		||||
    "System.Xml.XPath": "4.3.0",
 | 
			
		||||
    "Discord.Net.Commands": "1.0.0-beta2-*",
 | 
			
		||||
    "Discord.Net.WebSocket": "1.0.0-beta2-*"
 | 
			
		||||
    "Discord.Net.Commands": {
 | 
			
		||||
      "target": "project",
 | 
			
		||||
      "version": "1.0.0-*"
 | 
			
		||||
    },
 | 
			
		||||
    "Discord.Net.WebSocket": {
 | 
			
		||||
      "target": "project",
 | 
			
		||||
      "version": "1.0.0-*"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "tools": {
 | 
			
		||||
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user