Add documentation for Preconditions, Aliases, Command Structure
Resolves #223
This commit is contained in:
15
docs/guides/samples/groups.cs
Normal file
15
docs/guides/samples/groups.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
[Module("admin")]
|
||||
public class AdminModule
|
||||
{
|
||||
[Group("mod")]
|
||||
public class ModerationGroup
|
||||
{
|
||||
// ~admin mod ban foxbot#0282
|
||||
[Command("ban")]
|
||||
public async Task Ban(IMessage msg, IGuildUser user) { }
|
||||
}
|
||||
|
||||
// ~admin clean 100
|
||||
[Command("clean")]
|
||||
public async Task Clean(IMessage msg, int count = 100) { }
|
||||
}
|
||||
@@ -31,7 +31,9 @@ public class Sample
|
||||
// ~sample userinfo Khionu#8708 --> Khionu#8708
|
||||
// ~sample userinfo Khionu --> Khionu#8708
|
||||
// ~sample userinfo 96642168176807936 --> Khionu#8708
|
||||
// ~sample whois 96642168176807936 --> Khionu#8708
|
||||
[Command("userinfo"), Description("Returns info about the current user, or the user parameter, if one passed.")]
|
||||
[Alias("user", "whois")]
|
||||
public async Task UserInfo(IMessage msg,
|
||||
[Description("The (optional) user to get info for")] IUser user = null)
|
||||
{
|
||||
|
||||
11
docs/guides/samples/require_context.cs
Normal file
11
docs/guides/samples/require_context.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
[Module]
|
||||
public class InfoModule
|
||||
{
|
||||
// Constrain this command to Guilds
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Whois(IMessage msg, IGuildUser user) { }
|
||||
|
||||
// Constrain this command to either Guilds or DMs
|
||||
[RequireContext(ContextType.Guild | ContextType.DM)]
|
||||
public async Task Info(IMessage msg) { }
|
||||
}
|
||||
16
docs/guides/samples/require_owner.cs
Normal file
16
docs/guides/samples/require_owner.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
// Defining the Precondition
|
||||
|
||||
// Specify that this precondition can target a Class (Module/Group) or Method (Command)
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
// Inherit from PreconditionAttribute
|
||||
public class RequireOwnerAttribute : PreconditionAttribute
|
||||
{
|
||||
public readonly ulong OwnerId = 66078337084162048;
|
||||
|
||||
// Override the CheckPermissions method
|
||||
public override Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance)
|
||||
{
|
||||
// If the author of the message is '66078337084162048', return success; otherwise fail.
|
||||
return Task.FromResult(context.Author.Id == OwnerId ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("You must be the owner of the bot."));
|
||||
}
|
||||
}
|
||||
7
docs/guides/samples/require_permission.cs
Normal file
7
docs/guides/samples/require_permission.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
[Module]
|
||||
public class AdminModule
|
||||
{
|
||||
[Command("ban")]
|
||||
[RequirePermission(GuildPermission.BanMembers)]
|
||||
public async Task Ban(IMessage msg) { }
|
||||
}
|
||||
Reference in New Issue
Block a user