Skip to content

Commit

Permalink
Chatbot: Add option to reset sequential index on disable (#98)
Browse files Browse the repository at this point in the history
* Chatbot: Add option to reset sequential index on disable

* Add dash to command!
  • Loading branch information
VADemon authored and fr1kin committed Aug 3, 2019
1 parent 457495e commit 0af573b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/main/java/com/matt/forgehax/mods/ChatBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

@RegisterMod
public class ChatBot extends ToggleMod {
public final Options<SpamEntry> spams =
private final Options<SpamEntry> spams =
getCommandStub()
.builders()
.<SpamEntry>newOptionsBuilder()
Expand All @@ -43,7 +43,7 @@ public class ChatBot extends ToggleMod {
.supplier(Sets::newConcurrentHashSet)
.build();

public final Setting<Integer> max_input_length =
private final Setting<Integer> max_input_length =
getCommandStub()
.builders()
.<Integer>newSettingBuilder()
Expand All @@ -54,10 +54,28 @@ public class ChatBot extends ToggleMod {
.max(256)
.build();

private final Setting<Boolean> resetSequentialIndex =
getCommandStub()
.builders()
.<Boolean>newSettingBuilder()
.name("reset-sequential")
.description("start spam list anew in sequential mode")
.defaultTo(false)
.build();

public ChatBot() {
super(Category.MISC, "ChatBot", false, "Spam chat");
}

@Override
protected void onDisabled() {
if (resetSequentialIndex.get()) {
for (SpamEntry e : spams) {
e.reset();
}
}
}

@Override
protected void onLoad() {
spams
Expand Down Expand Up @@ -103,6 +121,7 @@ protected void onLoad() {
if (data.hasOption("trigger")) entry.setTrigger(data.getOptionAsString("trigger"));
if (data.hasOption("enabled"))
entry.setEnabled(SafeConverter.toBoolean(data.getOptionAsString("enabled")));
if (!entry.isEnabled() && resetSequentialIndex.get()) entry.reset();
if (data.hasOption("delay"))
entry.setDelay(SafeConverter.toLong(data.getOptionAsString("delay")));

Expand Down

0 comments on commit 0af573b

Please sign in to comment.