|
|
|
@@ -15,6 +15,7 @@
|
|
|
|
|
*/
|
|
|
|
|
package com.jagrosh.jmusicbot;
|
|
|
|
|
|
|
|
|
|
import com.jagrosh.jdautilities.command.CommandClient;
|
|
|
|
|
import com.jagrosh.jdautilities.command.CommandClientBuilder;
|
|
|
|
|
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
|
|
|
|
|
import com.jagrosh.jdautilities.examples.command.*;
|
|
|
|
@@ -86,7 +87,85 @@ public class JMusicBot
|
|
|
|
|
EventWaiter waiter = new EventWaiter();
|
|
|
|
|
SettingsManager settings = new SettingsManager();
|
|
|
|
|
Bot bot = new Bot(waiter, config, settings);
|
|
|
|
|
CommandClient client = createCommandClient(config, settings, bot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!prompt.isNoGUI())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
GUI gui = new GUI(bot);
|
|
|
|
|
bot.setGUI(gui);
|
|
|
|
|
gui.init();
|
|
|
|
|
|
|
|
|
|
LOG.info("Loaded config from " + config.getConfigLocation());
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
LOG.error("Could not start GUI. If you are "
|
|
|
|
|
+ "running on a server or in a location where you cannot display a "
|
|
|
|
|
+ "window, please run in nogui mode using the -Dnogui=true flag.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// attempt to log in and start
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS))
|
|
|
|
|
.enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE)
|
|
|
|
|
.disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE, CacheFlag.ONLINE_STATUS)
|
|
|
|
|
.setActivity(config.isGameNone() ? null : Activity.playing("loading..."))
|
|
|
|
|
.setStatus(config.getStatus()==OnlineStatus.INVISIBLE || config.getStatus()==OnlineStatus.OFFLINE
|
|
|
|
|
? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB)
|
|
|
|
|
.addEventListeners(client, waiter, new Listener(bot))
|
|
|
|
|
.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)
|
|
|
|
|
{
|
|
|
|
|
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nPlease make sure you are "
|
|
|
|
|
+ "editing the correct config.txt file, and that you have used the "
|
|
|
|
|
+ "correct token (not the 'secret'!)\nConfig Location: " + config.getConfigLocation());
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
catch(IllegalArgumentException ex)
|
|
|
|
|
{
|
|
|
|
|
prompt.alert(Prompt.Level.ERROR, "JMusicBot", "Some aspect of the configuration is "
|
|
|
|
|
+ "invalid: " + ex + "\nConfig Location: " + config.getConfigLocation());
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
catch(ErrorResponseException ex)
|
|
|
|
|
{
|
|
|
|
|
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nInvalid reponse returned when "
|
|
|
|
|
+ "attempting to connect, please make sure you're connected to the internet");
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static CommandClient createCommandClient(BotConfig config, SettingsManager settings, Bot bot)
|
|
|
|
|
{
|
|
|
|
|
// instantiate about command
|
|
|
|
|
AboutCommand aboutCommand = new AboutCommand(Color.BLUE.brighter(),
|
|
|
|
|
"a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v" + OtherUtil.getCurrentVersion() + ")",
|
|
|
|
|
new String[]{"High-quality music playback", "FairQueue™ Technology", "Easy to host yourself"},
|
|
|
|
@@ -144,91 +223,23 @@ public class JMusicBot
|
|
|
|
|
new SetstatusCmd(bot),
|
|
|
|
|
new ShutdownCmd(bot)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// enable eval if applicable
|
|
|
|
|
if(config.useEval())
|
|
|
|
|
cb.addCommand(new EvalCmd(bot));
|
|
|
|
|
boolean nogame = false;
|
|
|
|
|
if(config.getStatus()!=OnlineStatus.UNKNOWN)
|
|
|
|
|
|
|
|
|
|
// set status if set in config
|
|
|
|
|
if(config.getStatus() != OnlineStatus.UNKNOWN)
|
|
|
|
|
cb.setStatus(config.getStatus());
|
|
|
|
|
if(config.getGame()==null)
|
|
|
|
|
|
|
|
|
|
// set game
|
|
|
|
|
if(config.getGame() == null)
|
|
|
|
|
cb.useDefaultGame();
|
|
|
|
|
else if(config.getGame().getName().equalsIgnoreCase("none"))
|
|
|
|
|
{
|
|
|
|
|
else if(config.isGameNone())
|
|
|
|
|
cb.setActivity(null);
|
|
|
|
|
nogame = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cb.setActivity(config.getGame());
|
|
|
|
|
|
|
|
|
|
if(!prompt.isNoGUI())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
GUI gui = new GUI(bot);
|
|
|
|
|
bot.setGUI(gui);
|
|
|
|
|
gui.init();
|
|
|
|
|
|
|
|
|
|
LOG.info("Loaded config from " + config.getConfigLocation());
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
LOG.error("Could not start GUI. If you are "
|
|
|
|
|
+ "running on a server or in a location where you cannot display a "
|
|
|
|
|
+ "window, please run in nogui mode using the -Dnogui=true flag.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// attempt to log in and start
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS))
|
|
|
|
|
.enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE)
|
|
|
|
|
.disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE, CacheFlag.ONLINE_STATUS)
|
|
|
|
|
.setActivity(nogame ? null : Activity.playing("loading..."))
|
|
|
|
|
.setStatus(config.getStatus()==OnlineStatus.INVISIBLE || config.getStatus()==OnlineStatus.OFFLINE
|
|
|
|
|
? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB)
|
|
|
|
|
.addEventListeners(cb.build(), waiter, new Listener(bot))
|
|
|
|
|
.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)
|
|
|
|
|
{
|
|
|
|
|
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nPlease make sure you are "
|
|
|
|
|
+ "editing the correct config.txt file, and that you have used the "
|
|
|
|
|
+ "correct token (not the 'secret'!)\nConfig Location: " + config.getConfigLocation());
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
catch(IllegalArgumentException ex)
|
|
|
|
|
{
|
|
|
|
|
prompt.alert(Prompt.Level.ERROR, "JMusicBot", "Some aspect of the configuration is "
|
|
|
|
|
+ "invalid: " + ex + "\nConfig Location: " + config.getConfigLocation());
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
catch(ErrorResponseException ex)
|
|
|
|
|
{
|
|
|
|
|
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nInvalid reponse returned when "
|
|
|
|
|
+ "attempting to connect, please make sure you're connected to the internet");
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
return cb.build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|