Skip to content

Commit

Permalink
add an option to split large messages in the spam module and also add…
Browse files Browse the repository at this point in the history
… an option for uppercase letters in bypass
  • Loading branch information
Funtimes909 committed Sep 12, 2024
1 parent bddc37d commit cb5ebe9
Showing 1 changed file with 67 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class Spam extends Module {
.build()
);


private final Setting<Boolean> disableOnDisconnect = sgGeneral.add(new BoolSetting.Builder()
.name("disable-on-disconnect")
.description("Disables spam when you are disconnected from a server.")
Expand All @@ -60,13 +59,47 @@ public class Spam extends Module {
.build()
);

private final Setting<Boolean> autoSplitMessages = sgGeneral.add(new BoolSetting.Builder()
.name("auto-split-messages")
.description("Automatically split up large messages after a certain length")
.defaultValue(false)
.build()
);

private final Setting<Integer> splitLength = sgGeneral.add(new IntSetting.Builder()
.name("split-length")
.description("The length after which to split messages in chat")
.visible(autoSplitMessages::get)
.defaultValue(256)
.min(1)
.sliderMax(256)
.build()
);

private final Setting<Integer> autoSplitDelay = sgGeneral.add(new IntSetting.Builder()
.name("split-delay")
.description("The delay between split messages in ticks.")
.defaultValue(20)
.min(0)
.sliderMax(200)
.build()
);

private final Setting<Boolean> bypass = sgGeneral.add(new BoolSetting.Builder()
.name("bypass")
.description("Add random text at the end of the message to try to bypass anti spams.")
.defaultValue(false)
.build()
);

private final Setting<Boolean> lowercase = sgGeneral.add(new BoolSetting.Builder()
.name("lowercase")
.description("Should bypass include uppercase characters?")
.visible(bypass::get)
.defaultValue(true)
.build()
);

private final Setting<Integer> length = sgGeneral.add(new IntSetting.Builder()
.name("length")
.description("Number of characters used to bypass anti spam.")
Expand All @@ -76,7 +109,7 @@ public class Spam extends Module {
.build()
);

private int messageI, timer;
private int messageI, timer, splitDelay;

public Spam() {
super(Categories.Misc, "spam", "Spams specified messages in chat.");
Expand All @@ -85,6 +118,7 @@ public Spam() {
@Override
public void onActivate() {
timer = delay.get();
splitDelay = delay.get();
messageI = 0;
}

Expand All @@ -108,21 +142,45 @@ private void onTick(TickEvent.Post event) {
int i;
if (random.get()) {
i = Utils.random(0, messages.get().size());
}
else {
} else {
if (messageI >= messages.get().size()) messageI = 0;
i = messageI++;

}

String text = messages.get().get(i);
if (bypass.get()) {
text += " " + RandomStringUtils.randomAlphabetic(length.get()).toLowerCase();
if (!lowercase.get()) {
text += " " + RandomStringUtils.randomAlphabetic(length.get());
} else {
text += " " + RandomStringUtils.randomAlphabetic(length.get()).toLowerCase();
}
}

ChatUtils.sendPlayerMsg(text);
timer = delay.get();
}
else {
if (autoSplitMessages.get()) {
if (text.length() >= splitLength.get()) {
int chunkSize = splitLength.get();
int length = text.length();
// For every substring of text larger than the split length, send that chunk
for (int a = 0; a < length; a += chunkSize) {
int end = Math.min(a + chunkSize, length);
String chunk = text.substring(a, end);
if (splitDelay <= 0) {
ChatUtils.sendPlayerMsg(chunk);
splitDelay = autoSplitDelay.get();
} else {
splitDelay--;
}
}
} else {
ChatUtils.sendPlayerMsg(text);
timer = delay.get();
}
} else {
ChatUtils.sendPlayerMsg(text);
timer = delay.get();
}
} else {
timer--;
}
}
Expand Down

0 comments on commit cb5ebe9

Please sign in to comment.