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

Chatbot: Add option to reset sequential index on disable #98

Merged
merged 2 commits into from
Aug 3, 2019
Merged
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
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