Skip to content

Commit

Permalink
Starter (#609)
Browse files Browse the repository at this point in the history
* add Starter Command
  • Loading branch information
twonirwana authored Nov 4, 2024
1 parent 758f744 commit 111c44f
Show file tree
Hide file tree
Showing 86 changed files with 8,876 additions and 2,213 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/codeCov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,28 @@ on:

jobs:
build:

runs-on: ubuntu-latest

permissions:
checks: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- uses: gradle/gradle-build-action@v3
with:
gradle-version: current
arguments: test
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Run the tests
run: ./gradlew test
- name: Publish Test Report
uses: mikepenz/action-junit-report@v5
if: always() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
- uses: gradle/gradle-build-action@v3
with:
gradle-version: current
arguments: testCodeCoverageReport
- name: Run the testCodeCoverageReport
run: ./gradlew testCodeCoverageReport
- uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand Down
16 changes: 16 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The bot has list a ready to play list of presets for many RPG systems.
Simple select a system out of the list or keep typing to search and filter in the list.
All these presets are realised with the user available commands and dice expression and can be adapted and extended.
Please let me know if you have a good new preset or an improved version for an existing preset.
The quickstart will show a user also all named commands other user have created at the same server and all named commands the user himself has created in any server.

[cols="1,1"]
|===
Expand Down Expand Up @@ -398,6 +399,11 @@ It musst be a single emoji at the start of the label.
It can be a unicode emoji or a custom discord emoji (provided with emoji selection button, on the right side of the message input).
Commands with invalid emojis will fail and simply produce no button message.

=== Name

Commands can be given names.
Named commands can be recreated with the `quickstart` command or reused with the `starter` command.

== Commands

=== Custom Dice
Expand Down Expand Up @@ -651,6 +657,16 @@ For example: `/channel_config alias multi_save aliases: att:2d20;dmg:2d6+4= scop
* `delete_all` removes all aliases
* `list` provides a list of all alias

=== Starter

Starter creates a wrapper command, that allows it to switch between multiple commands or recreate commands with a click on the button.
The user can add 1 to 10 named commands (created by him self in any server, by another user in the same server or one of the commands defined in quickstart).
In the resulting message, the user musst then first select one of the named commands, use it to create a roll and then message will reset to the selection named commands.

If the option `open_in_new_message: true` is set or the command is pinned, then it will not transform itself in the named command but create a new command message, as if it was created with the slash command.

The option `message` allows it to set a custom message.

=== Fetch

The command moves the last existing button message to the bottom of the channel.
Expand Down
14 changes: 9 additions & 5 deletions bot/src/main/java/de/janno/discord/bot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import de.janno.discord.bot.command.help.RpgSystemCommandPreset;
import de.janno.discord.bot.command.help.WelcomeCommand;
import de.janno.discord.bot.command.reroll.RerollAnswerHandler;
import de.janno.discord.bot.command.starter.StarterCommand;
import de.janno.discord.bot.command.sumCustomSet.SumCustomSetCommand;
import de.janno.discord.bot.dice.CachingDiceEvaluator;
import de.janno.discord.bot.persistance.PersistenceManager;
Expand Down Expand Up @@ -59,6 +60,8 @@ public static void main(final String[] args) throws Exception {
WelcomeCommand welcomeCommand = new WelcomeCommand(persistenceManager, rpgSystemCommandPreset);
HiddenDirectRollCommand hiddenDirectRollCommand = new HiddenDirectRollCommand(persistenceManager, cachingDiceEvaluator);
RerollAnswerHandler rerollAnswerHandler = new RerollAnswerHandler(persistenceManager, cachingDiceEvaluator);
StarterCommand starterCommand = new StarterCommand(persistenceManager, customParameterCommand, customDiceCommand, sumCustomSetCommand);
QuickstartCommand quickstartCommand = new QuickstartCommand(persistenceManager, customParameterCommand, customDiceCommand, sumCustomSetCommand, channelConfigCommand);
DiscordConnectorImpl.createAndStart(
List.of(customDiceCommand,
new DirectRollCommand(persistenceManager, cachingDiceEvaluator),
Expand All @@ -68,21 +71,22 @@ public static void main(final String[] args) throws Exception {
channelConfigCommand,
sumCustomSetCommand,
customParameterCommand,
welcomeCommand,
new ClearCommand(persistenceManager),
new QuickstartCommand(rpgSystemCommandPreset),
quickstartCommand,
new HelpCommand(),
new FetchCommand(persistenceManager, customParameterCommand, customDiceCommand, sumCustomSetCommand)
new FetchCommand(persistenceManager, customParameterCommand, customDiceCommand, sumCustomSetCommand),
starterCommand
),
List.of(customDiceCommand,
sumCustomSetCommand,
customParameterCommand,
welcomeCommand,
hiddenDirectRollCommand,
rerollAnswerHandler,
new LegacyIdHandler()
new LegacyIdHandler(),
starterCommand
),
welcomeCommand.getWelcomeMessage(),
starterCommand.getWelcomeMessage(),
allGuildIdsInPersistence);
}

Expand Down
27 changes: 10 additions & 17 deletions bot/src/main/java/de/janno/discord/bot/command/AbstractCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected ConfigAndState<C, S> getMessageDataAndUpdateWithButtonValue(@NonNull M
}

@Override
protected @NonNull Optional<EmbedOrMessageDefinition> createNewButtonMessage(@NonNull UUID configId, @NonNull C config, @Nullable State<S> state, @Nullable Long guildId, long channelId) {
return AbstractCommand.this.createNewButtonMessageWithState(configId, config, state, guildId, channelId);
protected @NonNull Optional<EmbedOrMessageDefinition> createNewButtonMessage(@NonNull UUID configId, @NonNull C config, @Nullable State<S> state, @Nullable Long guildId, long channelId, long userId) {
return AbstractCommand.this.createNewButtonMessageWithState(configId, config, state, guildId, channelId, userId);
}

@Override
Expand All @@ -56,11 +56,6 @@ protected void updateCurrentMessageStateData(UUID configUUID, @Nullable Long gui
AbstractCommand.this.updateCurrentMessageStateData(configUUID, guildId, channelId, messageId, config, state);
}

@Override
protected Mono<Void> furtherAction(ButtonEventAdaptor event, C config, State<S> state, Timer timer) {
return AbstractCommand.this.furtherAction(event, config, state, timer);
}

@Override
protected Optional<List<ComponentRowDefinition>> getCurrentMessageComponentChange(UUID configUUID, C config, State<S> state, long channelId, long userId, boolean keepExistingButtonMessage) {
return AbstractCommand.this.getCurrentMessageComponentChange(configUUID, config, state, channelId, userId, keepExistingButtonMessage);
Expand Down Expand Up @@ -93,8 +88,8 @@ protected boolean shouldKeepExistingButtonMessage(@NonNull ButtonEventAdaptor ev
}

@Override
public Optional<MessageConfigDTO> createMessageConfig(@NonNull UUID configUUID, @Nullable Long guildId, long channelId, @NonNull C config) {
return AbstractCommand.this.createMessageConfig(configUUID, guildId, channelId, config);
public Optional<MessageConfigDTO> createMessageConfig(@NonNull UUID configUUID, @Nullable Long guildId, long channelId, long userId, @NonNull C config) {
return AbstractCommand.this.createMessageConfig(configUUID, guildId, channelId, userId, config);
}

@Override
Expand Down Expand Up @@ -148,8 +143,8 @@ protected Collection<CommandDefinitionOption> additionalCommandOptions() {
}

@Override
public @NonNull List<AutoCompleteAnswer> getAutoCompleteAnswer(@NonNull AutoCompleteRequest autoCompleteRequest, @NonNull Locale userLocale, long channelId, long userId) {
return AbstractCommand.this.getAutoCompleteAnswer(autoCompleteRequest, userLocale, channelId, userId);
public @NonNull List<AutoCompleteAnswer> getAutoCompleteAnswer(@NonNull AutoCompleteRequest autoCompleteRequest, @NonNull Locale userLocale, long channelId, Long guildId, long userId) {
return AbstractCommand.this.getAutoCompleteAnswer(autoCompleteRequest, userLocale, channelId, guildId, userId);
}

@Override
Expand Down Expand Up @@ -190,7 +185,7 @@ protected Collection<CommandDefinitionOption> additionalCommandOptions() {
}

@Override
public @NonNull List<AutoCompleteAnswer> getAutoCompleteAnswer(@NonNull AutoCompleteRequest autoCompleteRequest, @NonNull Locale userLocale, long channelId, long userId) {
public @NonNull List<AutoCompleteAnswer> getAutoCompleteAnswer(@NonNull AutoCompleteRequest autoCompleteRequest, @NonNull Locale userLocale, long channelId, Long guildId, long userId) {
return BaseCommandOptions.autoCompleteColorOption(autoCompleteRequest, userLocale);
}

Expand Down Expand Up @@ -219,6 +214,7 @@ protected abstract ConfigAndState<C, S> getMessageDataAndUpdateWithButtonValue(@
public abstract Optional<MessageConfigDTO> createMessageConfig(@NonNull UUID configUUID,
@Nullable Long guildId,
long channelId,
long userId,
@NonNull C config);

/**
Expand All @@ -239,10 +235,6 @@ public Mono<Void> handleComponentInteractEvent(@NonNull ButtonEventAdaptor event
return componentCommand.handleComponentInteractEvent(event);
}

protected Mono<Void> furtherAction(ButtonEventAdaptor event, C config, State<S> state, Timer timer) {
return Mono.empty();
}

@Override
public @NonNull Mono<Void> handleSlashCommandEvent(@NonNull SlashEventAdaptor event, @NonNull Supplier<UUID> uuidSupplier, @NonNull Locale userLocale) {
return slashCommand.handleSlashCommandEvent(event, uuidSupplier, userLocale);
Expand Down Expand Up @@ -273,7 +265,8 @@ protected Mono<Void> furtherAction(ButtonEventAdaptor event, C config, State<S>
@NonNull C config,
@Nullable State<S> state,
@Nullable Long guildId,
long channelId);
long channelId,
long userId);

protected abstract @NonNull Optional<RollAnswer> getAnswer(C config, State<S> state, long channelId, long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public final class BaseCommandOptions {
.descriptionLocales(I18n.allNoneEnglishMessagesDescriptions("base.option.target_channel.description"))
.type(CommandDefinitionOption.Type.CHANNEL)
.build();
public static final String NAME_OPTION_NAME = "name";
public static final CommandDefinitionOption NAME_COMMAND_OPTION = CommandDefinitionOption.builder()
.name(NAME_OPTION_NAME)
.nameLocales(I18n.allNoneEnglishMessagesNames("base.option.name.name"))
.description(I18n.getMessage("base.option.name.description", Locale.ENGLISH))
.descriptionLocales(I18n.allNoneEnglishMessagesDescriptions("base.option.name.description"))
.type(CommandDefinitionOption.Type.STRING)
.build();

public static AnswerInteractionType getAnswerInteractionFromStartCommandOption(@NonNull CommandInteractionOption options) {
return options.getStringSubOptionWithName(ANSWER_INTERACTION_OPTION_NAME)
Expand Down Expand Up @@ -144,4 +152,8 @@ public static Optional<String> getDiceColorOptionFromStartCommandOption(@NonNull
public static Optional<Locale> getLocaleOptionFromStartCommandOption(@NonNull CommandInteractionOption options) {
return options.getStringSubOptionWithName(LOCALE_OPTION_NAME).map(Locale::of);
}

public static Optional<String> getNameFromStartCommandOption(@NonNull CommandInteractionOption options) {
return options.getStringSubOptionWithName(NAME_OPTION_NAME);
}
}
Loading

0 comments on commit 111c44f

Please sign in to comment.