35 Commits

Author SHA1 Message Date
simpleauthority aa6fa281cc Add unregister method for JDA (#174)
This PR is to allow users to unregister commands from the `JDACommandManager`

Currently slightly flawed, needs research. When re-registering it spits out a load of messages like so:
```
SEVERE: [ACF] ACF Error: settings registered subcommand boss role for root command settings - but it is already defined in settings
Sep 20, 2018 3:58:31 AM com.algorithmjunkie.freelance.gachapon.acf.JDACommandManager log
SEVERE: [ACF] 2 subcommands of the same prefix may not be spread over 2 different classes. Ignoring this.
```

Not sure if this is just for me, or if it's for all.
2018-10-23 11:00:11 -04:00
Mark Vainomaa 7742dc3238 Deny permissions if command is issued by a webhook (#156) 2018-08-03 13:57:20 -04:00
simpleauthority 7a2e547766 Make Users optional arguments (#139)
This PR allows `User`s to be optional command arguments similar to how the annotation operates on Bukkit's `Player`.
2018-07-24 21:42:54 -04:00
Osip Fatkullin 3c979a9ef2 Drop trivial Guava usages (#142)
#120, #127
2018-07-19 19:43:17 -04:00
Gabik21MC 7c75cdd48c Improvements (#143)
Improve help output for commands split over multiple base commands
Fix help last page detection
Fix missing argument on Player Context Resolve
Expose registered root commands
2018-06-18 15:15:03 -04:00
simpleauthority 3319ab78a2 [JDA] Fix User context resolution (#138)
When @ mentioning someone in Discord, if you manually click the user's name then the ID will be in the chat field as "<@!...>". However, one can _also_ mention a user like so "<@...>".

This PR handles both cases.
2018-06-03 15:47:21 -04:00
simpleauthority cbe1507b1c Repair context types, add Role context, add CrossGuild annotation (#137)
In a previous PR, some contexts were not changed from **IssuerOnly** to **IssuerAware**. This has been patched.

I've added a context to resolve a Role. It makes use of the next item I added.

The CrossGuild annotation is used to signify whether or not the context is to be interpreted from a guild perspective or a bot perspective (i.e. all guilds). This annotation could probably be better named.
2018-06-03 12:58:24 -04:00
simpleauthority fbfb8decd0 Implement CommandPermissionResolver (#135)
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) {
    //...
  }
}
```
2018-06-03 00:28:19 -04:00
simpleauthority 7478d030d0 Reimplement JDAMessageFormatter for Discord (#136)
Because Discord does not support coloring messages outside of embeddable fields, it is safe to use a simple message formatter than just returns the message itself.

As I was testing my previous PR, I noticed messages coming through with coloring symbols (e.g. `<c1></c1>`), and each only went up to `c3` maximum. Finally, I figured out these were colors that needed to be handled in each case.

To remove colored messages from Discord, the message formatter is passed three empty strings for each of `c1`, `c2`, and `c3` respectively.

Finally, the default formatter is set inside of `JDACommandManager` but can always be overridden by the user.
2018-06-02 10:36:57 -04:00
Aikar d57dbcefab Update Maven Plugins, hopefully will fix #129 2018-05-27 12:43:32 -04:00
Mariell 11dcee8b39 Use MethodHandles for invocation (#112)
* Use method handles for invocation

* Fix parsing, add more safety and add for named MessageChannels, and format

* Add methodhandle support to BaseCommand
2018-03-24 10:59:43 -04:00
Aikar 8335d580f6 Improvements to help formatter 2018-03-21 22:02:48 -04:00
Aikar 633c6278b5 Ignore command issuer for context resolution in completions 2018-03-18 01:11:25 -04:00
Aikar d8017789d6 Refactor all annotation lookups in prep for processors 2018-03-17 12:31:05 -04:00
Aikar 2d0995a3ac Refactor how parameter annotations are parsed to prep for processors
this also will improve performance, as we will only do flag parsing and replacements
once on register instead of every execution for some things.
2018-03-15 23:22:18 -04:00
Aikar 8be2d4f9c2 fix JDA default command 2018-03-08 22:12:45 -05:00
games647 edf7ecc020 Add support for per issuer locale in Sponge and BungeeCord (#104)
* Add support for per issuer locale in Sponge and BungeeCord

* Added Optional<UUID> getUniqueId to CommandIssuer
* Added update task and delayed join listener in BungeeCord
* Added settings change listener in Sponge
* Moved setLocale method up to the CommandManager to remove the
amount of duplicated code

* Remove Optional usage

* Remove player terminology in core
2018-02-28 17:53:27 -05:00
Aikar 9acd2df4a2 Clean up JDA to use an options object builder instead of ctor builder
safer for future additions, so we don't have to change the signature of JDA ctor
2018-02-14 23:36:39 -05:00
Jeremy Wood d9b532de11 Properly handle multi-character command prefixes. (#95) 2018-01-26 01:07:02 -05:00
Jeremy Wood afc7f801b2 Improvements for JDA command prefixes. (#94) 2018-01-25 18:28:02 -05:00
Jeremy Wood 03d3d8b0e9 Added common message channel conditions. (#92) 2018-01-25 17:53:16 -05:00
Jeremy Wood 23e8858c67 Improvements for JDA implementation. (#91)
* Added owneronly condition for JDA.

* Fixed command registration for JDA.

* Removed extraneous event handling.

* Initialize bot owner on ReadyEvent.
2018-01-24 16:57:17 -05:00
Jeremy Wood 9aaf990ddb Added owneronly condition for JDA. (#88) 2018-01-24 15:20:50 -05:00
Aikar 42a6b112de constructor for jda can stay public for child classes 2018-01-23 00:48:53 -05:00
Aikar c3089d61c7 misc changes for jda 2018-01-23 00:47:19 -05:00
Aikar 7f590a76b2 Add permission resolver, fix many bugs, move to a builder style constructor 2018-01-23 00:42:21 -05:00
Aikar f1197dcdfc oops missed replacement 2018-01-23 00:31:28 -05:00
Aikar afd116982d use an interface for CommandConfig
so you can bind the interface to your own config state objects
2018-01-23 00:30:45 -05:00
Aikar 65ca960882 Use getter/setters for config so people can override it to bridge configs 2018-01-22 23:49:43 -05:00
Aikar bdfed57936 Setup Command Config object and allow providing alternate configs 2018-01-22 23:31:34 -05:00
Aikar d06fa55211 provide a better User context for JDA 2018-01-22 22:27:13 -05:00
Aikar 85d266b667 Smurf name the JDACommandEvent 2018-01-22 22:21:53 -05:00
Aikar ba6cf9a87c add getEvent for more clear getter 2018-01-22 22:20:25 -05:00
Aikar 46ee14e4a3 provide some contexts for JDA 2018-01-22 22:18:17 -05:00
Aikar 8667970216 Add JDA Implementation - untested - not ready yet!
Hoping @dumptruckman can finish this up
2018-01-22 22:03:22 -05:00