Skip to content

Commit

Permalink
Updated JDA and fixed it not loading on SpongeForge (damn module-info)
Browse files Browse the repository at this point in the history
Added warning about missing server intents
Bump version
  • Loading branch information
Eufranio committed Oct 27, 2020
1 parent 74fcb18 commit 6ec024d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ MagiBridge is a Sponge plugin that creates a Discord <-> Minecraft chat bridge,
## How to MagiBridge:
1) Go to https://discordapp.com/developers/applications/me and create a new App
2) Scroll down and click on "Create a Bot User"
3) Reveal the Token and copy-paste it into the bot-token="..." field in the `config/magibridge/MagiBridge.conf` file
4) Create a new Discord Server. It will have a #general channel. You can create other channels.
5) Add the bot to your server: Find the Client ID of the new App, and replace the CLIENTID in the following link with your bot's client ID in
3) Go to the **Bot** section, reveal the Token and copy-paste it into the bot-token="..." field in the `config/magibridge/MagiBridge.conf` file
4) **In the Privileged Gateway Intents section, make sure to ENABLE the SERVER MEMBERS INTENT. Without it, MagiBridge cannot track the discord users.
5) Create a new Discord Server. It will have a #general channel. You can create other channels.
6) Add the bot to your server: Find the Client ID of the new App, and replace the CLIENTID in the following link with your bot's client ID in
https://discordapp.com/oauth2/authorize?client_id=CLIENTID&scope=bot (for example, if you bot's Client ID is 168682538028630017, your link would be https://discordapp.com/oauth2/authorize?client_id=168682538028630017&scope=bot), select Your Server from the drop-down menu, and Authorize. You must have the Manage Server permission to add a bot to a server!
6) On _Server Settings_, in _Roles_, create a _New Role_ named e.g. "bot", give it the _Manage Channels_ permission, and in _Members_ [grant your Bot that role](https://support.discordapp.com/hc/en-us/articles/206029707).
7) [Enable Discord Developer Mode](https://discordia.me/developer-mode) and [copy-paste the channel ID you want to use](https://support.discordapp.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-) into the main-discord-channel=" "
7) On _Server Settings_, in _Roles_, create a _New Role_ named e.g. "bot", give it the _Manage Channels_ permission, and in _Members_ [grant your Bot that role](https://support.discordapp.com/hc/en-us/articles/206029707).
8) [Enable Discord Developer Mode](https://discordia.me/developer-mode) and [copy-paste the channel ID you want to use](https://support.discordapp.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-) into the main-discord-channel=" "

8) Make sure you have the compatibility features enabled and properly configured in `MagiBridge.conf` for Nucleus, UltimateChat and Boop if you're using them
9) Configure the rest of the stuff you want and reload the plugin/start the server
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
shadow 'com.github.Aquerr:EagleFactionsAPI:0.15.0'

compile 'com.mashape.unirest:unirest-java:1.4.9'
compile ('net.dv8tion:JDA:4.ALPHA.0_76') {
compile ('net.dv8tion:JDA:4.2.0_211') {
exclude module: 'opus-java'
}
compile 'com.vdurmont:emoji-java:4.0.0'
Expand Down Expand Up @@ -46,18 +46,18 @@ shadowJar {
relocate 'com.squareup', 'magibridge.com.squareup'
relocate 'okio', 'magibridge.okio'
relocate 'okhttp3', 'magibridge.okhttp3'
relocate 'net.dv8tion', 'magibridge.net.dv8tion'

relocate 'com.fasterxml.jackson', 'magibridge.com.fasterxml.jackson'
dependencies {
exclude(dependency('org.slf4j:slf4j-api'))
exclude(dependency('net.java.dev.jna:jna'))
}
exclude('module-info.class')
baseName = 'MagiBridge-API7'
classifier = null
}

compileJava {
excludes = ['**/module-info.java', '**/module-info.class']
}

build.dependsOn shadowJar

sponge.plugin.id = pluginId
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pluginGroup=com.magitechserver.magibridge
pluginId=magibridge
pluginVersion=2.11
pluginVersion=2.11.1
39 changes: 28 additions & 11 deletions src/main/java/com/magitechserver/magibridge/MagiBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger;
Expand All @@ -42,7 +43,6 @@
import javax.security.auth.login.LoginException;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -180,23 +180,40 @@ CompletableFuture<Void> init() {
// needed because of parsing issues
Utils.turnAllConfigChannelsNumeric();

boolean throwException = false;
try {
jda = new JDABuilder(config.CORE.BOT_TOKEN)
.setDisabledCacheFlags(EnumSet.of(
CacheFlag.VOICE_STATE,
CacheFlag.CLIENT_STATUS)
jda = JDABuilder.create(
config.CORE.BOT_TOKEN,
GatewayIntent.GUILD_MEMBERS,
GatewayIntent.GUILD_EMOJIS,
GatewayIntent.GUILD_MESSAGES,
GatewayIntent.DIRECT_MESSAGES
)
.disableCache(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE, CacheFlag.CLIENT_STATUS)
.build()
.awaitReady();
jda.addEventListener(new MessageListener());
} catch (LoginException e) {
String exception =
"ERROR STARTING THE PLUGIN: \n" +
"THE TOKEN IN THE CONFIG IS INVALID! \n" +
"You probably didn't set the token yet, edit your config!";
throw new RuntimeException(exception);
throwException = true;
logger.error("ERROR STARTING THE PLUGIN: THE TOKEN IN THE CONFIG IS INVALID!");
logger.error("You probably didn't set the token yet, edit your config!");
} catch (IllegalStateException e) {
throwException = true;
if (e.getMessage().contains("Was shutdown trying to await status")) {
logger.error("JDA couldn't start and didn't throw any errors. Make sure your bot " +
"has the SERVER MEMBERS INTENT enabled in the application page! See https://github.com/Eufranio/MagiBridge#how-to-magibridge");
} else {
logger.error("Error connecting to discord. This is NOT a plugin error: " + e.getMessage());
}
} catch (Exception e) {
throw new RuntimeException("Error connecting to discord. This is NOT a plugin error: ", e);
throwException = true;
logger.error("Error connecting to discord. This is NOT a plugin error: " + e.getMessage());
}

if (throwException) {
RuntimeException exception = new RuntimeException("MagiBridge errored and could not start, check the logs for the error!");
exception.setStackTrace(new StackTraceElement[0]);
throw exception;
}
}, executor).thenRun(() -> {
this.registerListeners();
Expand Down

0 comments on commit 6ec024d

Please sign in to comment.