diff --git a/jda/src/main/java/revxrsal/commands/jda/annotation/GuildOnly.java b/jda/src/main/java/revxrsal/commands/jda/annotation/GuildOnly.java index c97f006f..02ad5b6b 100644 --- a/jda/src/main/java/revxrsal/commands/jda/annotation/GuildOnly.java +++ b/jda/src/main/java/revxrsal/commands/jda/annotation/GuildOnly.java @@ -8,8 +8,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Marks a command as executable in guilds only. + */ @DistributeOnMethods @NotSender.ImpliesNotSender -@Target({ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER}) +@Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface GuildOnly {} diff --git a/jda/src/main/java/revxrsal/commands/jda/annotation/GuildPermission.java b/jda/src/main/java/revxrsal/commands/jda/annotation/GuildPermission.java index ceb7bc4b..e9fbc90f 100644 --- a/jda/src/main/java/revxrsal/commands/jda/annotation/GuildPermission.java +++ b/jda/src/main/java/revxrsal/commands/jda/annotation/GuildPermission.java @@ -9,12 +9,20 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Represents a guild permission, where a user is required to have + * all the specified {@link Permission}s + */ @DistributeOnMethods @Target({ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @NotSender.ImpliesNotSender public @interface GuildPermission { - Permission value(); + /** + * The permissions the user is required to have. Note that + * they must have ALL the permissions to be able to execute the command. + */ + Permission[] value(); } diff --git a/jda/src/main/java/revxrsal/commands/jda/annotation/RolePermission.java b/jda/src/main/java/revxrsal/commands/jda/annotation/RolePermission.java index 538662cb..99acd965 100644 --- a/jda/src/main/java/revxrsal/commands/jda/annotation/RolePermission.java +++ b/jda/src/main/java/revxrsal/commands/jda/annotation/RolePermission.java @@ -8,14 +8,33 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Requires one of certain roles to be present on the user executing + * the command. + *

+ * The user will be able to execute the command if they have at least + * one of the specified roles. + *

+ * Roles may be given in IDs ({@link #ids()}), or in names ({@link #names()}).. + */ @DistributeOnMethods @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER}) @NotSender.ImpliesNotSender public @interface RolePermission { + /** + * The names of roles the user must have at least one from. + * + * @return The role names + */ String[] names() default {}; + /** + * The IDs of roles the user must have at least one from. + * + * @return The role IDs + */ long[] ids() default {}; } diff --git a/jda/src/main/java/revxrsal/commands/jda/annotation/UserPermission.java b/jda/src/main/java/revxrsal/commands/jda/annotation/UserPermission.java index 6d1fbb2a..fcca5e1c 100644 --- a/jda/src/main/java/revxrsal/commands/jda/annotation/UserPermission.java +++ b/jda/src/main/java/revxrsal/commands/jda/annotation/UserPermission.java @@ -8,14 +8,30 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Marks a command as being executable only by a certain user or + * list of users. + *

+ * Users may be specified in names ({@link #names()}), or IDs ({@link #ids()}) + */ @DistributeOnMethods @NotSender.ImpliesNotSender @Target({ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) public @interface UserPermission { + /** + * The names of users who are allowed to execute the command + * + * @return The names + */ String[] names() default {}; + /** + * The IDs of users who are allowed to execute the command + * + * @return The IDs + */ long[] ids() default {}; } diff --git a/jda/src/main/java/revxrsal/commands/jda/core/JDAHandler.java b/jda/src/main/java/revxrsal/commands/jda/core/JDAHandler.java index a11fc132..81422428 100644 --- a/jda/src/main/java/revxrsal/commands/jda/core/JDAHandler.java +++ b/jda/src/main/java/revxrsal/commands/jda/core/JDAHandler.java @@ -46,6 +46,7 @@ public JDAHandler(@NotNull JDA jda, @NotNull String prefix) { registerResponseHandler(MessageEmbed.class, (response, actor, command) -> actor.as(JDAActor.class).getChannel().sendMessageEmbeds(response).queue()); setExceptionHandler(JDAExceptionAdapter.INSTANCE); registerPermissionReader(JDAPermission::new); + registerCondition((actor, command, arguments) -> actor.as(JDAActor.class).checkInGuild(command)); jda.addEventListener(new JDACommandListener(prefix, this)); }