drink icon indicating copy to clipboard operation
drink copied to clipboard

@Cooldown annotation

Open IIHERO4 opened this issue 2 years ago • 2 comments

Extend the drink api to include cooldown annotations for ease of managing cooldowns @Require-like

Per: the time at which the uses gets reset Rate: the number of times that are allowed the command to be executed in a specific amount of time BucketType: Which to apply the cooldown on

This is inspired by discord.py cooldowns

BucketTypes:

  • USER - applys a per-user cooldown
  • COMMAND - applys the cooldown globally

Behavior:

When annotated on an @Command annotated method

The cooldown applys on that command with respect to the bucket type, if a player is on cooldown. it will call a handler callback[^1].

When annotated on the class

Either The cooldown mapping is shared across all sub commands OR Add a mapping as the same as @Cooldown being annotated on all of the sub commands

You can achive this by making a boolean or another annotated @ClassCooldown for example

[^1]: A cooldown handler is should be a function that takes in (Player, DrinkContainer), (You may also make it return a boolean, if false the cooldown will be neglected)

IIHERO4 avatar Jun 25 '22 20:06 IIHERO4

I may implement this if i get time in about 2 weeks but feel free if u have suggestions or anyone to do it

IIHERO4 avatar Jun 25 '22 20:06 IIHERO4

Perhaps a system for binding annotations to whole command methods ("modifiers"?) similar to @Require would be nice to have, so that this and similar implementations can be done by users.

such as:

drink.bindModifier(Cooldown.class).to(CooldownHandler::new);

where Cooldown.class is the @Annotation class, and CooldownHandler implements a Modifier interface or abstract class.

I don't have any time to do this soon, but seems like a good idea.

You could also technically get the behaviour you want using a custom annotation+provider on the player/sender type

jonahseguin avatar Jun 27 '22 21:06 jonahseguin