Skip to content

Commit

Permalink
Make JMusicBot error & shut down if ran in an unsupported manner (#1486)
Browse files Browse the repository at this point in the history
* Make JMusicBot error & shut down if ran in an unsupported manner

* add info about message content intent

* five second rule

---------

Co-authored-by: unknown <john.a.grosh@gmail.com>
  • Loading branch information
MichailiK and jagrosh committed Mar 2, 2024
1 parent 18bf6ac commit 23c2dfa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ else if(config.getGame().getName().equalsIgnoreCase("none"))
.setBulkDeleteSplittingEnabled(true)
.build();
bot.setJDA(jda);

// check if something about the current startup is not supported
String unsupportedReason = OtherUtil.getUnsupportedBotReason(jda);
if (unsupportedReason != null)
{
prompt.alert(Prompt.Level.ERROR, "JMusicBot", "JMusicBot cannot be run on this Discord bot: " + unsupportedReason);
try{ Thread.sleep(5000);}catch(InterruptedException ignored){} // this is awful but until we have a better way...
jda.shutdown();
System.exit(1);
}

// other check that will just be a warning now but may be required in the future
// check if the user has changed the prefix and provide info about the
// message content intent
if(!"@mention".equals(config.getPrefix()))
{
prompt.alert(Prompt.Level.INFO, "JMusicBot", "You currently have a custom prefix set. "
+ "If your prefix is not working, make sure that the 'MESSAGE CONTENT INTENT' is Enabled "
+ "on https://discord.com/developers/applications/" + jda.getSelfUser().getId() + "/bot");
}
}
catch (LoginException ex)
{
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/utils/OtherUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
import java.net.URLConnection;
import java.nio.file.Path;
import java.nio.file.Paths;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.ApplicationInfo;
import net.dv8tion.jda.api.entities.User;
import okhttp3.*;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -207,4 +211,20 @@ public static String getLatestVersion()
return null;
}
}

/**
* Checks if the bot JMusicBot is being run on is supported & returns the reason if it is not.
* @return A string with the reason, or null if it is supported.
*/
public static String getUnsupportedBotReason(JDA jda)
{

This comment has been minimized.

Copy link
@Speak2Erase

Speak2Erase Mar 15, 2024

Why was this change made?

I want to give the benefit of the doubt and assume this is because of some API change, but I've seen this practice done enough times before to rightly assume that this is intentionally limited just to make a paywalled version without the limit.

Seeing as #1486 is now locked for being "too heated" after 3 comments, it looks like this is the direction @jagrosh wants to take this repository. Don't get me wrong, I'm not against paywalling like this if it is done with 100% transparency (which this is not, there are no mentions of this in the changelog).

The least malicious way to go about this is to be transparent about limits (like this one) and enabling limited features only in "free" builds, but not when compiling from source. (This is how aseprite makes money, sort of. The hassle of not having to build it every update is what you pay for, as well as some additional creature comforts. You'd be surprised how many people would pay for that!)

I'm really, really, really hoping this is not something malicious, and this is something that is related to the new way bots work on discord. I don't make discord bots!!! Please prove me wrong!!

This comment has been minimized.

Copy link
@jagrosh

jagrosh Mar 15, 2024

Author Owner

There are no plans to paywall JMusicBot at any point, nor release any supported builds other than the official builds on the releases page.

JMusicBot documentation has always instructed users to mark their bots as private. This update is the first update that actually enforces the instructions. The people complaining about this change are likely the vocal minority.

  • JMusicBot's internals are not optimized for running publicly; there are many design patterns within the code that are designed for ease-of-use or ease-of-maintenance that do not scale well to large numbers of servers.
  • The support server frequently has cases of users asking how to remove their bot from someone's server, and the root issue in most of these cases is that they didn't realize that their bot could be added by anyone.
  • (Hopefully this is not as much of an issue as it has been in the past) People have attempted to pass JMusicBot off as their own bot; some have even attempted to get their bot verified (running a bot that they potentially had zero idea how the internals worked).
  • This change does not prevent the bot owner from adding it to servers.
  • This check only occurs at startup; it is still possible to temporarily make it public if the bot owner isn't able to add it to a server that someone else would be able to.
if (jda.getSelfUser().getFlags().contains(User.UserFlag.VERIFIED_BOT))
return "The bot is verified. Using JMusicBot in a verified bot is not supported.";

ApplicationInfo info = jda.retrieveApplicationInfo().complete();
if (info.isBotPublic())
return "\"Public Bot\" is enabled. Using JMusicBot as a public bot is not supported. Please disable it in the Developer Dashboard.";

return null;
}
}

0 comments on commit 23c2dfa

Please sign in to comment.