ShindouMihou/Velen

Better Slash Command Support

Opened this issue · 2 comments

The behavior of Velen right now disregards any duplicate commands whether it'd be a global command or a server-specific slash command which isn't the proper behavior. There may be one or multiple solutions to approach this, but so far that we thought of is the following:

  • A method called Velen#index(DiscordApi) that fetches the list of slash commands globally, stores it.
  • The method then performs a little bit of "indexing" by assigning Velen commands that have an equal name to a command in the list and has no server_only field attached to it before assigning a private slash command id to the command via internal methods: VelenCommandImpl#assign_slash_id. **
  • Velen will then start performing slash command searches via O(N) again through something like commands.stream().filter(command -> id == comand.getAssignedSlashId()).findFirst(). ***

There is also another way to go about storing the slash command id without sacrificing O(1) but does take up a bit of memory, depending on how Java works and this preposition is to:

  • Store the slash command id linked with the command in an HashMap that we call indexes that then routes to the specific Velen command in a HashMap such as: Map<Long, VelenCommand> since Maps stores references as far as I can remember and this shouldn't take up any resources.

This feature is now implemented in the latest commit. To index all slash commands and wait for completion, you can add the line:

velen.index(DiscordApi).join();

Indexing can be cached by saving a file with the time it was cached. The cache can expire by having a default expire time that is customizable via:

velen.setIndexCache(Duration);

This behaviour should also be configurable since some people won't like files being created out of the blue.

*To be added