Skip to content

Commit

Permalink
Custom parameter layout (twonirwana#179)
Browse files Browse the repository at this point in the history
* wip

* wip

* readme
  • Loading branch information
twonirwana authored Dec 23, 2022
1 parent 3277427 commit 7a745f0
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 346 deletions.
14 changes: 9 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Some example for commands, many more systems can be mapped, please see in the de
[discrete]
=== Savage Worlds:

`/custom_parameter start expression: (d!!{side:4/6/8/12/20} + {Hero: 0/1d!!6})k1`
`/custom_parameter start expression: (d!!{Dice:4@D4/6@D6/8@D8/12@D12/20@D20} + {Type: 0@Regular/1d!!6@Wildcard})k1`

[discrete]
=== Traveller
Expand Down Expand Up @@ -111,7 +111,8 @@ image:image/full.png[image]

==== Without expression

`without_expression` is the same as `full` but don't show the dice expression in the result. This is useful if the expression is very long and it is recommended to add a label.
`without_expression` is the same as `full` but don't show the dice expression in the result.
This is useful if the expression is very long and it is recommended to add a label.

image:image/without_expression.png[image]

Expand Down Expand Up @@ -269,20 +270,23 @@ The old version of the command, with the old dice expression, can be still used

image:image/custom_parameter.webp[image]

Use for example the slash command `/custom_parameter expression:{numberOfDice:1<=>10}d{sides:4/6/8/10/12/20/100}` to create a message with a dice expression, where the user can fill the parameter with buttons.
Use for example the slash command `/custom_parameter expression:{numberOfDice:1\<\=>10}d{sides:4@D4/6@D6/8@D8/12@D12/20@D20}` to create a message with a dice expression, where the user can fill the parameter with buttons.
For the dice expression see the section <<Dice Expression Notation>>.
The parameter have the format `+{name}+`.
If there is no range given, then button for the values 1-15 are presented.
There are two parameter range notations:

* `{numberOfDice:1<=>10}`: Provides the buttons for the given range (including).
* `{numberOfDice:1\<\=>10}`: Provides the buttons for the given range (including).
The maximum are 23 buttons.
* `{sides:4/6/8/10/12/20/100}`: Provides each value, seperated be a slash up to 23 buttons.
* `{sides:4/6/8/10/12/20}`: Provides each value, seperated be a slash up to 23 buttons.
It is possible to add an optional label to each value in the format `value@label`.
For example `{bonus:0@None/3@Small Bonus/5@Big Bonus}` will show on the buttons 'None', 'Small Bonus' and 'Big Bonus' but apply the values 0, 3 or 5 to the expression

The user can click on the buttons to fill all open parameter of the expression.
If all parameter are selected then the expression will be rolled.
The first user that clicks on a button add his name to the message and only this user can select further parameter.
Every user can still use the `Clear` button.
The command uses the `without_expression` as default answer format.

=== Clear Command

Expand Down
2 changes: 1 addition & 1 deletion bot/src/main/java/de/janno/discord/bot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void main(final String[] args) throws Exception {
final String token = args[0];
final boolean disableCommandUpdate = Boolean.parseBoolean(args[1]);
final String publishMetricsToUrl = args[2];
BotMetrics.init(publishMetricsToUrl);
BotMetrics.init(publishMetricsToUrl, 8080);

final String h2Url;
if (args.length >= 4) {
Expand Down
4 changes: 2 additions & 2 deletions bot/src/main/java/de/janno/discord/bot/BotMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class BotMetrics {
private static final String ANSWER_TIMER_PREFIX = "answerTimer";
private static final String NEW_BUTTON_TIMER_PREFIX = "newButtonTimer";

public static void init(String publishMetricsToUrl) {
public static void init(String publishMetricsToUrl, int port) {
if (!Strings.isNullOrEmpty(publishMetricsToUrl)) {
PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
Metrics.addRegistry(prometheusRegistry);
Expand All @@ -55,7 +55,7 @@ public static void init(String publishMetricsToUrl) {
exchange.getResponseSender().send(prometheusRegistry.scrape());
});
Undertow server = Undertow.builder()
.addHttpListener(8080, publishMetricsToUrl)
.addHttpListener(port, publishMetricsToUrl)
.setHandler(handler).build();
server.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ protected Optional<Long> getAnswerTargetChannelIdFromStartCommandOption(@NonNull
protected AnswerFormatType getAnswerTypeFromStartCommandOption(@NonNull CommandInteractionOption options) {
return options.getStringSubOptionWithName(ANSWER_FORMAT_OPTION)
.map(AnswerFormatType::valueOf)
.orElse(AnswerFormatType.full);
.orElse(defaultAnswerFormat());
}

protected AnswerFormatType defaultAnswerFormat(){
return AnswerFormatType.full;
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions bot/src/main/java/de/janno/discord/bot/command/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class State<T extends StateData> {

@NonNull
String buttonValue;

//todo optional getter
@Nullable
T data;

Expand Down
Loading

0 comments on commit 7a745f0

Please sign in to comment.