JDA-Chewtils icon indicating copy to clipboard operation
JDA-Chewtils copied to clipboard

Add guild settings getter in command events

Open Matyrobbrt opened this issue 3 years ago • 3 comments

Pull Request

Pull Request Checklist

Please follow the following steps before opening this PR.
PRs that do not complete the checklist will be subject to denial for missing information.

Pull Request Information

Check and fill in the blanks for all that apply:

  • [ ] My PR fixes a bug, error, or other issue with the library's codebase.
  • [x] My PR is for the command module of the JDA-Utilities library.
  • [ ] My PR creates a new module for the JDA-Utilities library: ______.

Description

Describe your PR here. This PR adds 2 utility methods in the command and interaction events for getting the settings of the guild, using the class of the settings. Those methods will do the following checks:

  • the command was run in a guild
  • the settings manager is not null
  • the settings manager does not return null settings
  • the settings returned by the manager are instances of the specified settings class

Matyrobbrt avatar Apr 20 '22 11:04 Matyrobbrt

How does this differ from event.getClient().getSettingsFor(event.getGuild())?

Chew avatar Apr 20 '22 22:04 Chew

That method uses a generic argument which can't be inferred as it has no parameters using it. As such, it needs the type declared like .<Config>getSettingsFor(), which is annoying both to type and to look at. Plus, providing the wrong generic argument throws a class cast exception.

Matyrobbrt avatar Apr 20 '22 23:04 Matyrobbrt

Can this be added to the Interactions class? Unless I'm missing something.

Chew avatar Jun 10 '24 23:06 Chew