Skip to content

Commit 7bc91f1

Browse files
tearfulDalvikJRoy
andauthored
Discord: Add setting to configure an HTTP Proxy for JDA (#6275)
Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
1 parent 7c89592 commit 7bc91f1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

EssentialsDiscord/src/main/java/net/essentialsx/discord/DiscordSettings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public String getBotToken() {
6262
return config.getString("token", "");
6363
}
6464

65+
// #easteregg
66+
public String getHttpProxyServer() {
67+
return config.getString("http-proxy-server", "");
68+
}
69+
6570
public long getGuildId() {
6671
return config.getLong("guild", 0);
6772
}

EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.earth2me.essentials.utils.FormatUtil;
99
import com.earth2me.essentials.utils.NumberUtil;
1010
import com.earth2me.essentials.utils.VersionUtil;
11+
import com.neovisionaries.ws.client.ProxySettings;
12+
import com.neovisionaries.ws.client.WebSocketFactory;
1113
import net.dv8tion.jda.api.JDA;
1214
import net.dv8tion.jda.api.JDABuilder;
1315
import net.dv8tion.jda.api.entities.Guild;
@@ -168,7 +170,14 @@ public void startup() throws LoginException, InterruptedException {
168170
throw new IllegalArgumentException(tlLiteral("discordErrorNoToken"));
169171
}
170172

173+
final WebSocketFactory wsFactory = new WebSocketFactory();
174+
if (!plugin.getSettings().getHttpProxyServer().trim().isEmpty()) {
175+
final ProxySettings proxySettings = wsFactory.getProxySettings();
176+
proxySettings.setServer(plugin.getSettings().getHttpProxyServer());
177+
}
178+
171179
jda = JDABuilder.createDefault(plugin.getSettings().getBotToken())
180+
.setWebsocketFactory(wsFactory)
172181
.addEventListeners(new DiscordListener(this))
173182
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
174183
.enableCache(CacheFlag.EMOJI)

0 commit comments

Comments
 (0)