From 239d89e42adfb8e71b19cec0661429b4908183bf Mon Sep 17 00:00:00 2001 From: SebClem Date: Sat, 14 May 2022 19:26:08 +0200 Subject: [PATCH] Almost fix music --- src/main/java/net/Broken/Commands/Music.java | 182 ------------------ .../net/Broken/RestApi/CommandInterface.java | 1 - .../Broken/RestApi/Commands/AutoFlowOff.java | 1 - .../Broken/RestApi/Commands/AutoFlowOn.java | 1 - .../net/Broken/RestApi/Commands/Connect.java | 1 - .../net/Broken/RestApi/Commands/Dell.java | 2 - .../net/Broken/RestApi/Commands/Flush.java | 1 - .../net/Broken/RestApi/Commands/Next.java | 1 - .../net/Broken/RestApi/Commands/Pause.java | 1 - .../net/Broken/RestApi/Commands/Play.java | 1 - .../net/Broken/RestApi/Commands/Stop.java | 2 - src/main/java/net/Broken/SlashCommand.java | 3 + .../java/net/Broken/SlashCommands/Cat.java | 6 + .../java/net/Broken/SlashCommands/Music.java | 164 ++++++++++++++++ .../Tools/Command/SlashCommandLoader.java | 8 +- src/main/java/net/Broken/audio/AudioM.java | 71 +++---- 16 files changed, 218 insertions(+), 228 deletions(-) delete mode 100644 src/main/java/net/Broken/Commands/Music.java create mode 100644 src/main/java/net/Broken/SlashCommands/Music.java diff --git a/src/main/java/net/Broken/Commands/Music.java b/src/main/java/net/Broken/Commands/Music.java deleted file mode 100644 index 824e376..0000000 --- a/src/main/java/net/Broken/Commands/Music.java +++ /dev/null @@ -1,182 +0,0 @@ -package net.Broken.Commands; - -import net.Broken.Commande; -import net.Broken.MainBot; -import net.Broken.Tools.EmbedMessageUtils; -import net.Broken.Tools.MessageTimeOut; -import net.Broken.audio.AudioM; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.VoiceChannel; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - - -import java.util.ArrayList; -import java.util.List; - -/** - * Music commands - */ - -public class Music implements Commande { - private Logger logger = LogManager.getLogger(); - - - @Override - public void action(String[] args, MessageReceivedEvent event) { - AudioM audio = AudioM.getInstance(event.getGuild()); - if(args.length >= 1){ - switch (args[0]){ - case "play": - event.getTextChannel().sendTyping().queue(); - - if(args.length>=2){ - if(event.getMember().getVoiceState().inVoiceChannel()){ - - VoiceChannel voiceChanel = event.getMember().getVoiceState().getChannel(); - logger.info("Connecting to "+voiceChanel.getName()+"..."); - if(args.length ==2){ - audio.loadAndPlay(event,voiceChanel,args[1],30,false); - } - else if(args.length == 3){ - try{ - int limit = Integer.parseInt(args[2]); - audio.loadAndPlay(event,voiceChanel,args[1],limit,false); - }catch (NumberFormatException e){ - audio.loadAndPlay(event,voiceChanel,args[1],30,false); - } - } - } - else{ - Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("You are not in a voice channel !")).complete(); - List messages = new ArrayList(){{ - add(message); - add(event.getMessage()); - }}; - new MessageTimeOut(messages, MainBot.messageTimeOut).start(); - } - } - else{ - Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Missing argument!")).complete(); - List messages = new ArrayList(){{ - add(message); - add(event.getMessage()); - }}; - new MessageTimeOut(messages, MainBot.messageTimeOut).start(); - } - - break; - case "pause": - audio.pause(event); - break; - case "resume": - audio.resume(event); - break; - case "next": - audio.skipTrack(event); - break; - case "stop": - audio.stop(event); - break; - case "info": - audio.info(event); - break; - case "flush": - audio.flush(event); - break; - case "list": - audio.list(event); - break; - case "add": - event.getTextChannel().sendTyping().queue(); - if(args.length ==2){ - audio.add(event,args[1],30,false); - } - else if(args.length == 3){ - try{ - int limit = Integer.parseInt(args[2]); - audio.add(event,args[1],limit,false); - }catch (NumberFormatException e){ - audio.add(event,args[1],30,false); - } - } - else{ - Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Missing argument!")).complete(); - List messages = new ArrayList(){{ - add(message); - add(event.getMessage()); - }}; - new MessageTimeOut(messages, MainBot.messageTimeOut).start(); - } - break; - - case "addNext": - event.getTextChannel().sendTyping().queue(); - if(args.length >=2){ - audio.add(event,args[1],1,true); - } - else{ - Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Missing argument!")).complete(); - List messages = new ArrayList(){{ - add(message); - add(event.getMessage()); - }}; - new MessageTimeOut(messages, MainBot.messageTimeOut).start(); - } - break; - - case "disconnect": - audio.stop(); - List messages = new ArrayList(){{ - add(event.getMessage()); - }}; - new MessageTimeOut(messages, 0).start(); - break; - - default: - Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Unknown argument!")).complete(); - List messagess = new ArrayList(){{ - add(message); - add(event.getMessage()); - }}; - new MessageTimeOut(messagess, MainBot.messageTimeOut).start(); - break; - - } - } - else{ - Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Missing argument!")).complete(); - List messages = new ArrayList(){{ - add(message); - add(event.getMessage()); - }}; - new MessageTimeOut(messages, MainBot.messageTimeOut).start(); - } - } - - @Override - public boolean isPrivateUsable() { - return false; - } - - @Override - public boolean isAdminCmd() { - return false; - } - - /** - * Determines if the command is usable only by bot level admin user - * - * @return boolean - */ - @Override - public boolean isBotAdminCmd() { - return false; - } - - @Override - public boolean isNSFW() { - return false; - } -} diff --git a/src/main/java/net/Broken/RestApi/CommandInterface.java b/src/main/java/net/Broken/RestApi/CommandInterface.java index 53a5e24..ef6b5d2 100644 --- a/src/main/java/net/Broken/RestApi/CommandInterface.java +++ b/src/main/java/net/Broken/RestApi/CommandInterface.java @@ -1,6 +1,5 @@ package net.Broken.RestApi; -import net.Broken.Commands.Music; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; import net.dv8tion.jda.api.entities.Guild; diff --git a/src/main/java/net/Broken/RestApi/Commands/AutoFlowOff.java b/src/main/java/net/Broken/RestApi/Commands/AutoFlowOff.java index 843efc7..c33160a 100644 --- a/src/main/java/net/Broken/RestApi/Commands/AutoFlowOff.java +++ b/src/main/java/net/Broken/RestApi/Commands/AutoFlowOff.java @@ -1,6 +1,5 @@ package net.Broken.RestApi.Commands; -import net.Broken.Commands.Music; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; diff --git a/src/main/java/net/Broken/RestApi/Commands/AutoFlowOn.java b/src/main/java/net/Broken/RestApi/Commands/AutoFlowOn.java index a13f081..52b21d8 100644 --- a/src/main/java/net/Broken/RestApi/Commands/AutoFlowOn.java +++ b/src/main/java/net/Broken/RestApi/Commands/AutoFlowOn.java @@ -1,6 +1,5 @@ package net.Broken.RestApi.Commands; -import net.Broken.Commands.Music; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; diff --git a/src/main/java/net/Broken/RestApi/Commands/Connect.java b/src/main/java/net/Broken/RestApi/Commands/Connect.java index 6c00ca3..48ce506 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Connect.java +++ b/src/main/java/net/Broken/RestApi/Commands/Connect.java @@ -1,6 +1,5 @@ package net.Broken.RestApi.Commands; -import net.Broken.Commands.Music; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; diff --git a/src/main/java/net/Broken/RestApi/Commands/Dell.java b/src/main/java/net/Broken/RestApi/Commands/Dell.java index 1840da6..2c20dc4 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Dell.java +++ b/src/main/java/net/Broken/RestApi/Commands/Dell.java @@ -1,7 +1,5 @@ package net.Broken.RestApi.Commands; -import net.Broken.Commands.Music; -import net.Broken.MainBot; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; diff --git a/src/main/java/net/Broken/RestApi/Commands/Flush.java b/src/main/java/net/Broken/RestApi/Commands/Flush.java index 595c84c..f88942e 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Flush.java +++ b/src/main/java/net/Broken/RestApi/Commands/Flush.java @@ -1,6 +1,5 @@ package net.Broken.RestApi.Commands; -import net.Broken.Commands.Music; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; diff --git a/src/main/java/net/Broken/RestApi/Commands/Next.java b/src/main/java/net/Broken/RestApi/Commands/Next.java index 0e49bbf..f1170ba 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Next.java +++ b/src/main/java/net/Broken/RestApi/Commands/Next.java @@ -1,6 +1,5 @@ package net.Broken.RestApi.Commands; -import net.Broken.Commands.Music; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; diff --git a/src/main/java/net/Broken/RestApi/Commands/Pause.java b/src/main/java/net/Broken/RestApi/Commands/Pause.java index e6c9e08..86284ed 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Pause.java +++ b/src/main/java/net/Broken/RestApi/Commands/Pause.java @@ -1,6 +1,5 @@ package net.Broken.RestApi.Commands; -import net.Broken.Commands.Music; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; diff --git a/src/main/java/net/Broken/RestApi/Commands/Play.java b/src/main/java/net/Broken/RestApi/Commands/Play.java index 198ca3a..28109ee 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Play.java +++ b/src/main/java/net/Broken/RestApi/Commands/Play.java @@ -1,6 +1,5 @@ package net.Broken.RestApi.Commands; -import net.Broken.Commands.Music; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; diff --git a/src/main/java/net/Broken/RestApi/Commands/Stop.java b/src/main/java/net/Broken/RestApi/Commands/Stop.java index 8189e96..bb4c895 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Stop.java +++ b/src/main/java/net/Broken/RestApi/Commands/Stop.java @@ -1,13 +1,11 @@ package net.Broken.RestApi.Commands; -import net.Broken.Commands.Music; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.audio.AudioM; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/net/Broken/SlashCommand.java b/src/main/java/net/Broken/SlashCommand.java index 5e98448..70c1997 100644 --- a/src/main/java/net/Broken/SlashCommand.java +++ b/src/main/java/net/Broken/SlashCommand.java @@ -2,6 +2,7 @@ package net.Broken; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; import java.util.List; @@ -20,6 +21,8 @@ public interface SlashCommand { List getOptions(); + List getSubcommands(); + /** * Determines if the command is usable only by bot level admin user * @return boolean diff --git a/src/main/java/net/Broken/SlashCommands/Cat.java b/src/main/java/net/Broken/SlashCommands/Cat.java index b558dd5..5a7df36 100644 --- a/src/main/java/net/Broken/SlashCommands/Cat.java +++ b/src/main/java/net/Broken/SlashCommands/Cat.java @@ -11,6 +11,7 @@ import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.json.JSONObject; @@ -63,6 +64,11 @@ public class Cat implements SlashCommand { return new ArrayList<>(); } + @Override + public List getSubcommands() { + return null; + } + /** * Determines if the command is usable only by bot level admin user diff --git a/src/main/java/net/Broken/SlashCommands/Music.java b/src/main/java/net/Broken/SlashCommands/Music.java new file mode 100644 index 0000000..d5ee90a --- /dev/null +++ b/src/main/java/net/Broken/SlashCommands/Music.java @@ -0,0 +1,164 @@ +package net.Broken.SlashCommands; + + +import net.Broken.MainBot; +import net.Broken.SlashCommand; +import net.Broken.Tools.EmbedMessageUtils; +import net.Broken.Tools.MessageTimeOut; +import net.Broken.audio.AudioM; +import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; + +/** + * Command that return a random picture of cat. + */ +public class Music implements SlashCommand { + private Logger logger = LogManager.getLogger(); + ; + + @Override + public void action(SlashCommandEvent event) { + AudioM audio = AudioM.getInstance(event.getGuild()); + String action = event.getSubcommandName(); + event.deferReply().queue(); + switch (action) { + case "play": + if (event.getMember().getVoiceState().inVoiceChannel()) { + VoiceChannel voiceChanel = event.getMember().getVoiceState().getChannel(); + logger.info("Connecting to " + voiceChanel.getName() + "..."); + OptionMapping url = event.getOption("url"); + if (event.getOption("playlist-limit") == null) { + audio.loadAndPlay(event, voiceChanel, url.getAsString(), 30, false); + } else { + long limit = event.getOption("playlist-limit").getAsLong(); + audio.loadAndPlay(event, voiceChanel, url.getAsString(), (int) limit, false); + } + } else { + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("You are not in a voice channel !")).build(); + event.getHook().sendMessage(message).queue(); + } + break; +// case "add": +// event.getTextChannel().sendTyping().queue(); +// if(args.length ==2){ +// audio.add(event,args[1],30,false); +// } +// else if(args.length == 3){ +// try{ +// int limit = Integer.parseInt(args[2]); +// audio.add(event,args[1],limit,false); +// }catch (NumberFormatException e){ +// audio.add(event,args[1],30,false); +// } +// } +// else{ +// Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Missing argument!")).complete(); +// List messages = new ArrayList(){{ +// add(message); +// add(event.getMessage()); +// }}; +// new MessageTimeOut(messages, MainBot.messageTimeOut).start(); +// } +// break; +// case "addNext": +// event.getTextChannel().sendTyping().queue(); +// if(args.length >=2){ +// audio.add(event,args[1],1,true); +// } +// else{ +// Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Missing argument!")).complete(); +// List messages = new ArrayList(){{ +// add(message); +// add(event.getMessage()); +// }}; +// new MessageTimeOut(messages, MainBot.messageTimeOut).start(); +// } +// break; + case "pause": + audio.pause(event); + break; + case "resume": + audio.resume(event); + break; + case "next": + audio.skipTrack(event); + break; + case "stop": + case "disconnect": + audio.stop(event); + break; + case "info": + audio.info(event); + break; + case "flush": + audio.flush(event); + break; + case "list": + audio.list(event); + break; + } + + + } + + @Override + public String getDescription() { + return "Music Bot !"; + } + + @Override + public List getOptions() { + return null; + } + + @Override + public List getSubcommands() { + ArrayList subCommandList = new ArrayList<>(); + subCommandList.add(new SubcommandData("play", "Play somme music") + .addOption(OptionType.STRING, "url", "The URL of the video to play", true) + .addOption(OptionType.INTEGER, "playlist-limit", "If a playlist is loaded, enter the max number of loaded tracks")); + subCommandList.add(new SubcommandData("add", "Add music to queue") + .addOption(OptionType.STRING, "url", " The URL of the video to play", true)); + subCommandList.add(new SubcommandData("pause", "Pause playback")); + subCommandList.add(new SubcommandData("resume", "Resume playback")); + subCommandList.add(new SubcommandData("stop", "Stop playback")); + subCommandList.add(new SubcommandData("next", "Next music")); + subCommandList.add(new SubcommandData("info", "Get currently playing info")); + subCommandList.add(new SubcommandData("flush", "Flush queue")); + subCommandList.add(new SubcommandData("list", "Get queue")); + return subCommandList; + } + + + /** + * Determines if the command is usable only by bot level admin user + * + * @return boolean + */ + @Override + public boolean isBotAdminCmd() { + return false; + } + + @Override + public boolean isNSFW() { + return false; + } +} diff --git a/src/main/java/net/Broken/Tools/Command/SlashCommandLoader.java b/src/main/java/net/Broken/Tools/Command/SlashCommandLoader.java index dee23e8..4e2807f 100644 --- a/src/main/java/net/Broken/Tools/Command/SlashCommandLoader.java +++ b/src/main/java/net/Broken/Tools/Command/SlashCommandLoader.java @@ -63,7 +63,13 @@ public class SlashCommandLoader { public static void registerSlashCommands(CommandListUpdateAction commandListUpdateAction){ MainBot.slashCommands.forEach((k,v)->{ - commandListUpdateAction.addCommands(new CommandData(k, v.getDescription()).addOptions(v.getOptions())); + CommandData command = new CommandData(k, v.getDescription()); + if(v.getOptions() != null) + command.addOptions(v.getOptions()); + if(v.getSubcommands() != null){ + command.addSubcommands(v.getSubcommands()); + } + commandListUpdateAction.addCommands(command); }); commandListUpdateAction.queue(); } diff --git a/src/main/java/net/Broken/audio/AudioM.java b/src/main/java/net/Broken/audio/AudioM.java index 88d38ff..3462c5f 100644 --- a/src/main/java/net/Broken/audio/AudioM.java +++ b/src/main/java/net/Broken/audio/AudioM.java @@ -11,9 +11,12 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo; import net.Broken.MainBot; import net.Broken.RestApi.Data.UserAudioTrackData; import net.Broken.Tools.EmbedMessageUtils; +import net.dv8tion.jda.api.MessageBuilder; 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.VoiceChannel; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -77,7 +80,7 @@ public class AudioM { * @param playlistLimit Limit of playlist * @param onHead True for adding audio track on top of playlist */ - public void loadAndPlay(MessageReceivedEvent event, VoiceChannel voiceChannel, final String trackUrl, int playlistLimit, boolean onHead) { + public void loadAndPlay(SlashCommandEvent event, VoiceChannel voiceChannel, final String trackUrl, int playlistLimit, boolean onHead) { GuildMusicManager musicManager = getGuildAudioPlayer(); playedChanel = voiceChannel; @@ -85,9 +88,9 @@ public class AudioM { @Override public void trackLoaded(AudioTrack track) { logger.info("[" + guild + "] Single Track detected!"); - UserAudioTrack uat = new UserAudioTrack(event.getAuthor(), track); - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Add " + track.getInfo().title + " to playlist")).queue(); - + UserAudioTrack uat = new UserAudioTrack(event.getUser(), track); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Add " + track.getInfo().title + " to playlist")).build(); + event.getHook().sendMessage(message).queue(); play(guild, voiceChannel, musicManager, uat, onHead); } @@ -95,27 +98,24 @@ public class AudioM { public void playlistLoaded(AudioPlaylist playlist) { logger.info("[" + guild + "] Playlist detected! Limit: " + playlistLimit); AudioTrack firstTrack = playlist.getSelectedTrack(); - - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Add " + firstTrack.getInfo().title + " and 30 first videos to playlist !")).queue(); - - - playListLoader(playlist, playlistLimit, event.getAuthor(), onHead); - - + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Add " + firstTrack.getInfo().title + " and 30 first videos to playlist !")).build(); + event.getHook().sendMessage(message).queue(); + playListLoader(playlist, playlistLimit, event.getUser(), onHead); } @Override public void noMatches() { logger.warn("[" + guild + "] Cant find media!"); - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Video not found !")).queue(); - + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Video not found !")).build(); + event.getHook().sendMessage(message).queue(); } @Override public void loadFailed(FriendlyException exception) { logger.error("[" + guild + "] Can't load media!"); logger.error(exception.getMessage()); - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Playback error !")).queue(); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Playback error !")).build(); + event.getHook().sendMessage(message).queue(); } }); } @@ -208,10 +208,11 @@ public class AudioM { * * @param event */ - public void skipTrack(MessageReceivedEvent event) { + public void skipTrack(SlashCommandEvent event) { GuildMusicManager musicManager = getGuildAudioPlayer(); musicManager.scheduler.nextTrack(); - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Next music!")).queue(); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Next music !")).build(); + event.getHook().sendMessage(message).queue(); } /** @@ -219,11 +220,11 @@ public class AudioM { * * @param event */ - public void pause(MessageReceivedEvent event) { + public void pause(SlashCommandEvent event) { GuildMusicManager musicManager = getGuildAudioPlayer(); musicManager.scheduler.pause(); - - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Music paused")).queue(); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Playback paused")).build(); + event.getHook().sendMessage(message).queue(); } @@ -233,11 +234,11 @@ public class AudioM { * * @param event */ - public void resume(MessageReceivedEvent event) { + public void resume(SlashCommandEvent event) { GuildMusicManager musicManager = getGuildAudioPlayer(); musicManager.scheduler.resume(); - - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Music resumed")).queue(); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Playback resumed")).build(); + event.getHook().sendMessage(message).queue(); } /** @@ -245,18 +246,19 @@ public class AudioM { * * @param event */ - public void info(MessageReceivedEvent event) { + public void info(SlashCommandEvent event) { GuildMusicManager musicManager = getGuildAudioPlayer(); AudioTrackInfo info = musicManager.scheduler.getInfo(); UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack(); - - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk(info.title + "\n" + info.uri + "\nSubmitted by: " + userAudioTrack.getSubmittedUser().getName())).queue(); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk(info.title + "\n" + info.uri + "\nSubmitted by: " + userAudioTrack.getSubmittedUser().getName())).build(); + event.getHook().sendMessage(message).queue(); } - public void flush(MessageReceivedEvent event) { + public void flush(SlashCommandEvent event) { GuildMusicManager musicManager = getGuildAudioPlayer(); musicManager.scheduler.flush(); - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Flush playlist!")).queue(); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Flush playlist!")).build(); + event.getHook().sendMessage(message).queue(); } /** @@ -264,7 +266,7 @@ public class AudioM { * * @param event */ - public void list(MessageReceivedEvent event) { + public void list(SlashCommandEvent event) { GuildMusicManager musicManager = getGuildAudioPlayer(); List list = musicManager.scheduler.getList(); StringBuilder resp = new StringBuilder(); @@ -277,7 +279,8 @@ public class AudioM { resp.append("\n"); } } - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Playlist:\n\n" + resp.toString())).queue(); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Playlist:\n\n" + resp.toString())).build(); + event.getHook().sendMessage(message).queue(); } /** @@ -288,11 +291,12 @@ public class AudioM { * @param playListLimit Limit of playlist * @param onHead True for adding audio track on top of playlist */ - public void add(MessageReceivedEvent event, String url, int playListLimit, boolean onHead) { + public void add(SlashCommandEvent event, String url, int playListLimit, boolean onHead) { if (playedChanel != null) { loadAndPlay(event, playedChanel, url, playListLimit, onHead); } else { - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Not connected to vocal chanel !")).queue(); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicError("Not connected to vocal chanel !")).build(); + event.getHook().sendMessage(message).queue(); } } @@ -301,12 +305,13 @@ public class AudioM { * * @param event */ - public void stop(MessageReceivedEvent event) { + public void stop(SlashCommandEvent event) { musicManager.scheduler.stop(); musicManager.scheduler.flush(); if (event != null) { - event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Music stopped")).queue(); + Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Music stopped")).build(); + event.getHook().sendMessage(message).queue(); } }