Fixed several command errors

This commit is contained in:
RogueException
2015-08-27 15:47:28 -03:00
parent 20e267cfa4
commit 26c603531a
5 changed files with 39 additions and 42 deletions

View File

@@ -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<DiscordBotClient.CommandEventArgs, Task> Handler;
internal Func<CommandEventArgs, Task> Handler;
internal Command(string text)
{

View File

@@ -54,12 +54,12 @@ namespace Discord.Commands
return this;
}
public CommandBuilder Do(Func<DiscordBotClient.CommandEventArgs, Task> func)
public CommandBuilder Do(Func<CommandEventArgs, Task> func)
{
_command.Handler = func;
return this;
}
public CommandBuilder Do(Action<DiscordBotClient.CommandEventArgs> func)
public CommandBuilder Do(Action<CommandEventArgs> 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<CommandGroupBuilder> config = null)

View File

@@ -3,10 +3,7 @@ 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 Message Message { get; }
@@ -41,7 +38,8 @@ namespace Discord
Exception = ex;
}
}
public partial class DiscordBotClient : DiscordClient
{
public event EventHandler<CommandEventArgs> RanCommand;
private void RaiseRanCommand(CommandEventArgs args)
{

View File

@@ -16,7 +16,7 @@ namespace Discord
public bool RequireCommandCharInPublic { get; set; }
public bool RequireCommandCharInPrivate { get; set; }
public DiscordBotClient(DiscordClientConfig config = null, Func<User, int> getPermissions = null)
public DiscordBotClient(DiscordClientConfig config = null, Func<User, Server, int> getPermissions = null)
: base(config)
{
_commands = new List<Command>();
@@ -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)
{

View File

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