Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User install App #571

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
https://www.gnu.org/licenses/agpl-3.0[image:https://img.shields.io/badge/License-AGPL_v3-blue.svg[License: AGPL v3]] https://codecov.io/gh/twonirwana/DiscordDiceBot[image:https://codecov.io/gh/twonirwana/DiscordDiceBot/branch/main/graph/badge.svg?token=OLH7L312D7[codecov]]
image:https://img.shields.io/github/actions/workflow/status/twonirwana/DiscordDiceBot/codeCov.yml?branch=main[GitHub Workflow Status]
image:https://img.shields.io/discord/898657305883725834[link="https://discord.gg/e43BsqKpFr"]
image:https://dcbadge.limes.pink/api/shield/812381127943782502?bot=true&style=flat&theme=clean-inverted[link="https://discord.com/api/oauth2/authorize?client_id=812381127943782502&permissions=274878023680&scope=applications.commands%20bot"]
image:https://dcbadge.limes.pink/api/shield/812381127943782502?bot=true&style=flat&theme=clean-inverted[link="https://discord.com/oauth2/authorize?client_id=812381127943782502"]

This bot is for rolling dice in discord.
The bot needs to be configured with a slash command in a channel and then provides a message with buttons.
Upon clicking on a button the bot will roll the stored dice expression for the button, post the result and move the message with the buttons to the bottom of the channel.
If the message is pined, then it will only be copied and not moved.
This allows user to roll dice without typing commands and thereby improves usability, especially for touchscreen users.

If the message is pined, then it will only be copied and not moved.
The bot supports Discord thread (the button message must be added after the thread creation), forum, Text in Voice, direct messages, and it is possible to send the answer in a different channel.
It can provide images of the dice roll results and it is possible to configure channel or user specific aliases.

image:image/example.webp[image]
The bot can be user installed, this allows a user to use the slash commands (but no buttons) in server where the bot is not installed

*Add to Discord channel by following this link*: https://discord.com/api/oauth2/authorize?client_id=812381127943782502&permissions=274878023680&scope=applications.commands%20bot[*Bot invite link*]
image:image/example.webp[image]
*Add to Discord channel by following this link*: https://discord.com/oauth2/authorize?client_id=812381127943782502[*Bot invite link*]

*Discord Server for trying the bot, questions and feature suggestions*: https://discord.gg/e43BsqKpFr[Button Dice Roller Discord Server]

Expand Down
4 changes: 0 additions & 4 deletions bot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ plugins {
id("jacoco")
}

repositories {
mavenCentral()
}

dependencies {
implementation(project(":discord-connector"))
implementation("io.github.twonirwana:dice-evaluator:v0.9.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import de.janno.discord.bot.persistance.Mapper;
import de.janno.discord.bot.persistance.PersistenceManager;
import de.janno.discord.connector.api.*;
import de.janno.discord.connector.api.slash.CommandDefinition;
import de.janno.discord.connector.api.slash.CommandDefinitionOption;
import de.janno.discord.connector.api.slash.CommandDefinitionOptionChoice;
import de.janno.discord.connector.api.slash.CommandInteractionOption;
import de.janno.discord.connector.api.slash.*;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -200,6 +197,7 @@ public static List<Alias> parseStringToMultiAliasList(String aliasesString) {
.nameLocales(I18n.allNoneEnglishMessagesNames("channel_config.name"))
.description(I18n.getMessage("channel_config.description", Locale.ENGLISH))
.descriptionLocales(I18n.allNoneEnglishMessagesDescriptions("channel_config.description"))
.integrationTypes(CommandIntegrationType.ALL)
.option(CommandDefinitionOption.builder()
.name(SAVE_DIRECT_ROLL_CONFIG_OPTION_NAME)
.nameLocales(I18n.allNoneEnglishMessagesNames("channel_config.option.save_direct_roll_config.name"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.janno.discord.connector.api.message.EmbedOrMessageDefinition;
import de.janno.discord.connector.api.slash.CommandDefinition;
import de.janno.discord.connector.api.slash.CommandDefinitionOption;
import de.janno.discord.connector.api.slash.CommandIntegrationType;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -65,6 +66,7 @@ public AliasRollCommand(PersistenceManager persistenceManager, CachingDiceEvalua
.nameLocales(I18n.allNoneEnglishMessagesNames("a.name"))
.description(I18n.getMessage("a.description", Locale.ENGLISH))
.descriptionLocales(I18n.allNoneEnglishMessagesDescriptions("a.description"))
.integrationTypes(CommandIntegrationType.ALL)
.option(CommandDefinitionOption.builder()
.name(expressionOptionName)
.nameLocales(I18n.allNoneEnglishMessagesNames("a.expression.name"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import de.janno.discord.connector.api.message.EmbedOrMessageDefinition;
import de.janno.discord.connector.api.slash.CommandDefinition;
import de.janno.discord.connector.api.slash.CommandDefinitionOption;
import de.janno.discord.connector.api.slash.CommandIntegrationType;
import de.janno.discord.connector.api.slash.CommandInteractionOption;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -87,6 +88,7 @@ private static EmbedOrMessageDefinition createAnswerWithOptionalWarning(RollAnsw
.nameLocales(I18n.allNoneEnglishMessagesNames("r.name"))
.description(I18n.getMessage("r.description", Locale.ENGLISH))
.descriptionLocales(I18n.allNoneEnglishMessagesDescriptions("r.description"))
.integrationTypes(CommandIntegrationType.ALL)
.option(CommandDefinitionOption.builder()
.name(expressionOptionName)
.nameLocales(I18n.allNoneEnglishMessagesNames("r.expression.name"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import de.janno.discord.connector.api.message.EmbedOrMessageDefinition;
import de.janno.discord.connector.api.slash.CommandDefinition;
import de.janno.discord.connector.api.slash.CommandDefinitionOption;
import de.janno.discord.connector.api.slash.CommandIntegrationType;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -63,6 +64,7 @@ private AutoCompleteAnswer getValidAutoCompleteMessage(@NonNull String typedExpr
.nameLocales(I18n.allNoneEnglishMessagesNames("validation.name"))
.description(I18n.getMessage("validation.description", Locale.ENGLISH))
.descriptionLocales(I18n.allNoneEnglishMessagesDescriptions("validation.description"))
.integrationTypes(CommandIntegrationType.ALL)
.option(CommandDefinitionOption.builder()
.name(expressionOptionName)
.nameLocales(I18n.allNoneEnglishMessagesNames("validation.expression.name"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.janno.discord.connector.api.SlashEventAdaptor;
import de.janno.discord.connector.api.message.EmbedOrMessageDefinition;
import de.janno.discord.connector.api.slash.CommandDefinition;
import de.janno.discord.connector.api.slash.CommandIntegrationType;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;
Expand All @@ -26,6 +27,7 @@ public class HelpCommand implements SlashCommand {
return CommandDefinition.builder()
.name(getCommandId())
.nameLocales(I18n.allNoneEnglishMessagesNames("help.name"))
.integrationTypes(CommandIntegrationType.ALL)
.description(I18n.getMessage("help.description", Locale.ENGLISH))
.descriptionLocales(I18n.allNoneEnglishMessagesDescriptions("help.description"))
.build();
Expand All @@ -34,9 +36,12 @@ public class HelpCommand implements SlashCommand {
@Override
public @NonNull Mono<Void> handleSlashCommandEvent(@NonNull SlashEventAdaptor event, @NonNull Supplier<UUID> uuidSupplier, @NonNull Locale userLocale) {
BotMetrics.incrementSlashStartMetricCounter(getCommandId());

final String context = event.isUserInstallInteraction() ? "userInstall" : "guildInstall";

return event.replyWithEmbedOrMessageDefinition(EmbedOrMessageDefinition.builder()
.field(new EmbedOrMessageDefinition.Field(I18n.getMessage("help.quickstart.field.name", userLocale), I18n.getMessage("help.quickstart.field.value", userLocale), false))
.field(new EmbedOrMessageDefinition.Field(I18n.getMessage("help.command.field.name", userLocale), I18n.getMessage("help.command.field.value", userLocale), false))
.field(new EmbedOrMessageDefinition.Field(I18n.getMessage("help.quickstart.field.name", userLocale), I18n.getMessage("help.quickstart.field.value." + context, userLocale), false))
.field(new EmbedOrMessageDefinition.Field(I18n.getMessage("help.command.field.name", userLocale), I18n.getMessage("help.command.field.value." + context, userLocale), false))
.field(new EmbedOrMessageDefinition.Field(I18n.getMessage("help.documentation.field.name", userLocale), I18n.getMessage("help.documentation.field.value", userLocale), false))
.field(new EmbedOrMessageDefinition.Field(I18n.getMessage("help.discord.server.field.name", userLocale), I18n.getMessage("help.discord.server.field.value", userLocale), false))
.build(), true);
Expand Down
6 changes: 4 additions & 2 deletions bot/src/main/resources/botMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ help.discord.server.field.name=Discord Server for News, Help and Feature Request
custom_dice.help.example.field.value=`/custom_dice start buttons:3d6;10d10;3d20`
custom_parameter.help.example.field.value=`/custom_parameter start expression:{numberOfDice:1<=>10}d{sides:4/6/8/10/12/20/100}`
sum_custom_set.help.example.field.value=`/sum_custom_set start buttons:+;d6;1;2;3;4;5;6;7;8;9;0`
help.quickstart.field.value=Write `/welcome start` or `/quickstart system` to use pre-made RPG commands
help.command.field.value=Add `help` after a command to get specific help for it, e.g. `/custom_dice help`
help.quickstart.field.value.guildInstall=Write `/welcome start` or `/quickstart system` to use pre-made RPG commands
help.command.field.value.guildInstall=Add `help` after a command to get specific help for it, e.g. `/custom_dice help`
help.quickstart.field.value.userInstall=Write `/r expression: d20` to roll a twenty sided die
help.command.field.value.userInstall=Add `help` after a command to get specific help for it, e.g. `/r expression: help`
help.documentation.field.value=https://github.com/twonirwana/DiscordDiceBot
help.discord.server.field.value=https://discord.gg/e43BsqKpFr
r.help.example.value=`/r expression: 1d6@Damage`
Expand Down
6 changes: 4 additions & 2 deletions bot/src/main/resources/botMessages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ help.discord.server.field.name=Discord Server für Hilfe und Neuigkeiten
custom_dice.help.example.field.value=`/custom_dice start buttons:3d6;10d10;3d20`
custom_parameter.help.example.field.value=`/custom_parameter start ausdruck:{numberOfDice:1<=>10}d{sides:4/6/8/10/12/20/100}`
sum_custom_set.help.example.field.value=`/sum_custom_set start buttons:+;d6;1;2;3;4;5;6;7;8;9;0`
help.quickstart.field.value=Schreib `/welcome start` oder `/quickstart system` um vorgefertigte RPG Kommandos zu starten
help.command.field.value=Füge `help` nach einem Befehl um spezifische Hilfe zu bekommen, z.B. `/custom_dice help`
help.quickstart.field.value.guildInstall=Schreib `/welcome start` oder `/quickstart system` um vorgefertigte RPG Kommandos zu starten
help.command.field.value.guildInstall=Füge `help` nach einem Befehl um spezifische Hilfe zu bekommen, z.B. `/custom_dice help`
help.quickstart.field.value.userInstall=Schreib `/r expression: d20` um einen zwanzig Seitigen Würfel zu würfeln
help.command.field.value.userInstall=Füge `help` nach einem Befehl um spezifische Hilfe zu bekommen, z.B. `/r expression: help`
#help.documentation.field.value=https://github.com/twonirwana/DiscordDiceBot
#help.discord.server.field.value=https://discord.gg/e43BsqKpFr
r.help.example.value=`/{0} ausdruck:1d6`
Expand Down
6 changes: 4 additions & 2 deletions bot/src/main/resources/botMessages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ help.discord.server.field.name=Serveur Discord pour l'aide et les nouvelles
custom_dice.help.example.field.value=`/custom_dice démarrer boutons:3d6;10d10;3d20`
custom_parameter.help.example.field.value=`/custom_parameter démarrer expression:{numberOfDice:1<=>10}d{sides:4/6/8/10/12/20/100}`
sum_custom_set.help.example.field.value=`/sum_custom_set démarrer boutons:+;d6;1;2;3;4;5;6;7;8;9;0`
help.quickstart.field.value=Ecrire `/welcome start` ou `/quickstart système` pour utiliser des commandes RPG pré-faites
help.command.field.value=Ajoutez `help` après une commande pour obtenir une aide spécifique, par exemple `/custom_dice help`
help.quickstart.field.value.guildInstall=Ecrire `/welcome start` ou `/quickstart système` pour utiliser des commandes RPG pré-faites
help.command.field.value.guildInstall=Ajoutez `help` après une commande pour obtenir une aide spécifique, par exemple `/custom_dice help`
help.quickstart.field.value.userInstall=Ecrire `/r expression : d20` pour lancer un dé à vingt faces
help.command.field.value.userInstall=Ajoutez `help` après une commande pour obtenir une aide spécifique, par exemple `/r expression: help`
help.documentation.field.value=https://github.com/twonirwana/DiscordDiceBot
help.discord.server.field.value=https://discord.gg/e43BsqKpFr
r.help.example.value=`/{0} expression:1d6`
Expand Down
6 changes: 4 additions & 2 deletions bot/src/main/resources/botMessages_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ help.discord.server.field.name=Servidor do Discord Server para ajuda e notícias
custom_dice.help.example.field.value=`/custom_dice iniciar botoes:3d6;10d10;3d20`
custom_parameter.help.example.field.value=`/custom_parameter iniciar formula:{numberOfDice:1<=>10}d{sides:4/6/8/10/12/20/100}`
sum_custom_set.help.example.field.value=`/sum_custom_set iniciar botoes:+;d6;1;2;3;4;5;6;7;8;9;0`
help.quickstart.field.value=Escreva `/welcome iniciar` ou `/quickstart sistema` para usar comando de RPG pré-configurados
help.command.field.value=Adicione `help`depois de um comando para ter ajuda espefícia para ele, ex.: `/custom_dice help`
help.quickstart.field.value.guildInstall=Escreva `/welcome iniciar` ou `/quickstart sistema` para usar comando de RPG pré-configurados
help.command.field..guildInstall=Adicione `help`depois de um comando para ter ajuda espefícia para ele, ex.: `/custom_dice help`
help.quickstart.field.value.userInstall=Escreva `/r expression: d20` para lançar um dado de vinte lados
help.command.field.value.userInstall=Adicione `help`depois de um comando para ter ajuda espefícia para ele, ex.: `/r expression: help`
help.documentation.field.value=https://github.com/twonirwana/DiscordDiceBot
help.discord.server.field.value=https://discord.gg/e43BsqKpFr
r.help.example.value=`/{0} formula:1d6`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import de.janno.discord.connector.api.slash.CommandInteractionOption;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.ParallelFlux;
Expand All @@ -26,6 +27,9 @@ public class SlashEventAdaptorMock implements SlashEventAdaptor {
private final List<EmbedOrMessageDefinition> allReplays = new ArrayList<>();
private final long userId;
private final Locale userLocale;
@Getter
@Setter
private boolean userInstallInteraction = false;

@Getter
private Optional<ButtonEventAdaptorMock> firstButtonEventMockOfLastButtonMessage = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ de.janno.discord.bot.command.ClearCommandTest.getCommandDefinition=[
"description": "Supprime tous les messages des boutons et les données sauvegardées du bot pour ce canal."
}
],
"options": [ ]
"options": [ ],
"integrationTypes": [
"GUILD_INSTALL"
]
}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ de.janno.discord.bot.command.FetchCommandMockTest.getCommandDefinition=[
"description": "Déplace le dernier message du lancer de dés vers l'avant"
}
],
"options": [ ]
"options": [ ],
"integrationTypes": [
"GUILD_INSTALL"
]
}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ de.janno.discord.bot.command.channelConfig.ChannelConfigTest.getCommandDefinitio
],
"autoComplete": false
}
],
"integrationTypes": [
"GUILD_INSTALL",
"USER_INSTALL"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ de.janno.discord.bot.command.customDice.CustomDiceCommandTest.getCommandDefiniti
"options": [ ],
"autoComplete": false
}
],
"integrationTypes": [
"GUILD_INSTALL"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ de.janno.discord.bot.command.customParameter.CustomParameterCommandTest.getComma
"options": [ ],
"autoComplete": false
}
],
"integrationTypes": [
"GUILD_INSTALL"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ de.janno.discord.bot.command.directRoll.AliasRollCommandTest.getCommandDefinitio
"options": [ ],
"autoComplete": true
}
],
"integrationTypes": [
"GUILD_INSTALL",
"USER_INSTALL"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ de.janno.discord.bot.command.directRoll.DirectRollCommandTest.getCommandDefiniti
"options": [ ],
"autoComplete": false
}
],
"integrationTypes": [
"GUILD_INSTALL",
"USER_INSTALL"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ de.janno.discord.bot.command.directRoll.HiddenRollCommandTest.getCommandDefiniti
"options": [ ],
"autoComplete": false
}
],
"integrationTypes": [
"GUILD_INSTALL"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ de.janno.discord.bot.command.directRoll.ValidationCommandTest.getCommandDefiniti
"options": [ ],
"autoComplete": true
}
],
"integrationTypes": [
"GUILD_INSTALL",
"USER_INSTALL"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import au.com.origin.snapshots.Expect;
import au.com.origin.snapshots.junit5.SnapshotExtension;
import de.janno.discord.connector.api.SlashEventAdaptor;
import de.janno.discord.bot.SlashEventAdaptorMock;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.util.List;
import java.util.Locale;
import java.util.UUID;

import static org.mockito.Mockito.*;

@ExtendWith(SnapshotExtension.class)
class HelpCommandTest {

Expand All @@ -32,10 +31,22 @@ public void getId() {

@Test
void handleSlashCommandEvent() {
SlashEventAdaptor slashEventAdaptor = mock(SlashEventAdaptor.class);
when(slashEventAdaptor.replyWithEmbedOrMessageDefinition(any(), anyBoolean())).thenReturn(Mono.empty());
SlashEventAdaptorMock slashEventAdaptor = new SlashEventAdaptorMock(List.of());

Mono<Void> res = underTest.handleSlashCommandEvent(slashEventAdaptor, () -> UUID.fromString("00000000-0000-0000-0000-000000000000"), Locale.ENGLISH);
StepVerifier.create(res).verifyComplete();

expect.toMatchSnapshot(slashEventAdaptor.getSortedActions());
}

@Test
void handleSlashCommandEvent_userInstall() {
SlashEventAdaptorMock slashEventAdaptor = new SlashEventAdaptorMock(List.of());
slashEventAdaptor.setUserInstallInteraction(true);

Mono<Void> res = underTest.handleSlashCommandEvent(slashEventAdaptor, () -> UUID.fromString("00000000-0000-0000-0000-000000000000"), Locale.ENGLISH);
StepVerifier.create(res).verifyComplete();

expect.toMatchSnapshot(slashEventAdaptor.getSortedActions());
}
}
Loading
Loading