Skip to content

Commit

Permalink
Update documentation on JDA annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Jan 14, 2023
1 parent 014b868 commit a5f5370
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* The user will be able to execute the command if they have <strong>at least</strong>
* one of the specified roles.
* <p>
* 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 {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* 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 {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit a5f5370

Please sign in to comment.