diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs index df7ecb950..f8728f4c6 100644 --- a/src/Discord.Net.Commands/Command.cs +++ b/src/Discord.Net.Commands/Command.cs @@ -10,7 +10,7 @@ namespace Discord.Commands public int? MaxArgs { get; internal set; } public int MinPerms { get; internal set; } internal readonly string[] Parts; - internal Func Handler; + internal Func Handler; internal Command(string text) { diff --git a/src/Discord.Net.Commands/CommandBuilder.cs b/src/Discord.Net.Commands/CommandBuilder.cs index e6f5ce245..a13a2c850 100644 --- a/src/Discord.Net.Commands/CommandBuilder.cs +++ b/src/Discord.Net.Commands/CommandBuilder.cs @@ -54,12 +54,12 @@ namespace Discord.Commands return this; } - public CommandBuilder Do(Func func) + public CommandBuilder Do(Func func) { _command.Handler = func; return this; } - public CommandBuilder Do(Action func) + public CommandBuilder Do(Action func) { #if DNXCORE50 _command.Handler = e => { func(e); return Task.CompletedTask; }; @@ -82,10 +82,9 @@ namespace Discord.Commands _defaultMinPermissions = defaultMinPermissions; } - public CommandGroupBuilder DefaultMinPermissions(int level) + public void DefaultMinPermissions(int level) { _defaultMinPermissions = level; - return this; } public CommandGroupBuilder CreateCommandGroup(string cmd, Action config = null) diff --git a/src/Discord.Net.Commands/DiscordBotClient.Events.cs b/src/Discord.Net.Commands/DiscordBotClient.Events.cs index 38f6f98af..93c0ea44d 100644 --- a/src/Discord.Net.Commands/DiscordBotClient.Events.cs +++ b/src/Discord.Net.Commands/DiscordBotClient.Events.cs @@ -3,45 +3,43 @@ using System; namespace Discord { - public partial class DiscordBotClient : DiscordClient + public class PermissionException : Exception { public PermissionException() : base("User does not have permission to run this command.") { } } + public class CommandEventArgs { - public class PermissionException : Exception { public PermissionException() : base("User does not have permission to run this command.") { } } + public Message Message { get; } + public Command Command { get; } + public string CommandText { get; } + public int? Permissions { get; } + public string[] Args { get; } - public class CommandEventArgs - { - public Message Message { get; } - public Command Command { get; } - public string CommandText { get; } - public int? Permissions { get; } - public string[] Args { get; } - - public User User => Message.User; - public string UserId => Message.UserId; - public Channel Channel => Message.Channel; - public string ChannelId => Message.ChannelId; - public Server Server => Message.Channel.Server; - public string ServerId => Message.Channel.ServerId; + public User User => Message.User; + public string UserId => Message.UserId; + public Channel Channel => Message.Channel; + public string ChannelId => Message.ChannelId; + public Server Server => Message.Channel.Server; + public string ServerId => Message.Channel.ServerId; - public CommandEventArgs(Message message, Command command, string commandText, int? permissions, string[] args) - { - Message = message; - Command = command; - CommandText = commandText; - Permissions = permissions; - Args = args; - } - } - public class CommandErrorEventArgs : CommandEventArgs + public CommandEventArgs(Message message, Command command, string commandText, int? permissions, string[] args) { - public Exception Exception { get; } - - public CommandErrorEventArgs(CommandEventArgs baseArgs, Exception ex) - : base(baseArgs.Message, baseArgs.Command, baseArgs.CommandText, baseArgs.Permissions, baseArgs.Args) - { - Exception = ex; - } + Message = message; + Command = command; + CommandText = commandText; + Permissions = permissions; + Args = args; } + } + public class CommandErrorEventArgs : CommandEventArgs + { + public Exception Exception { get; } + public CommandErrorEventArgs(CommandEventArgs baseArgs, Exception ex) + : base(baseArgs.Message, baseArgs.Command, baseArgs.CommandText, baseArgs.Permissions, baseArgs.Args) + { + Exception = ex; + } + } + public partial class DiscordBotClient : DiscordClient + { public event EventHandler RanCommand; private void RaiseRanCommand(CommandEventArgs args) { diff --git a/src/Discord.Net.Commands/DiscordBotClient.cs b/src/Discord.Net.Commands/DiscordBotClient.cs index 857473acd..6745c7aba 100644 --- a/src/Discord.Net.Commands/DiscordBotClient.cs +++ b/src/Discord.Net.Commands/DiscordBotClient.cs @@ -16,7 +16,7 @@ namespace Discord public bool RequireCommandCharInPublic { get; set; } public bool RequireCommandCharInPrivate { get; set; } - public DiscordBotClient(DiscordClientConfig config = null, Func getPermissions = null) + public DiscordBotClient(DiscordClientConfig config = null, Func getPermissions = null) : base(config) { _commands = new List(); @@ -56,7 +56,7 @@ namespace Discord Command cmd = _commands[i]; //Check Command Parts - if (args.Length < cmd.Text.Length) + if (args.Length < cmd.Parts.Length) continue; bool isValid = true; @@ -82,7 +82,7 @@ namespace Discord newArgs[j] = args[j + cmd.Parts.Length]; //Check Permissions - int permissions = getPermissions != null ? getPermissions(e.Message.User) : 0; + int permissions = getPermissions != null ? getPermissions(e.Message.User, e.Message.Channel?.Server) : 0; var eventArgs = new CommandEventArgs(e.Message, cmd, msg, permissions, newArgs); if (permissions < cmd.MinPerms) { diff --git a/src/Discord.Net.Commands/project.json b/src/Discord.Net.Commands/project.json index a2e150e19..b15721376 100644 --- a/src/Discord.Net.Commands/project.json +++ b/src/Discord.Net.Commands/project.json @@ -1,5 +1,5 @@ { - "version": "0.6.0-beta1", + "version": "0.6.0-beta2", "description": "A small Discord.Net extension to make bot creation easier.", "authors": [ "RogueException" ], "tags": [ "discord", "discordapp" ],