diff --git a/NadekoBot.sln b/NadekoBot.sln index 6a872243..350bd395 100644 --- a/NadekoBot.sln +++ b/NadekoBot.sln @@ -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 diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index 5c50f075..7d260490 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -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) diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index 6168b062..1178508e 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -83,7 +83,7 @@ namespace NadekoBot //setup typereaders CommandService.AddTypeReader(new PermissionActionTypeReader()); CommandService.AddTypeReader(new CommandTypeReader()); - CommandService.AddTypeReader(new ModuleTypeReader()); + CommandService.AddTypeReader(new ModuleTypeReader()); CommandService.AddTypeReader(new GuildTypeReader()); //connect diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index d00c2e00..42d4e9d1 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -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> ExecuteCommand(IUserMessage message, string input, SocketGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) { - var searchResult = _commandService.Search(message, input); + public async Task> 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(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(null, null, searchResult); + return new Tuple(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(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(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(cmd, null, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you.")); - return new Tuple(commands[i], null, await commands[i].Execute(message, parseResult)); + return new Tuple(commands[i], null, await commands[i].Execute(context, parseResult, dependencyMap)); } return new Tuple(null, null, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload.")); diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 357a5f32..a691b373 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -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"; diff --git a/src/NadekoBot/ShardedDiscordClient.cs b/src/NadekoBot/ShardedDiscordClient.cs index 6be032d6..450289e6 100644 --- a/src/NadekoBot/ShardedDiscordClient.cs +++ b/src/NadekoBot/ShardedDiscordClient.cs @@ -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 GetGuilds() => Clients.SelectMany(c => c.Guilds).ToList(); diff --git a/src/NadekoBot/project.json b/src/NadekoBot/project.json index c12a7bf9..31325e07 100644 --- a/src/NadekoBot/project.json +++ b/src/NadekoBot/project.json @@ -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",