Skip to content
Merged
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8fbb2c2
Added: MAX_AGE_DURATION - This converts seconds to days (7) Being max…
Budbomber Jan 13, 2022
3e718a7
Added: MAX_AGE_DURATION_ONE_WEEK sets the duration the max duration i…
Budbomber Jan 14, 2022
903fcf6
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 14, 2022
2e97eda
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 14, 2022
ff8f11c
Added: MAX_AGE_DURATION_ONE_WEEK sets the duration the max duration i…
Budbomber Jan 14, 2022
0756745
Merge remote-tracking branch 'origin/develop' into develop
Budbomber Jan 14, 2022
9ccf518
Cleaned up code, Added MAX_USES_MAX VALUE, reformatted MAX_AGE_MAX_VA…
Budbomber Jan 14, 2022
4d015aa
Cleaned up code, Added MAX_VALUE_MAX_USES, reformatted MAX_VALUE_MAX_…
Budbomber Jan 14, 2022
93b9927
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 14, 2022
d760bc0
Taken into account, all the suggestions cleaned up code
Budbomber Jan 15, 2022
505da9b
Merge remote-tracking branch 'origin/develop' into develop
Budbomber Jan 15, 2022
2c7567c
Update VcActivityCommand.java
Budbomber Jan 15, 2022
f26b4f2
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 15, 2022
6f5cbbd
Update VcActivityCommand.java
Budbomber Jan 15, 2022
825ec48
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 15, 2022
5104e73
Update VcActivityCommand.java
Budbomber Jan 15, 2022
2ae2a87
Taken into account, all the suggestions cleaned up code
Budbomber Jan 15, 2022
b57c07b
Merge remote-tracking branch 'origin/develop' into develop
Budbomber Jan 15, 2022
f7d0640
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 15, 2022
a49095c
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 15, 2022
4ddbd6c
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 15, 2022
29d217f
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 15, 2022
a4ccedb
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 15, 2022
aeb8e79
Update application/src/main/java/org/togetherjava/tjbot/commands/basi…
Budbomber Jan 15, 2022
97ed98a
Made changes Zabu requested, typos, Moved declarations, updated doc, …
Budbomber Jan 17, 2022
0aca975
Final changes made, renamed handle method to RequiredOptionIfPresent,…
Budbomber Jan 17, 2022
c11b8ea
Changes made, remaned maxAge to maxAgeDays, added check in voicechane…
Budbomber Jan 17, 2022
19062bc
Fixed typo's changed text in options to reflect the values set in the…
Budbomber Jan 17, 2022
0a98196
Fixed value that was forgotten, input is now in days for UX, and the …
Budbomber Jan 17, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

/**
* Implements the {@code vc-activity} command. Creates VC activities.
Expand All @@ -45,6 +46,9 @@ public final class VcActivityCommand extends SlashCommandAdapter {
private static final String MAX_USES_OPTION = "max-uses";
private static final String MAX_AGE_OPTION = "max-age";

private static final long MAX_VALUE_MAX_AGE = TimeUnit.DAYS.toSeconds(7);
private static final long MAX_VALE_MAX_USES = 100;

public static final String YOUTUBE_TOGETHER_NAME = "YouTube Together";
public static final String POKER_NAME = "Poker";
public static final String BETRAYAL_IO_NAME = "Betrayal.io";
Expand Down Expand Up @@ -83,11 +87,12 @@ public final class VcActivityCommand extends SlashCommandAdapter {
"879863976006127627", LETTERTILE_NAME, "879863686565621790");

private static final List<OptionData> inviteOptions = List.of(
new OptionData(OptionType.STRING, MAX_USES_OPTION,
"The amount of times the invite can be used, default is infinity", false),
new OptionData(OptionType.INTEGER, MAX_USES_OPTION,
"The amount of times the invite can be used, default is infinity", false)
.setRequiredRange(0, MAX_VALE_MAX_USES),
new OptionData(OptionType.INTEGER, MAX_AGE_OPTION,
"Max age in seconds. Set this to 0 to never expire, default is 1 day", false));

"Max age in seconds. Set this to 0 to never expire, default is 1 day", false)
.setRequiredRange(0, MAX_VALUE_MAX_AGE));

/**
* Constructs an instance
Expand Down Expand Up @@ -148,29 +153,15 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) {
OptionMapping maxUsesOption = event.getOption(MAX_USES_OPTION);
OptionMapping maxAgeOption = event.getOption(MAX_AGE_OPTION);

String applicationId;
String applicationName;
Integer maxUses;

// the user already received the error in the handleIntegerTypeOption method
// it still throws to tell us to return this method and stop the proceeding code
try {
maxUses = handleIntegerTypeOption(event, maxUsesOption);
} catch (IllegalArgumentException ignore) {
return;
}

Integer maxAge;

// the user already received the error in the handleIntegerTypeOption method
// it still throws to tell us to return this method and stop the proceeding code
try {
maxAge = handleIntegerTypeOption(event, maxAgeOption);
} catch (IllegalArgumentException ignore) {
return;
}

maxUses = handleIntegerTypeOption(maxUsesOption);
maxAge = handleIntegerTypeOption(maxAgeOption);

String applicationId;
String applicationName;

if (applicationOption != null) {
applicationName = applicationOption.getAsString();
Expand Down Expand Up @@ -223,51 +214,29 @@ private static void handleErrors(@NotNull SlashCommandEvent event,
logger.warn("Something went wrong in the VcActivityCommand", throwable);
}


/**
* This grabs the OptionMapping, after this it <br />
* - validates whenever it's within an {@link Integer Integer's} range <br />
* - validates whenever it's positive <br />
* This grabs the OptionMapping, after this it returns null of the OptionMapping is null, else
* it'll return the number option as an Integer
*
* <p>
* <p/>
*
* @param event the {@link SlashCommandEvent}
* @param optionMapping the {@link OptionMapping}
* @return nullable {@link Integer}
* @throws java.lang.IllegalArgumentException if the option's value is - outside of
* {@link Integer#MAX_VALUE} - negative
*/
@Contract("_, null -> null")
private static @Nullable Integer handleIntegerTypeOption(@NotNull SlashCommandEvent event,
**/
@Contract("null -> null")
private static @Nullable Integer handleIntegerTypeOption(
@Nullable OptionMapping optionMapping) {

int optionValue;

if (optionMapping == null) {
return null;
}
} else {

try {
optionValue = Math.toIntExact(optionMapping.getAsLong());
} catch (ArithmeticException e) {
event
.reply("The " + optionMapping.getName() + " is above `" + Integer.MAX_VALUE
+ "`, which is too high")
.setEphemeral(true)
.queue();
throw new IllegalArgumentException(
optionMapping.getName() + " can't be above " + Integer.MAX_VALUE);
}

if (optionValue < 0) {
event.reply("The " + optionMapping.getName() + " is negative, which isn't supported")
.setEphemeral(true)
.queue();
throw new IllegalArgumentException(optionMapping.getName() + " can't be negative");
}


return optionValue;
}
}