mirror of
https://github.com/aikar/commands.git
synced 2026-06-13 11:30:37 +00:00
fbfb8decd0
This pull request is an initial attempt at implementing permission for commands for the JDA module.
It includes one added file, **JDACommandPermissionResolver** which implements CommandPermissionResolver.
I created a map to store the Discord permission offsets stored mapped by their kebab-cased name (i.e. "ADMINISTRATOR" becomes "administrator", "MANAGE_SERVER" becomes "manage-server".
The implementation of `hasPermission(JDACommandEvent, String)` is fairly simple:
- Get the issuer's Member object
- Check if it's null; if so, return false.
- Get the permission offset from the aforementioned map
- Check if it's null; if so, return false.
- Return whether or not the member has the permission.
---------------------------------------
This PR allows new commands to use the `@CommandPermission` annotation like so:
```java
@CommandAlias("test|t")
public class Command extends BaseCommand {
@Subcommand("admin|a")
@CommandPermission("manage-server")
public void adminCommand(MessageReceivedEvent event) {
//...
}
}
```