-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cadf525
commit d8439e6
Showing
13 changed files
with
527 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# cloud-processors-confirmation | ||
|
||
Postprocessor that adds the ability to require an extra confirmation before executing commands. | ||
|
||
## Installation | ||
|
||
Snapshots are available on the Sonatype Snapshots Repository: | ||
|
||
```xml | ||
<repository> | ||
<id>sonatype-snapshots</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url> | ||
</repository> | ||
|
||
<dependency> | ||
<groupId>org.incendo</groupId> | ||
<artifactId>cloud-processors-confirmation</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
``` | ||
|
||
## Usage | ||
|
||
You have to create an instance of `ConfirmationManager`, which accepts a `ConfirmationConfiguration`: | ||
|
||
```java | ||
ConfirmationManager<YourSenderType> confirmationManager | ||
= ConfirmationManager.of(configuration); | ||
``` | ||
|
||
The configuration is created using a builder: | ||
|
||
```java | ||
ConfirmationConfiguration.<YourSenderType>builder() | ||
.cache(cache) | ||
.noPendingCommandNotifier(...) | ||
.confirmationRequiredNotifier(...) | ||
.build(); | ||
``` | ||
|
||
The notifiers are consumers that are invoked when different events take place. See the JavaDoc for more information. | ||
|
||
The cache is an instance of `CloudCache`, the default implementations are: | ||
|
||
- `GuavaCache`: Cache that wraps a Guava cache. | ||
- `CaffeineCache`: Cache that wraps a Caffeine cache. | ||
- `SimpleCache`: Cache that wraps a weak hashmap. This is not recommended to use as it may grow indefinitely and offers very | ||
little control. | ||
|
||
You then need to register the postprocessor to the command manager: | ||
|
||
```java | ||
commandManager.registerCommandPostProcessor( | ||
confirmationManager.createPostProcessor() | ||
); | ||
``` | ||
|
||
Commands that have the confirmation meta key will now require confirmation before they can be executed. | ||
You may pass a predicate to the configuration that accepts a command context and determines whether the confirmation | ||
should be bypassed. This allows you to use permissions, flags and other methods to conditionally disable the confirmation | ||
requirement. | ||
|
||
You'll likely want to create a confirmation command, which can be done using the command execution handler returned by | ||
the confirmation manager: | ||
|
||
```java | ||
commandManager.command( | ||
commandManager.commandBuilder("confirm") | ||
.handler(confirmationManager.createExecutionHandler()) | ||
); | ||
``` | ||
|
||
### Builders | ||
|
||
To indicate that a command requires confirmation you need to apply the `ConfirmationManager.META_CONFIRMATION_REQUIRED` | ||
meta to the command. You may either to do this by manually applying it: | ||
|
||
```java | ||
commandBuilder.meta(ConfirmationManager.META_CONFIRMATION_REQUIRED, true) | ||
``` | ||
|
||
or by decorating the builder using the confirmation manager: | ||
|
||
```java | ||
commandBuilder.apply(confirmationManager) | ||
``` | ||
|
||
### Annotations | ||
|
||
The module ships with a builder modifier that enables the use of the `@Confirmation` annotation. To install this, you | ||
simply do: | ||
|
||
```java | ||
ConfirmationBuilderModifier.install(annotationParser); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# cloud-processors-cooldown | ||
|
||
Postprocessor that adds command cooldowns. | ||
|
||
## Installation | ||
|
||
Snapshots are available on the Sonatype Snapshots Repository: | ||
|
||
```xml | ||
<repository> | ||
<id>sonatype-snapshots</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url> | ||
</repository> | ||
|
||
<dependency> | ||
<groupId>org.incendo</groupId> | ||
<artifactId>cloud-processors-cooldown</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
``` | ||
|
||
## Usage | ||
|
||
The cooldown system is managed by a `CooldownManager`, so the first step is to create an instance of that: | ||
|
||
```java | ||
CooldownManager<YourSenderType> cooldownManager = CooldownManager.of( | ||
configuration | ||
); | ||
``` | ||
|
||
The configuration is an instance of `CooldownConfiguration`. Refer to the JavaDocs for information about specific options, | ||
but an example would be: | ||
|
||
```java | ||
CooldownConfiguration.<YourSenderType>builder() | ||
.repository(CooldownRepository.forMap(new HashMap<>())) | ||
.addActiveCooldownListener(...) | ||
.addCooldownCreationListener(...) | ||
.cooldownNotifier(notifier) | ||
.build(); | ||
``` | ||
|
||
The listeners are invoked when different events take place. The active cooldown listener in particular may be used to | ||
inform the command sender that their command execution got blocked due to an active cooldown. | ||
|
||
The repository stores active cooldowns for a command sender in the form of cooldown profiles. | ||
The cooldowns are grouped by their `CooldownGroup`, by default a unique group will be created per command. | ||
You may create a named group by using `CooldownGroup.named(name)`. Commands that use the same cooldown group | ||
will have their cooldowns shared by the command sender. | ||
|
||
You may create a repository from a map, `CloudCache` or even implement your own. If you want to persist the cooldowns | ||
across multiple temporary sessions then you may use a mapping repository to store the cooldown profiles for a persistent key, | ||
rather than the potentially temporary command sender objects: | ||
|
||
```java | ||
CooldownRepository repository = CooldownRepository.mapping( | ||
sender -> sender.uuid(), | ||
CooldownRepository.forMap(new HashMap<UUID, CooldownProfile>()) | ||
); | ||
``` | ||
|
||
You may also customize how the cooldown profiles are created by passing a `CooldownProfileFactory` to the `CooldownConfiguration`. | ||
|
||
If you want to have the cooldowns automatically removed from the repository to prevent unused profiles from taking up memory you | ||
may register a `ScheduledCleanupCreationListener`: | ||
|
||
```java | ||
CooldownRepository repository = CooldownRepository.forMap(new HashMap<>()); | ||
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); | ||
CooldownConfiguration configuration = CooldownConfiguration.<YourSenderType>builder() | ||
// ... | ||
.repository(repository) | ||
.addCreationListener(new ScheduledCleanupCreationListener(executorService, repository)) | ||
.build(); | ||
``` | ||
|
||
You then need to register the postprocessor: | ||
|
||
```java | ||
commandManager.registerCommandPostProcessor( | ||
cooldownManager.createPostprocessor() | ||
); | ||
``` | ||
|
||
### Builders | ||
|
||
The cooldowns are configured using a `Cooldown` instance: | ||
|
||
```java | ||
Cooldown cooldown = Cooldown.of( | ||
DurationFunction.constant(Duration.ofMinutes(5L)) | ||
); | ||
Cooldown cooldown = Cooldown.of( | ||
DurationFunction.constant(Duration.ofMinutes(5L)), | ||
CooldownGroup.named("group-name") | ||
); | ||
``` | ||
|
||
which can then be applied to the command by either manually setting the meta value: | ||
|
||
```java | ||
commandBuilder.meta(CooldownManager.META_COOLDOWN_DURATION, cooldown); | ||
``` | ||
|
||
or by applying the cooldown to the builder: | ||
|
||
```java | ||
commandBuilder.apply(cooldown); | ||
``` | ||
|
||
### Annotations | ||
|
||
Annotated commands may use the `@Cooldown` annotation: | ||
|
||
```java | ||
@Cooldown(duration = 5, timeUnit = ChronoUnit.MINUTES, group = "some-group") | ||
public void yourCommand() { | ||
// ... | ||
} | ||
``` | ||
|
||
You need to install the builder modifier for this to work: | ||
|
||
```java | ||
CooldownBuilderModifier.install(annotationParser); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# cloud-processors | ||
|
||
## Modules | ||
|
||
<div class="grid cards" markdown> | ||
|
||
- [cloud-processors-confirmation](confirmation.md) | ||
- [cloud-processors-cooldown](cooldown.md) | ||
- [cloud-processors-requirements](requirements.md) | ||
|
||
</div> |
Oops, something went wrong.