diff --git a/common/src/main/java/com/discordsrv/common/core/logging/impl/DependencyLoggingHandler.java b/common/src/main/java/com/discordsrv/common/core/logging/impl/DependencyLoggingHandler.java index 4dff2481..a8c02643 100644 --- a/common/src/main/java/com/discordsrv/common/core/logging/impl/DependencyLoggingHandler.java +++ b/common/src/main/java/com/discordsrv/common/core/logging/impl/DependencyLoggingHandler.java @@ -19,11 +19,13 @@ package com.discordsrv.common.core.logging.impl; import com.discordsrv.common.DiscordSRV; +import com.discordsrv.common.helper.Timeout; import com.discordsrv.common.logging.LogAppender; import com.discordsrv.common.logging.LogLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.time.Duration; import java.util.*; import java.util.concurrent.RejectedExecutionException; @@ -31,6 +33,7 @@ public class DependencyLoggingHandler implements LogAppender { private static final Map> BLACKLISTED_MESSAGES = new HashMap<>(); private static final Map LOGGER_MAPPINGS = new HashMap<>(); + private static final Timeout RATELIMIT_TIMEOUT = new Timeout(Duration.ofSeconds(20)); static { // Class names here will get relocated, which is fine @@ -93,6 +96,23 @@ public class DependencyLoggingHandler implements LogAppender { } } + if (name.equals("JDA") && message != null && + (message.startsWith("Encountered global rate limit!") + || message.startsWith("Encountered cloudflare rate limit!"))) { + if (!RATELIMIT_TIMEOUT.checkAndUpdate()) { + discordSRV.logger().warning(message); + return; + } + + boolean usingProxy = discordSRV.connectionConfig().httpProxy.enabled; + discordSRV.logger().warning("+------------------------------------------>"); + discordSRV.logger().warning("| " + message); + discordSRV.logger().warning("| This means the " + (usingProxy ? "proxy" : "server") + "'s ip is sending too many requests to Discord"); + discordSRV.logger().warning("| The ip is being temporarily restricted from making requests to Discord"); + discordSRV.logger().warning("+------------------------------------------>"); + return; + } + if (name.equals("JDA") && message != null && message.contains("Got an unexpected error. Please redirect the following message to the devs:") && throwable instanceof RejectedExecutionException