Initial commit

This commit is contained in:
elijahtaylorr
2026-03-05 00:54:11 +08:00
parent 859e5c5862
commit 136e9ed0bc
16 changed files with 171 additions and 137 deletions

62
pom.xml
View File

@@ -8,9 +8,9 @@
<repositories> <repositories>
<repository> <repository>
<id>dv8tion</id> <id>chew</id>
<name>m2-dv8tion</name> <name>m2-chew</name>
<url>https://m2.dv8tion.net/releases</url> <url>https://m2.chew.pro/releases</url>
</repository> </repository>
<repository> <repository>
<id>central</id> <id>central</id>
@@ -42,25 +42,63 @@
<dependency> <dependency>
<groupId>net.dv8tion</groupId> <groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId> <artifactId>JDA</artifactId>
<version>4.4.1_353</version> <version>6.3.1</version>
</dependency>
<dependency>
<groupId>club.minnced</groupId>
<artifactId>jdave-api</artifactId>
<version>0.1.7</version>
</dependency>
<dependency>
<groupId>club.minnced</groupId>
<artifactId>jdave-native-linux-x86-64</artifactId>
<version>0.1.7</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.jagrosh</groupId> <groupId>club.minnced</groupId>
<artifactId>jda-utilities</artifactId> <artifactId>jdave-native-linux-aarch64</artifactId>
<version>3.0.5</version> <version>0.1.7</version>
</dependency>
<dependency>
<groupId>club.minnced</groupId>
<artifactId>jdave-native-win-x86-64</artifactId>
<version>0.1.7</version>
</dependency>
<dependency>
<groupId>club.minnced</groupId>
<artifactId>jdave-native-darwin</artifactId>
<version>0.1.7</version>
</dependency>
<dependency>
<groupId>pw.chew</groupId>
<artifactId>jda-chewtils</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
<dependency>
<groupId>pw.chew</groupId>
<artifactId>jda-chewtils-command</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>pw.chew</groupId>
<artifactId>jda-chewtils-examples</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
<!-- Music Dependencies --> <!-- Music Dependencies -->
<dependency> <dependency>
<groupId>dev.arbjerg</groupId> <groupId>dev.arbjerg</groupId>
<artifactId>lavaplayer</artifactId> <artifactId>lavaplayer</artifactId>
<version>2.2.1</version> <version>2.2.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>dev.lavalink.youtube</groupId> <groupId>dev.lavalink.youtube</groupId>
<artifactId>common</artifactId> <artifactId>common</artifactId>
<version>1.5.2</version> <version>1.13.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.jagrosh</groupId> <groupId>com.github.jagrosh</groupId>
@@ -77,7 +115,7 @@
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>1.2.13</version> <version>1.5.18</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.typesafe</groupId> <groupId>com.typesafe</groupId>
@@ -149,7 +187,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>25</maven.compiler.target>
</properties> </properties>
</project> </project>

View File

@@ -27,6 +27,7 @@ import com.jagrosh.jmusicbot.playlist.PlaylistLoader;
import com.jagrosh.jmusicbot.settings.SettingsManager; import com.jagrosh.jmusicbot.settings.SettingsManager;
import java.util.Objects; import java.util.Objects;
import net.dv8tion.jda.api.JDA; 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.Activity;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
@@ -121,6 +122,9 @@ public class Bot
Activity game = config.getGame()==null || config.getGame().getName().equalsIgnoreCase("none") ? null : config.getGame(); Activity game = config.getGame()==null || config.getGame().getName().equalsIgnoreCase("none") ? null : config.getGame();
if(!Objects.equals(jda.getPresence().getActivity(), game)) if(!Objects.equals(jda.getPresence().getActivity(), game))
jda.getPresence().setActivity(game); jda.getPresence().setActivity(game);
OnlineStatus status = config.getStatus();
if(status != OnlineStatus.UNKNOWN && jda.getPresence().getStatus() != status)
jda.getPresence().setStatus(status);
} }
public void shutdown() public void shutdown()

View File

@@ -30,8 +30,8 @@ import com.jagrosh.jmusicbot.settings.SettingsManager;
import com.jagrosh.jmusicbot.utils.OtherUtil; import com.jagrosh.jmusicbot.utils.OtherUtil;
import java.awt.Color; import java.awt.Color;
import java.util.Arrays; import java.util.Arrays;
import javax.security.auth.login.LoginException;
import net.dv8tion.jda.api.*; import net.dv8tion.jda.api.*;
import net.dv8tion.jda.api.audio.AudioModuleConfig;
import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.cache.CacheFlag; import net.dv8tion.jda.api.utils.cache.CacheFlag;
@@ -39,27 +39,28 @@ import net.dv8tion.jda.api.exceptions.ErrorResponseException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Level;
import club.minnced.discord.jdave.interop.JDaveSessionFactory;
/** /**
* *
* @author John Grosh (jagrosh) * @author John Grosh (jagrosh)
*/ */
public class JMusicBot public class JMusicBot {
{
public final static Logger LOG = LoggerFactory.getLogger(JMusicBot.class); public final static Logger LOG = LoggerFactory.getLogger(JMusicBot.class);
public final static Permission[] RECOMMENDED_PERMS = {Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION, public final static Permission[] RECOMMENDED_PERMS = { Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND,
Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_MANAGE, Permission.MESSAGE_EXT_EMOJI, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION,
Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.NICKNAME_CHANGE}; Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_MANAGE,
public final static GatewayIntent[] INTENTS = {GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES}; Permission.MESSAGE_EXT_EMOJI,
Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.NICKNAME_CHANGE };
public final static GatewayIntent[] INTENTS = { GatewayIntent.MESSAGE_CONTENT, GatewayIntent.DIRECT_MESSAGES,
GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES };
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) public static void main(String[] args) {
{ if (args.length > 0)
if(args.length > 0) switch (args[0].toLowerCase()) {
switch(args[0].toLowerCase())
{
case "generate-config": case "generate-config":
BotConfig.writeDefaultConfig(); BotConfig.writeDefaultConfig();
return; return;
@@ -67,117 +68,106 @@ public class JMusicBot
} }
startBot(); startBot();
} }
private static void startBot() private static void startBot() {
{
// create prompt to handle startup // create prompt to handle startup
Prompt prompt = new Prompt("JMusicBot"); Prompt prompt = new Prompt("JMusicBot");
// startup checks // startup checks
OtherUtil.checkVersion(prompt); OtherUtil.checkVersion(prompt);
OtherUtil.checkJavaVersion(prompt); OtherUtil.checkJavaVersion(prompt);
// load config // load config
BotConfig config = new BotConfig(prompt); BotConfig config = new BotConfig(prompt);
config.load(); config.load();
if(!config.isValid()) if (!config.isValid())
return; return;
LOG.info("Loaded config from " + config.getConfigLocation()); LOG.info("Loaded config from " + config.getConfigLocation());
// set log level from config // set log level from config
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel( ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel(
Level.toLevel(config.getLogLevel(), Level.INFO)); Level.toLevel(config.getLogLevel(), Level.INFO));
// set up the listener // set up the listener
EventWaiter waiter = new EventWaiter(); EventWaiter waiter = new EventWaiter();
SettingsManager settings = new SettingsManager(); SettingsManager settings = new SettingsManager();
Bot bot = new Bot(waiter, config, settings); Bot bot = new Bot(waiter, config, settings);
CommandClient client = createCommandClient(config, settings, bot); CommandClient client = createCommandClient(config, settings, bot);
if (!prompt.isNoGUI()) {
if(!prompt.isNoGUI()) try {
{
try
{
GUI gui = new GUI(bot); GUI gui = new GUI(bot);
bot.setGUI(gui); bot.setGUI(gui);
gui.init(); gui.init();
LOG.info("Loaded config from " + config.getConfigLocation()); LOG.info("Loaded config from " + config.getConfigLocation());
} } catch (Exception e) {
catch(Exception e)
{
LOG.error("Could not start GUI. If you are " LOG.error("Could not start GUI. If you are "
+ "running on a server or in a location where you cannot display a " + "running on a server or in a location where you cannot display a "
+ "window, please run in nogui mode using the -Dnogui=true flag."); + "window, please run in nogui mode using the -Dnogui=true flag.");
} }
} }
// attempt to log in and start // attempt to log in and start
try try {
{
JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS)) JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS))
.enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE) .enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE)
.disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE, CacheFlag.ONLINE_STATUS) .disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOJI, CacheFlag.ONLINE_STATUS,
CacheFlag.STICKER, CacheFlag.SCHEDULED_EVENTS)
.setActivity(config.isGameNone() ? null : Activity.playing("loading...")) .setActivity(config.isGameNone() ? null : Activity.playing("loading..."))
.setStatus(config.getStatus()==OnlineStatus.INVISIBLE || config.getStatus()==OnlineStatus.OFFLINE .setStatus(
? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB) config.getStatus() == OnlineStatus.INVISIBLE || config.getStatus() == OnlineStatus.OFFLINE
? OnlineStatus.INVISIBLE
: OnlineStatus.DO_NOT_DISTURB)
.addEventListeners(client, waiter, new Listener(bot)) .addEventListeners(client, waiter, new Listener(bot))
.setBulkDeleteSplittingEnabled(true) .setBulkDeleteSplittingEnabled(true)
.setAudioModuleConfig(new AudioModuleConfig()
.withDaveSessionFactory(new JDaveSessionFactory()))
.build(); .build();
bot.setJDA(jda); bot.setJDA(jda);
// check if something about the current startup is not supported // check if something about the current startup is not supported
String unsupportedReason = OtherUtil.getUnsupportedBotReason(jda); String unsupportedReason = OtherUtil.getUnsupportedBotReason(jda);
if (unsupportedReason != null) if (unsupportedReason != null) {
{ prompt.alert(Prompt.Level.ERROR, "JMusicBot",
prompt.alert(Prompt.Level.ERROR, "JMusicBot", "JMusicBot cannot be run on this Discord bot: " + unsupportedReason); "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... try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {
} // this is awful but until we have a better way...
jda.shutdown(); jda.shutdown();
System.exit(1); System.exit(1);
} }
// other check that will just be a warning now but may be required in the future // 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 // check if the user has changed the prefix and provide info about the
// message content intent // message content intent
if(!"@mention".equals(config.getPrefix())) if (!"@mention".equals(config.getPrefix())) {
{
LOG.info("JMusicBot", "You currently have a custom prefix set. " LOG.info("JMusicBot", "You currently have a custom prefix set. "
+ "If your prefix is not working, make sure that the 'MESSAGE CONTENT INTENT' is Enabled " + "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"); + "on https://discord.com/developers/applications/" + jda.getSelfUser().getId() + "/bot");
} }
} } catch (IllegalArgumentException ex) {
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 " prompt.alert(Prompt.Level.ERROR, "JMusicBot", "Some aspect of the configuration is "
+ "invalid: " + ex + "\nConfig Location: " + config.getConfigLocation()); + "invalid: " + ex + "\nConfig Location: " + config.getConfigLocation());
System.exit(1); System.exit(1);
} } catch (ErrorResponseException ex) {
catch(ErrorResponseException ex)
{
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nInvalid reponse returned when " prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nInvalid reponse returned when "
+ "attempting to connect, please make sure you're connected to the internet"); + "attempting to connect, please make sure you're connected to the internet");
System.exit(1); System.exit(1);
} }
} }
private static CommandClient createCommandClient(BotConfig config, SettingsManager settings, Bot bot) private static CommandClient createCommandClient(BotConfig config, SettingsManager settings, Bot bot) {
{
// instantiate about command // instantiate about command
AboutCommand aboutCommand = new AboutCommand(Color.BLUE.brighter(), AboutCommand aboutCommand = new AboutCommand(Color.BLUE.brighter(),
"a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v" + OtherUtil.getCurrentVersion() + ")", "a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v"
new String[]{"High-quality music playback", "FairQueue™ Technology", "Easy to host yourself"}, + OtherUtil.getCurrentVersion() + ")",
RECOMMENDED_PERMS); new String[] { "High-quality music playback", "FairQueue™ Technology", "Easy to host yourself" },
RECOMMENDED_PERMS);
aboutCommand.setIsAuthor(false); aboutCommand.setIsAuthor(false);
aboutCommand.setReplacementCharacter("\uD83C\uDFB6"); // 🎶 aboutCommand.setReplacementCharacter("\uD83C\uDFB6"); // 🎶
// set up the command client // set up the command client
CommandClientBuilder cb = new CommandClientBuilder() CommandClientBuilder cb = new CommandClientBuilder()
.setPrefix(config.getPrefix()) .setPrefix(config.getPrefix())
@@ -190,7 +180,7 @@ public class JMusicBot
.addCommands(aboutCommand, .addCommands(aboutCommand,
new PingCommand(), new PingCommand(),
new SettingsCmd(bot), new SettingsCmd(bot),
new LyricsCmd(bot), new LyricsCmd(bot),
new NowplayingCmd(bot), new NowplayingCmd(bot),
new PlayCmd(bot), new PlayCmd(bot),
@@ -212,7 +202,7 @@ public class JMusicBot
new SkiptoCmd(bot), new SkiptoCmd(bot),
new StopCmd(bot), new StopCmd(bot),
new VolumeCmd(bot), new VolumeCmd(bot),
new PrefixCmd(bot), new PrefixCmd(bot),
new QueueTypeCmd(bot), new QueueTypeCmd(bot),
new SetdjCmd(bot), new SetdjCmd(bot),
@@ -227,25 +217,24 @@ public class JMusicBot
new SetgameCmd(bot), new SetgameCmd(bot),
new SetnameCmd(bot), new SetnameCmd(bot),
new SetstatusCmd(bot), new SetstatusCmd(bot),
new ShutdownCmd(bot) new ShutdownCmd(bot));
);
// enable eval if applicable // enable eval if applicable
if(config.useEval()) if (config.useEval())
cb.addCommand(new EvalCmd(bot)); cb.addCommand(new EvalCmd(bot));
// set status if set in config // set status if set in config
if(config.getStatus() != OnlineStatus.UNKNOWN) if (config.getStatus() != OnlineStatus.UNKNOWN)
cb.setStatus(config.getStatus()); cb.setStatus(config.getStatus());
// set game // set game
if(config.getGame() == null) if (config.getGame() == null)
cb.useDefaultGame(); cb.useDefaultGame();
else if(config.isGameNone()) else if (config.isGameNone())
cb.setActivity(null); cb.setActivity(null);
else else
cb.setActivity(config.getGame()); cb.setActivity(config.getGame());
return cb.build(); return cb.build();
} }
} }

View File

@@ -20,12 +20,12 @@ import java.util.concurrent.TimeUnit;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.ShutdownEvent;
import net.dv8tion.jda.api.events.guild.GuildJoinEvent; import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
import net.dv8tion.jda.api.events.session.ReadyEvent;
import net.dv8tion.jda.api.events.session.ShutdownEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -85,10 +85,11 @@ public class Listener extends ListenerAdapter
catch(Exception ignored) {} // ignored catch(Exception ignored) {} // ignored
}, 0, 24, TimeUnit.HOURS); }, 0, 24, TimeUnit.HOURS);
} }
bot.resetGame();
} }
@Override @Override
public void onGuildMessageDelete(GuildMessageDeleteEvent event) public void onMessageDelete(MessageDeleteEvent event)
{ {
bot.getNowplayingHandler().onMessageDelete(event.getGuild(), event.getMessageIdLong()); bot.getNowplayingHandler().onMessageDelete(event.getGuild(), event.getMessageIdLong());
} }

View File

@@ -36,11 +36,11 @@ import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.audio.AudioSendHandler; import net.dv8tion.jda.api.audio.AudioSendHandler;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
@@ -118,7 +118,7 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
public boolean isMusicPlaying(JDA jda) public boolean isMusicPlaying(JDA jda)
{ {
return guild(jda).getSelfMember().getVoiceState().inVoiceChannel() && audioPlayer.getPlayingTrack()!=null; return guild(jda).getSelfMember().getVoiceState().inAudioChannel() && audioPlayer.getPlayingTrack()!=null;
} }
public Set<String> getVotes() public Set<String> getVotes()
@@ -215,14 +215,14 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
// Formatting // Formatting
public Message getNowPlaying(JDA jda) public MessageCreateData getNowPlaying(JDA jda)
{ {
if(isMusicPlaying(jda)) if(isMusicPlaying(jda))
{ {
Guild guild = guild(jda); Guild guild = guild(jda);
AudioTrack track = audioPlayer.getPlayingTrack(); AudioTrack track = audioPlayer.getPlayingTrack();
MessageBuilder mb = new MessageBuilder(); MessageCreateBuilder mb = new MessageCreateBuilder();
mb.append(FormatUtil.filter(manager.getBot().getConfig().getSuccess()+" **Now Playing in "+guild.getSelfMember().getVoiceState().getChannel().getAsMention()+"...**")); mb.setContent(FormatUtil.filter(manager.getBot().getConfig().getSuccess()+" **Now Playing in "+guild.getSelfMember().getVoiceState().getChannel().getAsMention()+"...**"));
EmbedBuilder eb = new EmbedBuilder(); EmbedBuilder eb = new EmbedBuilder();
eb.setColor(guild.getSelfMember().getColor()); eb.setColor(guild.getSelfMember().getColor());
RequestMetadata rm = getRequestMetadata(); RequestMetadata rm = getRequestMetadata();
@@ -263,10 +263,10 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
else return null; else return null;
} }
public Message getNoMusicPlaying(JDA jda) public MessageCreateData getNoMusicPlaying(JDA jda)
{ {
Guild guild = guild(jda); Guild guild = guild(jda);
return new MessageBuilder() return new MessageCreateBuilder()
.setContent(FormatUtil.filter(manager.getBot().getConfig().getSuccess()+" **Now Playing...**")) .setContent(FormatUtil.filter(manager.getBot().getConfig().getSuccess()+" **Now Playing...**"))
.setEmbeds(new EmbedBuilder() .setEmbeds(new EmbedBuilder()
.setTitle("No music playing") .setTitle("No music playing")

View File

@@ -27,9 +27,9 @@ import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.exceptions.PermissionException; import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import net.dv8tion.jda.api.exceptions.RateLimitedException; import net.dv8tion.jda.api.utils.messages.MessageEditData;
/** /**
* *
@@ -54,7 +54,7 @@ public class NowplayingHandler
public void setLastNPMessage(Message m) public void setLastNPMessage(Message m)
{ {
lastNP.put(m.getGuild().getIdLong(), new Pair<>(m.getTextChannel().getIdLong(), m.getIdLong())); lastNP.put(m.getGuild().getIdLong(), new Pair<>(m.getChannelIdLong(), m.getIdLong()));
} }
public void clearLastNPMessage(Guild guild) public void clearLastNPMessage(Guild guild)
@@ -81,7 +81,7 @@ public class NowplayingHandler
continue; continue;
} }
AudioHandler handler = (AudioHandler)guild.getAudioManager().getSendingHandler(); AudioHandler handler = (AudioHandler)guild.getAudioManager().getSendingHandler();
Message msg = handler.getNowPlaying(bot.getJDA()); MessageCreateData msg = handler.getNowPlaying(bot.getJDA());
if(msg==null) if(msg==null)
{ {
msg = handler.getNoMusicPlaying(bot.getJDA()); msg = handler.getNoMusicPlaying(bot.getJDA());
@@ -89,7 +89,7 @@ public class NowplayingHandler
} }
try try
{ {
tc.editMessageById(pair.getValue(), msg).queue(m->{}, t -> lastNP.remove(guildId)); tc.editMessageById(pair.getValue(), MessageEditData.fromCreateData(msg)).queue(m->{}, t -> lastNP.remove(guildId));
} }
catch(Exception e) catch(Exception e)
{ {
@@ -105,7 +105,7 @@ public class NowplayingHandler
// update bot status if applicable // update bot status if applicable
if(bot.getConfig().getSongInStatus()) if(bot.getConfig().getSongInStatus())
{ {
if(track!=null && bot.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inVoiceChannel()).count()<=1) if(track!=null && bot.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inAudioChannel()).count()<=1)
bot.getJDA().getPresence().setActivity(Activity.listening(track.getInfo().title)); bot.getJDA().getPresence().setActivity(Activity.listening(track.getInfo().title));
else else
bot.resetGame(); bot.resetGame();

View File

@@ -21,8 +21,9 @@ import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.settings.Settings; import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.audio.AudioHandler; import com.jagrosh.jmusicbot.audio.AudioHandler;
import net.dv8tion.jda.api.entities.GuildVoiceState; import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.exceptions.PermissionException; import net.dv8tion.jda.api.exceptions.PermissionException;
/** /**
@@ -64,11 +65,11 @@ public abstract class MusicCommand extends Command
} }
if(beListening) if(beListening)
{ {
VoiceChannel current = event.getGuild().getSelfMember().getVoiceState().getChannel(); AudioChannel current = event.getGuild().getSelfMember().getVoiceState().getChannel();
if(current==null) if(current==null)
current = settings.getVoiceChannel(event.getGuild()); current = settings.getVoiceChannel(event.getGuild());
GuildVoiceState userState = event.getMember().getVoiceState(); GuildVoiceState userState = event.getMember().getVoiceState();
if(!userState.inVoiceChannel() || userState.isDeafened() || (current!=null && !userState.getChannel().equals(current))) if(!userState.inAudioChannel() || userState.isDeafened() || (current!=null && !userState.getChannel().equals(current)))
{ {
event.replyError("You must be listening in "+(current==null ? "a voice channel" : current.getAsMention())+" to use that!"); event.replyError("You must be listening in "+(current==null ? "a voice channel" : current.getAsMention())+" to use that!");
return; return;
@@ -81,7 +82,7 @@ public abstract class MusicCommand extends Command
return; return;
} }
if(!event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) if(!event.getGuild().getSelfMember().getVoiceState().inAudioChannel())
{ {
try try
{ {

View File

@@ -22,7 +22,7 @@ import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.AdminCommand; import com.jagrosh.jmusicbot.commands.AdminCommand;
import com.jagrosh.jmusicbot.settings.Settings; import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil; import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
/** /**
* *

View File

@@ -22,7 +22,7 @@ import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.AdminCommand; import com.jagrosh.jmusicbot.commands.AdminCommand;
import com.jagrosh.jmusicbot.settings.Settings; import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil; import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
/** /**
* *

View File

@@ -23,10 +23,10 @@ import com.jagrosh.jmusicbot.settings.RepeatMode;
import com.jagrosh.jmusicbot.settings.Settings; import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil; import com.jagrosh.jmusicbot.utils.FormatUtil;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
/** /**
* *
@@ -48,10 +48,10 @@ public class SettingsCmd extends Command
protected void execute(CommandEvent event) protected void execute(CommandEvent event)
{ {
Settings s = event.getClient().getSettingsFor(event.getGuild()); Settings s = event.getClient().getSettingsFor(event.getGuild());
MessageBuilder builder = new MessageBuilder() MessageCreateBuilder builder = new MessageCreateBuilder()
.append(EMOJI + " **") .addContent(EMOJI + " **")
.append(FormatUtil.filter(event.getSelfUser().getName())) .addContent(FormatUtil.filter(event.getSelfUser().getName()))
.append("** settings:"); .addContent("** settings:");
TextChannel tchan = s.getTextChannel(event.getGuild()); TextChannel tchan = s.getTextChannel(event.getGuild());
VoiceChannel vchan = s.getVoiceChannel(event.getGuild()); VoiceChannel vchan = s.getVoiceChannel(event.getGuild());
Role role = s.getRole(event.getGuild()); Role role = s.getRole(event.getGuild());
@@ -70,7 +70,7 @@ public class SettingsCmd extends Command
+ "\nDefault Playlist: " + (s.getDefaultPlaylist() == null ? "None" : "**" + s.getDefaultPlaylist() + "**") + "\nDefault Playlist: " + (s.getDefaultPlaylist() == null ? "None" : "**" + s.getDefaultPlaylist() + "**")
) )
.setFooter(event.getJDA().getGuilds().size() + " servers | " .setFooter(event.getJDA().getGuilds().size() + " servers | "
+ event.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inVoiceChannel()).count() + event.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inAudioChannel()).count()
+ " audio connections", null); + " audio connections", null);
event.getChannel().sendMessage(builder.setEmbeds(ebuilder.build()).build()).queue(); event.getChannel().sendMessage(builder.setEmbeds(ebuilder.build()).build()).queue();
} }

View File

@@ -20,7 +20,7 @@ import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler; import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.MusicCommand; import com.jagrosh.jmusicbot.commands.MusicCommand;
import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.utils.messages.MessageCreateData;
/** /**
* *
@@ -41,7 +41,7 @@ public class NowplayingCmd extends MusicCommand
public void doCommand(CommandEvent event) public void doCommand(CommandEvent event)
{ {
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
Message m = handler.getNowPlaying(event.getJDA()); MessageCreateData m = handler.getNowPlaying(event.getJDA());
if(m==null) if(m==null)
{ {
event.reply(handler.getNoMusicPlaying(event.getJDA())); event.reply(handler.getNoMusicPlaying(event.getJDA()));

View File

@@ -28,10 +28,10 @@ import com.jagrosh.jmusicbot.settings.RepeatMode;
import com.jagrosh.jmusicbot.settings.Settings; import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil; import com.jagrosh.jmusicbot.utils.FormatUtil;
import com.jagrosh.jmusicbot.utils.TimeUtil; import com.jagrosh.jmusicbot.utils.TimeUtil;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.exceptions.PermissionException; import net.dv8tion.jda.api.exceptions.PermissionException;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
/** /**
* *
@@ -75,9 +75,9 @@ public class QueueCmd extends MusicCommand
List<QueuedTrack> list = ah.getQueue().getList(); List<QueuedTrack> list = ah.getQueue().getList();
if(list.isEmpty()) if(list.isEmpty())
{ {
Message nowp = ah.getNowPlaying(event.getJDA()); MessageCreateData nowp = ah.getNowPlaying(event.getJDA());
Message nonowp = ah.getNoMusicPlaying(event.getJDA()); MessageCreateData nonowp = ah.getNoMusicPlaying(event.getJDA());
Message built = new MessageBuilder() MessageCreateData built = new MessageCreateBuilder()
.setContent(event.getClient().getWarning() + " There is no music in the queue!") .setContent(event.getClient().getWarning() + " There is no music in the queue!")
.setEmbeds((nowp==null ? nonowp : nowp).getEmbeds().get(0)).build(); .setEmbeds((nowp==null ? nonowp : nowp).getEmbeds().get(0)).build();
event.reply(built, m -> event.reply(built, m ->

View File

@@ -23,7 +23,8 @@ import com.jagrosh.jmusicbot.utils.OtherUtil;
import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary; import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary;
import net.dv8tion.jda.api.JDAInfo; import net.dv8tion.jda.api.JDAInfo;
import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.ChannelType; import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.utils.FileUpload;
/** /**
* *
@@ -80,8 +81,8 @@ public class DebugCmd extends OwnerCommand
if(event.isFromType(ChannelType.PRIVATE) if(event.isFromType(ChannelType.PRIVATE)
|| event.getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_ATTACH_FILES)) || event.getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_ATTACH_FILES))
event.getChannel().sendFile(sb.toString().getBytes(), "debug_information.txt").queue(); event.getChannel().sendFiles(FileUpload.fromData(sb.toString().getBytes(), "debug_information.txt")).queue();
else else
event.reply("Debug Information: " + sb.toString()); event.reply("Debug Information: " + sb);
} }
} }

View File

@@ -20,7 +20,7 @@ import javax.script.ScriptEngineManager;
import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot; import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.OwnerCommand; import com.jagrosh.jmusicbot.commands.OwnerCommand;
import net.dv8tion.jda.api.entities.ChannelType; import net.dv8tion.jda.api.entities.channel.ChannelType;
/** /**
* *

View File

@@ -20,8 +20,8 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
/** /**
* *

View File

@@ -18,9 +18,9 @@ package com.jagrosh.jmusicbot.utils;
import com.jagrosh.jmusicbot.audio.RequestMetadata.UserInfo; import com.jagrosh.jmusicbot.audio.RequestMetadata.UserInfo;
import java.util.List; import java.util.List;
import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
/** /**
* *