Fixed several command errors
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 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)
|
||||
{
|
||||
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 CommandEventArgs(Message message, Command command, string commandText, int? permissions, string[] args)
|
||||
{
|
||||
Message = message;
|
||||
Command = command;
|
||||
CommandText = commandText;
|
||||
Permissions = permissions;
|
||||
Args = args;
|
||||
}
|
||||
Message = message;
|
||||
Command = command;
|
||||
CommandText = commandText;
|
||||
Permissions = permissions;
|
||||
Args = args;
|
||||
}
|
||||
public class CommandErrorEventArgs : CommandEventArgs
|
||||
}
|
||||
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)
|
||||
{
|
||||
public Exception Exception { get; }
|
||||
|
||||
public CommandErrorEventArgs(CommandEventArgs baseArgs, Exception ex)
|
||||
: base(baseArgs.Message, baseArgs.Command, baseArgs.CommandText, baseArgs.Permissions, baseArgs.Args)
|
||||
{
|
||||
Exception = ex;
|
||||
}
|
||||
Exception = ex;
|
||||
}
|
||||
|
||||
}
|
||||
public partial class DiscordBotClient : DiscordClient
|
||||
{
|
||||
public event EventHandler<CommandEventArgs> RanCommand;
|
||||
private void RaiseRanCommand(CommandEventArgs args)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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" ],
|
||||
|
||||
Reference in New Issue
Block a user