more work

This commit is contained in:
Kwoth 2016-12-18 01:52:53 +01:00
parent cf17d2a1ac
commit caef908a0e
7 changed files with 68 additions and 26 deletions

View File

@ -12,6 +12,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NadekoBot", "src\NadekoBot\NadekoBot.xproj", "{45EC1473-C678-4857-A544-07DFE0D0B478}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.WebSocket", "Discord.Net\src\Discord.Net.WebSocket\Discord.Net.WebSocket.xproj", "{E9800F7A-3354-41B1-BDBB-2D59F8124EC9}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Core", "Discord.Net\src\Discord.Net.Core\Discord.Net.Core.xproj", "{E5F4786F-58F3-469E-8C87-1908A95436B7}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Rest", "Discord.Net\src\Discord.Net.Rest\Discord.Net.Rest.xproj", "{63F5B5C8-56FE-4B53-8003-B58CEB451EF9}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Commands", "Discord.Net\src\Discord.Net.Commands\Discord.Net.Commands.xproj", "{8CBA56CD-A954-481E-8358-F36273757A6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -25,6 +33,30 @@ Global
{45EC1473-C678-4857-A544-07DFE0D0B478}.GlobalNadeko|Any CPU.Build.0 = GlobalNadeko|Any CPU
{45EC1473-C678-4857-A544-07DFE0D0B478}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45EC1473-C678-4857-A544-07DFE0D0B478}.Release|Any CPU.Build.0 = Release|Any CPU
{E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
{E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU
{E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Release|Any CPU.Build.0 = Release|Any CPU
{E5F4786F-58F3-469E-8C87-1908A95436B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5F4786F-58F3-469E-8C87-1908A95436B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5F4786F-58F3-469E-8C87-1908A95436B7}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
{E5F4786F-58F3-469E-8C87-1908A95436B7}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU
{E5F4786F-58F3-469E-8C87-1908A95436B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5F4786F-58F3-469E-8C87-1908A95436B7}.Release|Any CPU.Build.0 = Release|Any CPU
{63F5B5C8-56FE-4B53-8003-B58CEB451EF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63F5B5C8-56FE-4B53-8003-B58CEB451EF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63F5B5C8-56FE-4B53-8003-B58CEB451EF9}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
{63F5B5C8-56FE-4B53-8003-B58CEB451EF9}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU
{63F5B5C8-56FE-4B53-8003-B58CEB451EF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63F5B5C8-56FE-4B53-8003-B58CEB451EF9}.Release|Any CPU.Build.0 = Release|Any CPU
{8CBA56CD-A954-481E-8358-F36273757A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CBA56CD-A954-481E-8358-F36273757A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CBA56CD-A954-481E-8358-F36273757A6B}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
{8CBA56CD-A954-481E-8358-F36273757A6B}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU
{8CBA56CD-A954-481E-8358-F36273757A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CBA56CD-A954-481E-8358-F36273757A6B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -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)

View File

@ -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

View File

@ -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."));

View File

@ -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";

View File

@ -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();

View File

@ -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",