Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Commit 413371d

Browse files
authored
Merge pull request #301 from Jookly123/banned-user-discord-notif
Added banned user notification to Discord Remote Control, thanks Jookly123!
2 parents 2f0143c + 10bbaca commit 413371d

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
44
mcVersion=1.8.9
55
modid=farmhelperv2
66
modName=FarmHelper
7-
version=2.9.4-pre2
7+
version=2.9.4-pre3
88
shouldRelease=true

src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,11 @@ public static void triggerManuallyPestsDestroyer() {
14131413
description = "Sends messages when the macro has been enabled or disabled"
14141414
)
14151415
public static boolean sendMacroEnableDisableLogs = true;
1416+
@Switch(
1417+
name = "Send FH ban logs", category = DISCORD_INTEGRATION, subcategory = "Discord Webhook",
1418+
description = "Sends message when a FH user gets banned (Like in game chat)"
1419+
)
1420+
public static boolean sendFHBanLogs = false;
14161421
@Text(
14171422
name = "WebHook URL", category = DISCORD_INTEGRATION, subcategory = "Discord Webhook",
14181423
description = "The URL to use for the webhook",

src/main/java/com/jelly/farmhelperv2/feature/impl/BanInfoWS.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.nio.charset.StandardCharsets;
3737
import java.util.*;
3838
import java.util.concurrent.TimeUnit;
39+
import java.util.regex.Pattern;
3940
import java.util.zip.GZIPInputStream;
4041
import java.util.zip.GZIPOutputStream;
4142

@@ -640,12 +641,18 @@ public void onMessage(String message) {
640641
String crop = jsonObject.get("crop").getAsString().toLowerCase().replace("_", " ");
641642
long longestSession7D = jsonObject.get("longestSession7D").getAsLong();
642643
String lastFailsafe = jsonObject.get("lastFailsafe").getAsString();
643-
LogUtils.sendWarning("User §c" + username + "§e got banned for " + days + " days"
644+
String warningMessage = ("User §c" + username + "§e got banned for " + days + " days"
644645
+ (macroEnabled ? " while " + (fastBreak ? "§c§nfastbreaking§r§e " : "farming ") + crop + "." : ".")
645646
+ "\n§ePossible reason: §c" + reason + "§e."
646647
+ "\n§eLongest session in the last 7 days: §c" + LogUtils.formatTime(longestSession7D)
647648
+ (!lastFailsafe.isEmpty() ? "\n§eLast failsafe: §c" + lastFailsafe : ""));
649+
LogUtils.sendWarning(warningMessage);
648650
// LogUtils.sendNotification("Farm Helper", "User " + username + " got banned for " + days + " days");
651+
if (FarmHelperConfig.sendFHBanLogs && FarmHelperConfig.enableWebHook) {
652+
Pattern MC_COLOUR = Pattern.compile("§[0-9A-FK-ORa-fk-or]");
653+
String cleanString = MC_COLOUR.matcher(warningMessage).replaceAll("").replace("\n", "\\n");
654+
LogUtils.FHBanLogsWebhook(cleanString);
655+
}
649656
break;
650657
}
651658
}

src/main/java/com/jelly/farmhelperv2/util/LogUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,28 @@ public static void webhookLog(String message, boolean mentionAll, Tuple<String,
181181
sendWebhook(webhook);
182182
}
183183

184+
@SafeVarargs
185+
public static void FHBanLogsWebhook(String message, Tuple<String, String>... fields) {
186+
if (!FarmHelperConfig.enableWebHook) return;
187+
if (!FarmHelperConfig.sendLogs) return;
188+
if (!FarmHelperConfig.sendFHBanLogs) return;
189+
190+
DiscordWebhook webhook = new DiscordWebhook(FarmHelperConfig.webHookURL.replace(" ", "").replace("\n", "").trim());
191+
webhook.setUsername("Jelly - User Bans Log");
192+
webhook.setAvatarUrl("https://cdn.discordapp.com/attachments/1152966451406327858/1160577992876109884/icon.png");
193+
String randomColor = String.format("#%06x", (int) (Math.random() * 0xFFFFFF));
194+
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject()
195+
.setDescription("### " + message)
196+
.setColor(Color.decode(randomColor))
197+
.setFooter("Farm Helper Webhook Status", "https://cdn.discordapp.com/attachments/861700235890130986/1144673641951395982/icon.png");
198+
for (Tuple<String, String> field : fields) {
199+
embedObject.addField(field.getFirst(), field.getSecond(), false);
200+
}
201+
retries = 0;
202+
webhook.addEmbed(embedObject);
203+
sendWebhook(webhook);
204+
}
205+
184206
private static void sendWebhook(DiscordWebhook webhook) {
185207
Multithreading.schedule(() -> {
186208
try {

0 commit comments

Comments
 (0)