Compare commits

..

4 Commits

Author SHA1 Message Date
Renovate Bot
c0ff885066
Update dependency org.reflections:reflections to v0.10.2 2022-05-15 14:50:55 +00:00
12230218df
Disable plain jar 2022-05-15 16:49:55 +02:00
35093a1bd1
Fix build 2022-05-15 16:40:00 +02:00
4118116ee9
Migrate music to slash command 2022-05-15 14:37:20 +02:00
19 changed files with 206 additions and 250 deletions

View File

@ -17,10 +17,10 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set up JDK 1.8 - name: Set up JDK 17
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: 1.8 java-version: 17
- name: Grant execute permission for gradlew - name: Grant execute permission for gradlew
run: chmod +x gradlew run: chmod +x gradlew
@ -35,8 +35,9 @@ jobs:
path: build/libs/ path: build/libs/
build-docker: build-docker:
runs-on: [ ubuntu-latest ] runs-on: ubuntu-latest
needs: [ build-gradle ] needs:
- build-gradle
if: github.ref == 'refs/heads/master' if: github.ref == 'refs/heads/master'
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2

View File

@ -1,4 +1,4 @@
FROM openjdk:8-jre-buster FROM openjdk:17.0.2
WORKDIR /bot_src WORKDIR /bot_src
ARG BUILD_NBR ARG BUILD_NBR
ARG BRANCH_NAME ARG BRANCH_NAME
@ -6,7 +6,5 @@ ARG BRANCH_NAME
ARG GITHUB_RUN_NUMBER ARG GITHUB_RUN_NUMBER
ADD build/libs/ClaptrapBot-*.jar /bot_src/bot.jar ADD build/libs/ClaptrapBot-*.jar /bot_src/bot.jar
RUN java -version RUN java -version
ENV PORT=8080 CMD java -jar bot.jar
ENV TOKEN=10
CMD java -jar bot.jar -t ${TOKEN}
LABEL org.opencontainers.image.source=https://github.com/Sebclem/ClaptrapBot/ LABEL org.opencontainers.image.source=https://github.com/Sebclem/ClaptrapBot/

View File

@ -15,26 +15,15 @@ version = "$versionObj"
sourceCompatibility = '17' sourceCompatibility = '17'
jar.doFirst {
delete "${buildDir}/libs/*"
}
jar {
// delete "${buildDir}/libs/*"
// baseName = 'DiscordBot'
}
repositories { repositories {
mavenCentral() mavenCentral()
jcenter()
maven { maven {
url 'https://m2.dv8tion.net/releases' url 'https://m2.dv8tion.net/releases'
} }
} }
jar{
enabled(false)
}
dependencies { dependencies {
implementation("org.springframework.boot:spring-boot-starter-web"){ implementation("org.springframework.boot:spring-boot-starter-web"){

View File

@ -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<Message> messages = new ArrayList<Message>(){{
add(message);
add(event.getMessage());
}};
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
}
}
else{
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Missing argument!")).complete();
List<Message> messages = new ArrayList<Message>(){{
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<Message> messages = new ArrayList<Message>(){{
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<Message> messages = new ArrayList<Message>(){{
add(message);
add(event.getMessage());
}};
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
}
break;
case "disconnect":
audio.stop();
List<Message> messages = new ArrayList<Message>(){{
add(event.getMessage());
}};
new MessageTimeOut(messages, 0).start();
break;
default:
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Unknown argument!")).complete();
List<Message> messagess = new ArrayList<Message>(){{
add(message);
add(event.getMessage());
}};
new MessageTimeOut(messagess, MainBot.messageTimeOut).start();
break;
}
}
else{
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicError("Missing argument!")).complete();
List<Message> messages = new ArrayList<Message>(){{
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;
}
}

View File

@ -1,6 +1,5 @@
package net.Broken.RestApi; package net.Broken.RestApi;
import net.Broken.Commands.Music;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;

View File

@ -1,6 +1,5 @@
package net.Broken.RestApi.Commands; package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;

View File

@ -1,6 +1,5 @@
package net.Broken.RestApi.Commands; package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;

View File

@ -1,6 +1,5 @@
package net.Broken.RestApi.Commands; package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;

View File

@ -1,7 +1,5 @@
package net.Broken.RestApi.Commands; package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.MainBot;
import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;

View File

@ -1,6 +1,5 @@
package net.Broken.RestApi.Commands; package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;

View File

@ -1,6 +1,5 @@
package net.Broken.RestApi.Commands; package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;

View File

@ -1,6 +1,5 @@
package net.Broken.RestApi.Commands; package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;

View File

@ -1,6 +1,5 @@
package net.Broken.RestApi.Commands; package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;

View File

@ -1,13 +1,11 @@
package net.Broken.RestApi.Commands; package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.RestApi.Data.CommandResponseData;
import net.Broken.audio.AudioM; import net.Broken.audio.AudioM;
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.events.message.MessageReceivedEvent;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;

View File

@ -2,6 +2,7 @@ package net.Broken;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; 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.OptionData;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import java.util.List; import java.util.List;
@ -20,6 +21,8 @@ public interface SlashCommand {
List<OptionData> getOptions(); List<OptionData> getOptions();
List<SubcommandData> getSubcommands();
/** /**
* Determines if the command is usable only by bot level admin user * Determines if the command is usable only by bot level admin user
* @return boolean * @return boolean

View File

@ -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.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; 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.OptionData;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.json.JSONObject; import org.json.JSONObject;
@ -63,6 +64,11 @@ public class Cat implements SlashCommand {
return new ArrayList<>(); return new ArrayList<>();
} }
@Override
public List<SubcommandData> getSubcommands() {
return null;
}
/** /**
* Determines if the command is usable only by bot level admin user * Determines if the command is usable only by bot level admin user

View File

@ -0,0 +1,142 @@
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":
OptionMapping url = event.getOption("url");
boolean next = false;
if(event.getOption("next") != null){
next = event.getOption("next").getAsBoolean();
}
if(event.getOption("playlist-limit") == null){
audio.add(event, url.getAsString(),30, next);
}
else{
long limit = event.getOption("playlist-limit").getAsLong();
audio.add(event, url.getAsString(), (int) limit, next);
}
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<OptionData> getOptions() {
return null;
}
@Override
public List<SubcommandData> getSubcommands() {
ArrayList<SubcommandData> subCommandList = new ArrayList<>();
subCommandList.add(new SubcommandData("play", "Play 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 (default to 30)"));
subCommandList.add(new SubcommandData("add", "Add track to queue")
.addOption(OptionType.STRING, "url", " The URL of the video to play", true)
.addOption(OptionType.BOOLEAN, "next", "If true, track will be added on top of the playlist and will be the next to play")
.addOption(OptionType.INTEGER, "playlist-limit", "If a playlist is loaded, enter the max number of loaded tracks (default to 30)"));
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;
}
}

View File

@ -63,7 +63,13 @@ public class SlashCommandLoader {
public static void registerSlashCommands(CommandListUpdateAction commandListUpdateAction){ public static void registerSlashCommands(CommandListUpdateAction commandListUpdateAction){
MainBot.slashCommands.forEach((k,v)->{ 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(); commandListUpdateAction.queue();
} }

View File

@ -11,9 +11,12 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import net.Broken.MainBot; import net.Broken.MainBot;
import net.Broken.RestApi.Data.UserAudioTrackData; import net.Broken.RestApi.Data.UserAudioTrackData;
import net.Broken.Tools.EmbedMessageUtils; import net.Broken.Tools.EmbedMessageUtils;
import net.dv8tion.jda.api.MessageBuilder;
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.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -77,7 +80,7 @@ public class AudioM {
* @param playlistLimit Limit of playlist * @param playlistLimit Limit of playlist
* @param onHead True for adding audio track on top 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(); GuildMusicManager musicManager = getGuildAudioPlayer();
playedChanel = voiceChannel; playedChanel = voiceChannel;
@ -85,9 +88,9 @@ public class AudioM {
@Override @Override
public void trackLoaded(AudioTrack track) { public void trackLoaded(AudioTrack track) {
logger.info("[" + guild + "] Single Track detected!"); logger.info("[" + guild + "] Single Track detected!");
UserAudioTrack uat = new UserAudioTrack(event.getAuthor(), track); UserAudioTrack uat = new UserAudioTrack(event.getUser(), track);
event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Add " + track.getInfo().title + " to playlist")).queue(); 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); play(guild, voiceChannel, musicManager, uat, onHead);
} }
@ -95,27 +98,24 @@ public class AudioM {
public void playlistLoaded(AudioPlaylist playlist) { public void playlistLoaded(AudioPlaylist playlist) {
logger.info("[" + guild + "] Playlist detected! Limit: " + playlistLimit); logger.info("[" + guild + "] Playlist detected! Limit: " + playlistLimit);
AudioTrack firstTrack = playlist.getSelectedTrack(); AudioTrack firstTrack = playlist.getSelectedTrack();
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Add " + firstTrack.getInfo().title + " and 30 first videos to playlist !")).build();
event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Add " + firstTrack.getInfo().title + " and 30 first videos to playlist !")).queue(); event.getHook().sendMessage(message).queue();
playListLoader(playlist, playlistLimit, event.getUser(), onHead);
playListLoader(playlist, playlistLimit, event.getAuthor(), onHead);
} }
@Override @Override
public void noMatches() { public void noMatches() {
logger.warn("[" + guild + "] Cant find media!"); 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 @Override
public void loadFailed(FriendlyException exception) { public void loadFailed(FriendlyException exception) {
logger.error("[" + guild + "] Can't load media!"); logger.error("[" + guild + "] Can't load media!");
logger.error(exception.getMessage()); 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 * @param event
*/ */
public void skipTrack(MessageReceivedEvent event) { public void skipTrack(SlashCommandEvent event) {
GuildMusicManager musicManager = getGuildAudioPlayer(); GuildMusicManager musicManager = getGuildAudioPlayer();
musicManager.scheduler.nextTrack(); 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 * @param event
*/ */
public void pause(MessageReceivedEvent event) { public void pause(SlashCommandEvent event) {
GuildMusicManager musicManager = getGuildAudioPlayer(); GuildMusicManager musicManager = getGuildAudioPlayer();
musicManager.scheduler.pause(); musicManager.scheduler.pause();
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Playback paused")).build();
event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Music paused")).queue(); event.getHook().sendMessage(message).queue();
} }
@ -233,11 +234,11 @@ public class AudioM {
* *
* @param event * @param event
*/ */
public void resume(MessageReceivedEvent event) { public void resume(SlashCommandEvent event) {
GuildMusicManager musicManager = getGuildAudioPlayer(); GuildMusicManager musicManager = getGuildAudioPlayer();
musicManager.scheduler.resume(); musicManager.scheduler.resume();
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Playback resumed")).build();
event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Music resumed")).queue(); event.getHook().sendMessage(message).queue();
} }
/** /**
@ -245,18 +246,19 @@ public class AudioM {
* *
* @param event * @param event
*/ */
public void info(MessageReceivedEvent event) { public void info(SlashCommandEvent event) {
GuildMusicManager musicManager = getGuildAudioPlayer(); GuildMusicManager musicManager = getGuildAudioPlayer();
AudioTrackInfo info = musicManager.scheduler.getInfo(); AudioTrackInfo info = musicManager.scheduler.getInfo();
UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack(); UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack();
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk(info.title + "\n" + info.uri + "\nSubmitted by: " + userAudioTrack.getSubmittedUser().getName())).build();
event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk(info.title + "\n" + info.uri + "\nSubmitted by: " + userAudioTrack.getSubmittedUser().getName())).queue(); event.getHook().sendMessage(message).queue();
} }
public void flush(MessageReceivedEvent event) { public void flush(SlashCommandEvent event) {
GuildMusicManager musicManager = getGuildAudioPlayer(); GuildMusicManager musicManager = getGuildAudioPlayer();
musicManager.scheduler.flush(); 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 * @param event
*/ */
public void list(MessageReceivedEvent event) { public void list(SlashCommandEvent event) {
GuildMusicManager musicManager = getGuildAudioPlayer(); GuildMusicManager musicManager = getGuildAudioPlayer();
List<UserAudioTrackData> list = musicManager.scheduler.getList(); List<UserAudioTrackData> list = musicManager.scheduler.getList();
StringBuilder resp = new StringBuilder(); StringBuilder resp = new StringBuilder();
@ -277,7 +279,8 @@ public class AudioM {
resp.append("\n"); 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 playListLimit Limit of playlist
* @param onHead True for adding audio track on top 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) { if (playedChanel != null) {
loadAndPlay(event, playedChanel, url, playListLimit, onHead); loadAndPlay(event, playedChanel, url, playListLimit, onHead);
} else { } 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 * @param event
*/ */
public void stop(MessageReceivedEvent event) { public void stop(SlashCommandEvent event) {
musicManager.scheduler.stop(); musicManager.scheduler.stop();
musicManager.scheduler.flush(); musicManager.scheduler.flush();
if (event != null) { 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();
} }
} }