+ This commit also adds overwrites for CommandContexts; this allows for additional remarks for the class.pull/988/head
@@ -0,0 +1,9 @@ | |||||
--- | |||||
uid: Discord.Commands.CommandContext | |||||
--- | |||||
An example of how this class is used the command system can be seen | |||||
below: | |||||
[!code[Sample module](../../guides/commands/samples/empty-module.cs)] | |||||
[!code[Command handler](../../guides/commands/samples/command_handler.cs)] |
@@ -0,0 +1,9 @@ | |||||
--- | |||||
uid: Discord.Commands.SocketCommandContext | |||||
--- | |||||
An example of how this class is used the command system can be seen | |||||
below: | |||||
[!code[Sample module](../../guides/commands/samples/empty-module.cs)] | |||||
[!code[Command handler](../../guides/commands/samples/command_handler.cs)] |
@@ -55,6 +55,7 @@ | |||||
"template":[ | "template":[ | ||||
"default" | "default" | ||||
], | ], | ||||
"overwrite": "_overwrites/**/**.md", | |||||
"globalMetadata":{ | "globalMetadata":{ | ||||
"_appFooter":"Discord.Net (c) 2015-2018 2.0.0-beta", | "_appFooter":"Discord.Net (c) 2015-2018 2.0.0-beta", | ||||
"_enableSearch":true | "_enableSearch":true | ||||
@@ -2,7 +2,7 @@ using System; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> Provides aliases for a command. </summary> | |||||
/// <summary> Marks the aliases for a command. </summary> | |||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
public class AliasAttribute : Attribute | public class AliasAttribute : Attribute | ||||
{ | { | ||||
@@ -2,7 +2,7 @@ using System; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> Provides the execution information for a command. </summary> | |||||
/// <summary> Marks the execution information for a command. </summary> | |||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
public class CommandAttribute : Attribute | public class CommandAttribute : Attribute | ||||
{ | { | ||||
@@ -2,7 +2,7 @@ using System; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> Prevents the module from being loaded automatically. </summary> | |||||
/// <summary> Prevents the marked module from being loaded automatically. </summary> | |||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] | ||||
public class DontAutoLoadAttribute : Attribute | public class DontAutoLoadAttribute : Attribute | ||||
{ | { | ||||
@@ -2,7 +2,7 @@ using System; | |||||
namespace Discord.Commands { | namespace Discord.Commands { | ||||
/// <summary> Prevents the property from being injected into a module. </summary> | |||||
/// <summary> Prevents the marked property from being injected into a module. </summary> | |||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] | ||||
public class DontInjectAttribute : Attribute { | public class DontInjectAttribute : Attribute { | ||||
} | } | ||||
@@ -2,15 +2,19 @@ using System; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> Marks the module as a command group. </summary> | |||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] | ||||
public class GroupAttribute : Attribute | public class GroupAttribute : Attribute | ||||
{ | { | ||||
/// <summary> Gets the prefix set for the module. </summary> | |||||
public string Prefix { get; } | public string Prefix { get; } | ||||
public GroupAttribute() | public GroupAttribute() | ||||
{ | { | ||||
Prefix = null; | Prefix = null; | ||||
} | } | ||||
/// <summary> Creates a <see cref="GroupAttribute"/> with the provided prefix. </summary> | |||||
/// <param name="prefix"> The prefix of the module group.</param> | |||||
public GroupAttribute(string prefix) | public GroupAttribute(string prefix) | ||||
{ | { | ||||
Prefix = prefix; | Prefix = prefix; | ||||
@@ -3,6 +3,7 @@ using System; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
// Override public name of command/module | // Override public name of command/module | ||||
/// <summary> Marks the public name of a command, module, or parameter. </summary> | |||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] | ||||
public class NameAttribute : Attribute | public class NameAttribute : Attribute | ||||
{ | { | ||||
@@ -4,13 +4,17 @@ using System.Reflection; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> Marks the <see cref="Type"/> to be read by the specified <see cref="TypeReader"/>. </summary> | |||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] | ||||
public class OverrideTypeReaderAttribute : Attribute | public class OverrideTypeReaderAttribute : Attribute | ||||
{ | { | ||||
private static readonly TypeInfo _typeReaderTypeInfo = typeof(TypeReader).GetTypeInfo(); | private static readonly TypeInfo _typeReaderTypeInfo = typeof(TypeReader).GetTypeInfo(); | ||||
/// <summary> Gets the specified <see cref="TypeReader"/> of the parameter. </summary> | |||||
public Type TypeReader { get; } | public Type TypeReader { get; } | ||||
/// <summary> Marks the parameter to be read with the specified <see cref="TypeReader"/>. </summary> | |||||
/// <param name="overridenTypeReader">The <see cref="TypeReader"/> to be used with the parameter. </param> | |||||
public OverrideTypeReaderAttribute(Type overridenTypeReader) | public OverrideTypeReaderAttribute(Type overridenTypeReader) | ||||
{ | { | ||||
if (!_typeReaderTypeInfo.IsAssignableFrom(overridenTypeReader.GetTypeInfo())) | if (!_typeReaderTypeInfo.IsAssignableFrom(overridenTypeReader.GetTypeInfo())) | ||||
@@ -3,6 +3,7 @@ using System.Threading.Tasks; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> Requires the parameter to pass the specified precondition before execution can begin. </summary> | |||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)] | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)] | ||||
public abstract class ParameterPreconditionAttribute : Attribute | public abstract class ParameterPreconditionAttribute : Attribute | ||||
{ | { | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord.Commands | namespace Discord.Commands | ||||
@@ -6,11 +6,13 @@ namespace Discord.Commands | |||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] | ||||
public abstract class PreconditionAttribute : Attribute | public abstract class PreconditionAttribute : Attribute | ||||
{ | { | ||||
/// <summary> | |||||
/// Specify a group that this precondition belongs to. Preconditions of the same group require only one | |||||
/// of the preconditions to pass in order to be successful (A || B). Specifying <see cref="Group"/> = <see langword="null"/> | |||||
/// or not at all will require *all* preconditions to pass, just like normal (A && B). | |||||
/// </summary> | |||||
/// <summary> Specify a group that this precondition belongs to. </summary> | |||||
/// <remarks> | |||||
/// Preconditions of the same group require only one | |||||
/// of the preconditions to pass in order to be successful (A || B). | |||||
/// Specifying <see cref="Group"/> = <see langword="null"/> | |||||
/// or not at all will require *all* preconditions to pass, just like normal (A && B). | |||||
/// </remarks> | |||||
public string Group { get; set; } = null; | public string Group { get; set; } = null; | ||||
public abstract Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services); | public abstract Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services); | ||||
@@ -2,6 +2,7 @@ using System; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> Marks the input to not be parsed by the parser. </summary> | |||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] | ||||
public class RemainderAttribute : Attribute | public class RemainderAttribute : Attribute | ||||
{ | { | ||||
@@ -1,5 +1,6 @@ | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> The context of a command which may contain the client, user, guild, channel, and message. </summary> | |||||
public class CommandContext : ICommandContext | public class CommandContext : ICommandContext | ||||
{ | { | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
@@ -2,6 +2,7 @@ using System; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> An exception thrown when a command fails to execute. </summary> | |||||
public class CommandException : Exception | public class CommandException : Exception | ||||
{ | { | ||||
/// <summary> The command that caused the exception. </summary> | /// <summary> The command that caused the exception. </summary> | ||||
@@ -1,16 +1,17 @@ | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> Represents the context of a command. This may include the client, guild, channel, user, and message. </summary> | |||||
public interface ICommandContext | public interface ICommandContext | ||||
{ | { | ||||
/// <summary> The Discord client of which the command is executed with. </summary> | |||||
/// <summary> Gets the <see cref="IDiscordClient"/> that the command is executed with. </summary> | |||||
IDiscordClient Client { get; } | IDiscordClient Client { get; } | ||||
/// <summary> The guild of which the command is executed in. </summary> | |||||
/// <summary> Gets the <see cref="IGuild"/> that the command is executed in. </summary> | |||||
IGuild Guild { get; } | IGuild Guild { get; } | ||||
/// <summary> The channel of which the command is executed in. </summary> | |||||
/// <summary> Gets the <see cref="IMessageChannel"/> that the command is executed in. </summary> | |||||
IMessageChannel Channel { get; } | IMessageChannel Channel { get; } | ||||
/// <summary> The user who executed the command. </summary> | |||||
/// <summary> Gets the <see cref="IUser"/> who executed the command. </summary> | |||||
IUser User { get; } | IUser User { get; } | ||||
/// <summary> The message of which the command is interpreted from. </summary> | |||||
/// <summary> Gets the <see cref="IUserMessage"/> that the command is interpreted from. </summary> | |||||
IUserMessage Message { get; } | IUserMessage Message { get; } | ||||
} | } | ||||
} | } |
@@ -1,15 +1,23 @@ | |||||
using Discord.WebSocket; | |||||
using Discord.WebSocket; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> The WebSocket variant of <see cref="ICommandContext"/>, which may contain the client, user, guild, channel, and message. </summary> | |||||
/// <seealso cref="ICommandContext"/> | |||||
public class SocketCommandContext : ICommandContext | public class SocketCommandContext : ICommandContext | ||||
{ | { | ||||
/// <summary> Gets the <see cref="DiscordSocketClient"/> that the command is executed with. </summary> | |||||
public DiscordSocketClient Client { get; } | public DiscordSocketClient Client { get; } | ||||
/// <summary> Gets the <see cref="SocketGuild"/> that the command is executed in. </summary> | |||||
public SocketGuild Guild { get; } | public SocketGuild Guild { get; } | ||||
/// <summary> Gets the <see cref="ISocketMessageChannel"/> that the command is executed in. </summary> | |||||
public ISocketMessageChannel Channel { get; } | public ISocketMessageChannel Channel { get; } | ||||
/// <summary> Gets the <see cref="SocketUser"/> who executed the command. </summary> | |||||
public SocketUser User { get; } | public SocketUser User { get; } | ||||
/// <summary> Gets the <see cref="SocketUserMessage"/> that the command is interpreted from. </summary> | |||||
public SocketUserMessage Message { get; } | public SocketUserMessage Message { get; } | ||||
/// <summary> Indicates whether the channel that the command is executed in is a private channel. </summary> | |||||
public bool IsPrivate => Channel is IPrivateChannel; | public bool IsPrivate => Channel is IPrivateChannel; | ||||
public SocketCommandContext(DiscordSocketClient client, SocketUserMessage msg) | public SocketCommandContext(DiscordSocketClient client, SocketUserMessage msg) | ||||
@@ -22,10 +30,15 @@ namespace Discord.Commands | |||||
} | } | ||||
//ICommandContext | //ICommandContext | ||||
/// <inheritdoc/> | |||||
IDiscordClient ICommandContext.Client => Client; | IDiscordClient ICommandContext.Client => Client; | ||||
/// <inheritdoc/> | |||||
IGuild ICommandContext.Guild => Guild; | IGuild ICommandContext.Guild => Guild; | ||||
/// <inheritdoc/> | |||||
IMessageChannel ICommandContext.Channel => Channel; | IMessageChannel ICommandContext.Channel => Channel; | ||||
/// <inheritdoc/> | |||||
IUser ICommandContext.User => User; | IUser ICommandContext.User => User; | ||||
/// <inheritdoc/> | |||||
IUserMessage ICommandContext.Message => Message; | IUserMessage ICommandContext.Message => Message; | ||||
} | } | ||||
} | } |