diff --git a/pom.xml b/pom.xml
index 0d7fb77..e395d03 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
ca.tristan.easycommands
EasyCommands
- 0.3
+ 0.6
jar
EasyCommands
@@ -30,6 +30,10 @@
m2-dv8tion
https://m2.dv8tion.net/releases
+
+ jitpack.io
+ https://jitpack.io
+
@@ -48,6 +52,11 @@
lavaplayer
1.3.77
+
+ com.github.LowLevelSubmarine
+ GeniusLyricsAPI
+ 1.0.3
+
\ No newline at end of file
diff --git a/src/main/java/ca/tristan/easycommands/commands/EasyCommands.java b/src/main/java/ca/tristan/easycommands/commands/EasyCommands.java
index 8fd4834..76b19ed 100644
--- a/src/main/java/ca/tristan/easycommands/commands/EasyCommands.java
+++ b/src/main/java/ca/tristan/easycommands/commands/EasyCommands.java
@@ -1,24 +1,28 @@
package ca.tristan.easycommands.commands;
-import ca.tristan.easycommands.commands.music.NowPlayingCmd;
-import ca.tristan.easycommands.commands.music.PlayCmd;
-import ca.tristan.easycommands.commands.music.SkipCmd;
-import ca.tristan.easycommands.commands.music.StopCmd;
+import ca.tristan.easycommands.commands.music.*;
import ca.tristan.easycommands.commands.prefix.PrefixCommands;
import ca.tristan.easycommands.commands.prefix.PrefixExecutor;
-import ca.tristan.easycommands.commands.slash.CommandExecutor;
import ca.tristan.easycommands.commands.slash.SlashExecutor;
+import ca.tristan.easycommands.events.AutoDisconnectEvent;
+import ca.tristan.easycommands.events.ButtonEvents;
+import ca.tristan.easycommands.utils.ConsoleColors;
import ca.tristan.easycommands.utils.LogType;
import ca.tristan.easycommands.utils.Logger;
+import com.mysql.cj.log.Log;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Role;
+import net.dv8tion.jda.api.entities.channel.Channel;
+import net.dv8tion.jda.api.entities.channel.ChannelType;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
+import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.requests.GatewayIntent;
-import net.dv8tion.jda.api.requests.restaction.CommandEditAction;
+import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.jetbrains.annotations.NotNull;
@@ -44,9 +48,14 @@ public class EasyCommands extends ListenerAdapter {
private PrefixCommands prefixCommands;
+ private static Channel musicChannel;
+
+ private Long millisStart, millisEnd;
+
public EasyCommands(String token, boolean enablePrefixCommands, boolean enableMusicBot) {
this.usePrefixCommands = enablePrefixCommands;
this.useMusicBot = enableMusicBot;
+ millisStart = System.currentTimeMillis();
loadIntents();
@@ -69,6 +78,7 @@ public JDA buildJDA() throws InterruptedException {
if(this.useMusicBot) {
enableMusicBot();
+ this.jda.addEventListener(new AutoDisconnectEvent(), new ButtonEvents());
}
if(usePrefixCommands) {
@@ -77,7 +87,8 @@ public JDA buildJDA() throws InterruptedException {
updateCommands();
logCurrentExecutors();
-
+ millisEnd = System.currentTimeMillis();
+ Logger.log(LogType.OK, "EasyCommands finished loading in " + ConsoleColors.GREEN_BOLD + (millisEnd - millisStart) + "ms" + ConsoleColors.GREEN + ".");
return jda;
}
@@ -156,8 +167,7 @@ public EasyCommands clearExecutors() {
@Override
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
- if(getExecutors().containsKey(event.getName()) && (getExecutors().get(event.getName()) instanceof SlashExecutor || getExecutors().get(event.getName()) instanceof CommandExecutor)) {
- IExecutor executor = getExecutors().get(event.getName());
+ if(getExecutors().containsKey(event.getName()) && getExecutors().get(event.getName()) instanceof SlashExecutor executor) {
Logger.log(LogType.SLASHCMD, "'" + executor.getName() + "' has been triggered.");
if(executor.isOwnerOnly() && ! (Objects.requireNonNull(event.getMember())).isOwner()) {
event.reply("This command can only be used by the server owner.").setEphemeral(true).queue();
@@ -172,22 +182,14 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even
if(executor.getAuthorizedRoles(jda) != null && !executor.getAuthorizedRoles(jda).isEmpty()) {
for (Role authorizedRole : executor.getAuthorizedRoles(jda)) {
if(Objects.requireNonNull(event.getMember()).getRoles().contains(authorizedRole)) {
- if(executor instanceof CommandExecutor ex) {
- ex.execute(new EventData(event));
- } else if(executor instanceof SlashExecutor ex) {
- ex.execute(new EventData(event));
- }
+ executor.execute(new EventData(event));
break;
}
}
return;
}
- if(executor instanceof CommandExecutor ex) {
- ex.execute(new EventData(event));
- } else if(executor instanceof SlashExecutor ex) {
- ex.execute(new EventData(event));
- }
+ executor.execute(new EventData(event));
}
}
@@ -195,17 +197,32 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even
* Used to debug executors. Serve to identify if the commands are registered to Discord correctly.
*/
private void logCurrentExecutors() {
- Logger.log(LogType.OK, jda.retrieveCommands().complete().toString());
+
+ List commands = jda.retrieveCommands().complete();
+ Logger.log(LogType.EXECUTORS, "--- Registered SlashExecutors ---");
+ for (Command command : commands) {
+ Logger.logNoType("/" + command.getName() + ConsoleColors.RESET + ":" + ConsoleColors.CYAN + command.getId());
+ }
+
+ Logger.log(LogType.EXECUTORS, "--- Registered PrefixExecutors ---");
+ getExecutors().forEach((s, iExecutor) -> {
+ if(iExecutor instanceof PrefixExecutor) {
+ if(!iExecutor.getAliases().contains(s)) {
+ Logger.logNoType(getPrefixCommands().getPrefix() + s);
+ }
+ }
+ });
+
}
/**
* Updates all executors/commands to Discord Guild.
*/
- public void updateCommands() {
+ private void updateCommands() {
List commands = new ArrayList<>();
getExecutors().forEach((name, executor) -> {
if(executor instanceof SlashExecutor executor1) {
- commands.add(Commands.slash(executor1.getName(), executor1.getDescription()).addOptions(executor1.getOptions()));
+ commands.add(Commands.slash(name, executor1.getDescription()).addOptions(executor1.getOptions()));
}
});
jda.updateCommands().addCommands(commands).queue();
@@ -226,9 +243,23 @@ public EasyCommands registerListeners(ListenerAdapter... listeners) {
return this;
}
- public void enableMusicBot() {
- this.addExecutor(new PlayCmd(), new StopCmd(), new NowPlayingCmd(), new SkipCmd());
- Logger.log(LogType.OK, "Music bot enabled.");
+ private void enableMusicBot() {
+ this.addExecutor(new PlayCmd(), new StopCmd(), new NowPlayingCmd(), new SkipCmd(), new PauseCmd(), new LyricsCmd());
+ Logger.log(LogType.OK, "EasyCommands MusicBot has been enabled successfully.");
+ }
+
+ public void setMusicChannel(String id) {
+
+ if(this.jda == null) {
+ Logger.log(LogType.ERROR, "Can't set the music channel before building JDA.");
+ return;
+ }
+
+ musicChannel = this.jda.getTextChannelById(id);
+ }
+
+ public static Channel getMusicChannel() {
+ return musicChannel;
}
}
diff --git a/src/main/java/ca/tristan/easycommands/commands/EventData.java b/src/main/java/ca/tristan/easycommands/commands/EventData.java
index 0106254..6186f07 100644
--- a/src/main/java/ca/tristan/easycommands/commands/EventData.java
+++ b/src/main/java/ca/tristan/easycommands/commands/EventData.java
@@ -95,8 +95,12 @@ public GuildVoiceState getMemberVoiceState() {
return memberVoiceState;
}
+ public void deferReply(boolean isEphemeral) {
+ event.deferReply(isEphemeral).queue();
+ }
+
public void deferReply() {
- event.deferReply().queue();
+ this.deferReply(false);
}
public ReplyCallbackAction reply(String content, boolean ephemeral) {
diff --git a/src/main/java/ca/tristan/easycommands/commands/defaults/HelpCmd.java b/src/main/java/ca/tristan/easycommands/commands/defaults/HelpCmd.java
index 7dba270..af8d91b 100644
--- a/src/main/java/ca/tristan/easycommands/commands/defaults/HelpCmd.java
+++ b/src/main/java/ca/tristan/easycommands/commands/defaults/HelpCmd.java
@@ -5,8 +5,10 @@
import ca.tristan.easycommands.commands.EventData;
import ca.tristan.easycommands.commands.prefix.PrefixExecutor;
import net.dv8tion.jda.api.EmbedBuilder;
+import net.dv8tion.jda.api.entities.MessageEmbed;
import java.awt.*;
+import java.util.List;
public class HelpCmd extends SlashExecutor {
@@ -39,21 +41,25 @@ public void execute(EventData data) {
builder.addField("Slash Commands", "--------------------", false);
easyCommands.getExecutors().forEach((name, commandExecutor) -> {
if(commandExecutor instanceof SlashExecutor && !commandExecutor.isOwnerOnly() && !commandExecutor.getName().equals("help") && (commandExecutor.getDescription() != null || !commandExecutor.getDescription().isEmpty())) {
- builder.addField("/" + commandExecutor.getName(), commandExecutor.getDescription(), false);
+ if(!commandExecutor.getAliases().contains(name)) {
+ builder.addField("/" + name, commandExecutor.getDescription(), false);
+ }
}
});
builder.addField("Prefix Commands", "--------------------", false);
easyCommands.getExecutors().forEach((name, commandExecutor) -> {
if(commandExecutor instanceof PrefixExecutor && !commandExecutor.isOwnerOnly() && !commandExecutor.getName().equals("help") && (commandExecutor.getDescription() != null || !commandExecutor.getDescription().isEmpty())) {
- builder.addField(easyCommands.getPrefixCommands().getPrefix() + commandExecutor.getName(), commandExecutor.getDescription(), false);
+ if(!commandExecutor.getAliases().contains(name)) {
+ builder.addField(easyCommands.getPrefixCommands().getPrefix() + name, commandExecutor.getDescription(), false);
+ }
}
});
if(builder.getFields().isEmpty()) {
- builder.addField("There's no command to show for this server.", "", false);
+ builder.setDescription("There's no command to show for this server.");
}else {
builder.setDescription("Here's a list of command you might be able to use on this server.");
}
- builder.setFooter("This help message was generated by EasyCommands.", "https://raw.githubusercontent.com/FrostedCA/EasyCommands/master/LEAFSTACKv2.png");
+ builder.setFooter("This help message was generated by EasyCommands.", "https://raw.githubusercontent.com/FrostedCA/EasyCommands/master/ECLogo_new.png");
data.reply(builder.build(), true).queue();
}
diff --git a/src/main/java/ca/tristan/easycommands/commands/music/LyricsCmd.java b/src/main/java/ca/tristan/easycommands/commands/music/LyricsCmd.java
new file mode 100644
index 0000000..7d280c8
--- /dev/null
+++ b/src/main/java/ca/tristan/easycommands/commands/music/LyricsCmd.java
@@ -0,0 +1,74 @@
+package ca.tristan.easycommands.commands.music;
+
+import ca.tristan.easycommands.commands.EasyCommands;
+import ca.tristan.easycommands.commands.EventData;
+import ca.tristan.easycommands.commands.slash.SlashExecutor;
+import ca.tristan.easycommands.embeds.MusicEB;
+import ca.tristan.easycommands.lavaplayer.GuildMusicManager;
+import ca.tristan.easycommands.lavaplayer.PlayerManager;
+import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
+import core.GLA;
+import genius.SongSearch;
+import net.dv8tion.jda.api.JDA;
+import net.dv8tion.jda.api.entities.channel.Channel;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class LyricsCmd extends SlashExecutor {
+
+ @Override
+ public String getName() {
+ return "lyrics";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Retrieves the lyrics of the current playing music.";
+ }
+
+ @Override
+ public List getAuthorizedChannels(JDA jda) {
+ List channels = new ArrayList<>();
+ if(EasyCommands.getMusicChannel() != null) {
+ channels.add(EasyCommands.getMusicChannel());
+ }
+ return channels;
+ }
+
+ @Override
+ public void execute(EventData data) {
+ final GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(data.getGuild());
+ final AudioPlayer audioPlayer = musicManager.audioPlayer;
+
+ MusicEB musicEB = new MusicEB();
+
+ if(audioPlayer.getPlayingTrack() == null){
+ musicEB.getBuilder().setDescription("There is no music currently playing.");
+ data.reply(musicEB.getBuilder().build(), true).queue();
+ return;
+ }
+
+ String title = audioPlayer.getPlayingTrack().getInfo().title;
+
+ GLA gla = new GLA();
+ try {
+
+ SongSearch search = gla.search(title.toLowerCase().replaceAll("official", "").replaceAll("music", "").replaceAll("video", "").replaceAll("Audio", ""));
+
+ String url = search.getHits().isEmpty() ? "" : search.getHits().getFirst().getUrl();
+ if(url.isBlank()){
+ musicEB.getBuilder().setDescription("Sorry, I haven't found any lyrics for that song.");
+ data.reply(musicEB.getBuilder().build(), true).queue();
+ return;
+ }
+ musicEB.getBuilder().setDescription("Here's what I've found: " + url);
+ data.reply(musicEB.getBuilder().build(), true).queue();
+ } catch (IOException e) {
+ musicEB.getBuilder().setDescription("Sorry, I haven't found any lyrics for that song.");
+ data.reply(musicEB.getBuilder().build(), true).queue();
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/ca/tristan/easycommands/commands/music/NowPlayingCmd.java b/src/main/java/ca/tristan/easycommands/commands/music/NowPlayingCmd.java
index 5599f30..6f94598 100644
--- a/src/main/java/ca/tristan/easycommands/commands/music/NowPlayingCmd.java
+++ b/src/main/java/ca/tristan/easycommands/commands/music/NowPlayingCmd.java
@@ -1,10 +1,16 @@
package ca.tristan.easycommands.commands.music;
+import ca.tristan.easycommands.commands.EasyCommands;
import ca.tristan.easycommands.commands.slash.SlashExecutor;
import ca.tristan.easycommands.commands.EventData;
import ca.tristan.easycommands.lavaplayer.GuildMusicManager;
import ca.tristan.easycommands.lavaplayer.PlayerManager;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
+import net.dv8tion.jda.api.JDA;
+import net.dv8tion.jda.api.entities.channel.Channel;
+
+import java.util.ArrayList;
+import java.util.List;
public class NowPlayingCmd extends SlashExecutor {
@@ -18,6 +24,15 @@ public String getDescription() {
return "Shows the current playing track.";
}
+ @Override
+ public List getAuthorizedChannels(JDA jda) {
+ List channels = new ArrayList<>();
+ if(EasyCommands.getMusicChannel() != null) {
+ channels.add(EasyCommands.getMusicChannel());
+ }
+ return channels;
+ }
+
@Override
public void execute(EventData data) {
final GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(data.getGuild());
diff --git a/src/main/java/ca/tristan/easycommands/commands/music/PauseCmd.java b/src/main/java/ca/tristan/easycommands/commands/music/PauseCmd.java
new file mode 100644
index 0000000..03e6d5e
--- /dev/null
+++ b/src/main/java/ca/tristan/easycommands/commands/music/PauseCmd.java
@@ -0,0 +1,73 @@
+package ca.tristan.easycommands.commands.music;
+
+import ca.tristan.easycommands.commands.EasyCommands;
+import ca.tristan.easycommands.commands.EventData;
+import ca.tristan.easycommands.commands.slash.SlashExecutor;
+import ca.tristan.easycommands.embeds.MusicEB;
+import ca.tristan.easycommands.lavaplayer.GuildMusicManager;
+import ca.tristan.easycommands.lavaplayer.PlayerManager;
+import net.dv8tion.jda.api.JDA;
+import net.dv8tion.jda.api.entities.channel.Channel;
+import net.dv8tion.jda.api.entities.emoji.Emoji;
+import net.dv8tion.jda.api.interactions.components.buttons.Button;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PauseCmd extends SlashExecutor {
+
+ @Override
+ public String getName() {
+ return "pause";
+ }
+
+ @Override
+ public List getAliases() {
+ List aliases = new ArrayList<>();
+ aliases.add("unpause");
+ return aliases;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Pauses the current music.";
+ }
+
+ @Override
+ public List getAuthorizedChannels(JDA jda) {
+ List channels = new ArrayList<>();
+ if(EasyCommands.getMusicChannel() != null) {
+ channels.add(EasyCommands.getMusicChannel());
+ }
+ return channels;
+ }
+
+ @Override
+ public void execute(EventData data) {
+
+ GuildMusicManager guildMusicManager = PlayerManager.getInstance().getMusicManager(data.getGuild());
+
+ if(guildMusicManager.scheduler.player.getPlayingTrack() == null) {
+ MusicEB musicEB = new MusicEB();
+ musicEB.getBuilder().setDescription("There is no music currently playing.");
+ data.reply(musicEB.getBuilder().build(), false).setActionRow(
+ Button.link("https://github.com/FrostedCA/EasyCommands", "EasyCommands").withEmoji(Emoji.fromUnicode("✨"))
+ ).queue();
+ return;
+ }
+
+ guildMusicManager.scheduler.player.setPaused(!guildMusicManager.scheduler.player.isPaused());
+ MusicEB musicEB = new MusicEB();
+ musicEB.getBuilder().addField("Current Music", guildMusicManager.scheduler.player.getPlayingTrack().getInfo().title, false);
+ if(guildMusicManager.scheduler.player.isPaused()) {
+ musicEB.getBuilder().setDescription("Current music has been paused.");
+ musicEB.getBuilder().addField("Paused by", data.getCommandSender().getAsMention(), false);
+ }else {
+ musicEB.getBuilder().setDescription("Current music has been unpause.");
+ musicEB.getBuilder().addField("Unpause by", data.getCommandSender().getAsMention(), false);
+ }
+ data.reply(musicEB.getBuilder().build(), false).setActionRow(musicEB.getActionRow()).queue();
+
+ }
+
+}
diff --git a/src/main/java/ca/tristan/easycommands/commands/music/PlayCmd.java b/src/main/java/ca/tristan/easycommands/commands/music/PlayCmd.java
index 3d64755..cccacca 100644
--- a/src/main/java/ca/tristan/easycommands/commands/music/PlayCmd.java
+++ b/src/main/java/ca/tristan/easycommands/commands/music/PlayCmd.java
@@ -1,8 +1,11 @@
package ca.tristan.easycommands.commands.music;
+import ca.tristan.easycommands.commands.EasyCommands;
import ca.tristan.easycommands.commands.slash.SlashExecutor;
import ca.tristan.easycommands.commands.EventData;
import ca.tristan.easycommands.lavaplayer.PlayerManager;
+import net.dv8tion.jda.api.JDA;
+import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.commands.OptionType;
@@ -12,6 +15,7 @@
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ArrayList;
import java.util.List;
public class PlayCmd extends SlashExecutor {
@@ -32,6 +36,15 @@ public List getOptions() {
return options;
}
+ @Override
+ public List getAuthorizedChannels(JDA jda) {
+ List channels = new ArrayList<>();
+ if(EasyCommands.getMusicChannel() != null) {
+ channels.add(EasyCommands.getMusicChannel());
+ }
+ return channels;
+ }
+
@Override
public void execute(EventData data) {
if(data.getCommand().getOptions().isEmpty()) {
@@ -44,7 +57,7 @@ public void execute(EventData data) {
return;
}
- data.getEvent().deferReply().queue();
+ data.deferReply();
if(!data.getSelfVoiceState().inAudioChannel()){
final AudioManager audioManager = data.getGuild().getAudioManager();
diff --git a/src/main/java/ca/tristan/easycommands/commands/music/SkipCmd.java b/src/main/java/ca/tristan/easycommands/commands/music/SkipCmd.java
index 2843622..67d1cd8 100644
--- a/src/main/java/ca/tristan/easycommands/commands/music/SkipCmd.java
+++ b/src/main/java/ca/tristan/easycommands/commands/music/SkipCmd.java
@@ -1,12 +1,23 @@
package ca.tristan.easycommands.commands.music;
+import ca.tristan.easycommands.commands.EasyCommands;
import ca.tristan.easycommands.commands.slash.SlashExecutor;
import ca.tristan.easycommands.commands.EventData;
+import ca.tristan.easycommands.embeds.MusicEB;
import ca.tristan.easycommands.lavaplayer.GuildMusicManager;
import ca.tristan.easycommands.lavaplayer.PlayerManager;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
+import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.Member;
+import net.dv8tion.jda.api.entities.channel.Channel;
+import net.dv8tion.jda.api.entities.emoji.Emoji;
+import net.dv8tion.jda.api.interactions.components.ItemComponent;
+import net.dv8tion.jda.api.interactions.components.buttons.Button;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
public class SkipCmd extends SlashExecutor {
@@ -20,28 +31,39 @@ public String getDescription() {
return "Skips the current track to the next one.";
}
+ @Override
+ public List getAuthorizedChannels(JDA jda) {
+ List channels = new ArrayList<>();
+ if(EasyCommands.getMusicChannel() != null) {
+ channels.add(EasyCommands.getMusicChannel());
+ }
+ return channels;
+ }
+
@Override
public void execute(EventData data) {
final Member self = data.getSelfMember();
final GuildVoiceState selfVoiceState = self.getVoiceState();
- data.deferReply();
+ MusicEB musicEB = new MusicEB();
if(selfVoiceState == null || !selfVoiceState.inAudioChannel()){
- data.getHook().sendMessage("I need to be in a voice channel for this to work.").queue();
+ musicEB.getBuilder().setDescription("I need to be in a voice channel for this to work.");
+ data.reply(musicEB.getBuilder().build(), true).queue();
return;
}
- final Member member = data.getCommandSender();
final GuildVoiceState memberVoiceState = data.getMemberVoiceState();
if(!memberVoiceState.inAudioChannel()){
- data.getHook().sendMessage("You need to be in a voice channel for this command to work.").queue();
+ musicEB.getBuilder().setDescription("You need to be in a voice channel for this command to work.");
+ data.reply(musicEB.getBuilder().build(), true).queue();
return;
}
if(!memberVoiceState.getChannel().equals(selfVoiceState.getChannel())){
- data.getHook().sendMessage("You need to be in the same voice channel as me for this to work.").queue();
+ musicEB.getBuilder().setDescription("You need to be in the same voice channel as me for this to work.");
+ data.reply(musicEB.getBuilder().build(), true).queue();
return;
}
@@ -49,12 +71,18 @@ public void execute(EventData data) {
final AudioPlayer audioPlayer = musicManager.audioPlayer;
if(audioPlayer.getPlayingTrack() == null){
- data.getHook().sendMessage("There is no track playing currently.").queue();
+ musicEB.getBuilder().setDescription("There is no track playing currently.");
+ data.reply(musicEB.getBuilder().build(), true).queue();
return;
}
musicManager.scheduler.nextTrack();
- data.getHook().sendMessage("Skipped the current track. Now playing **`" + musicManager.audioPlayer.getPlayingTrack().getInfo().title + "`** by **`" + musicManager.audioPlayer.getPlayingTrack().getInfo().author + "`**.").queue();
+
+ musicEB.getBuilder().setDescription("Skipped the current music.");
+ musicEB.getBuilder().addField("Now playing", musicManager.audioPlayer.getPlayingTrack().getInfo().title, false);
+ musicEB.getBuilder().addField("By", musicManager.audioPlayer.getPlayingTrack().getInfo().author, false);
+
+ data.reply(musicEB.getBuilder().build(), false).setActionRow(musicEB.getActionRow()).queue();
}
}
diff --git a/src/main/java/ca/tristan/easycommands/commands/music/StopCmd.java b/src/main/java/ca/tristan/easycommands/commands/music/StopCmd.java
index de8c845..851d38f 100644
--- a/src/main/java/ca/tristan/easycommands/commands/music/StopCmd.java
+++ b/src/main/java/ca/tristan/easycommands/commands/music/StopCmd.java
@@ -1,9 +1,17 @@
package ca.tristan.easycommands.commands.music;
+import ca.tristan.easycommands.commands.EasyCommands;
import ca.tristan.easycommands.commands.slash.SlashExecutor;
import ca.tristan.easycommands.commands.EventData;
+import ca.tristan.easycommands.embeds.MusicEB;
import ca.tristan.easycommands.lavaplayer.PlayerManager;
+import net.dv8tion.jda.api.JDA;
+import net.dv8tion.jda.api.entities.channel.Channel;
+import net.dv8tion.jda.api.entities.emoji.Emoji;
+import net.dv8tion.jda.api.interactions.components.buttons.Button;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
public class StopCmd extends SlashExecutor {
@@ -18,16 +26,28 @@ public String getDescription() {
return "Makes the bot leave your channel and clears the current music queue.";
}
+ @Override
+ public List getAuthorizedChannels(JDA jda) {
+ List channels = new ArrayList<>();
+ if(EasyCommands.getMusicChannel() != null) {
+ channels.add(EasyCommands.getMusicChannel());
+ }
+ return channels;
+ }
+
@Override
public void execute(EventData data) {
- data.deferReply();
+
+ MusicEB musicEB = new MusicEB();
if(!data.getMemberVoiceState().inAudioChannel()){
- data.reply("You need to be in a voice channel for this command to work.", true).queue();
+ musicEB.getBuilder().setDescription("You need to be in a voice channel for this command to work.");
+ data.reply(musicEB.getBuilder().build(), true).queue();
return;
}
if(!data.getSelfVoiceState().inAudioChannel()){
- data.reply("I need to be in a voice channel or I need to be playing music for this command to work.", true).queue();
+ musicEB.getBuilder().setDescription("I need to be in a voice channel or I need to be playing music for this command to work.");
+ data.reply(musicEB.getBuilder().build(), true).queue();
return;
}
@@ -35,7 +55,11 @@ public void execute(EventData data) {
PlayerManager.getInstance().getMusicManager(data.getGuild()).scheduler.player.stopTrack();
PlayerManager.getInstance().getMusicManager(data.getGuild()).scheduler.queue.clear();
data.getGuild().getAudioManager().closeAudioConnection();
- data.getHook().sendMessage("The player has been stopped and the queue has been cleared.").queue();
+ musicEB.getBuilder().setDescription("The player has been stopped and the queue has been cleared.");
+ musicEB.getBuilder().addField("Stopped by", data.getCommandSender().getAsMention(), false);
+ data.reply(musicEB.getBuilder().build(), false).setActionRow(
+ Button.link("https://github.com/FrostedCA/EasyCommands", "EasyCommands").withEmoji(Emoji.fromUnicode("✨"))
+ ).queue();
}
}
diff --git a/src/main/java/ca/tristan/easycommands/commands/prefix/PrefixCommands.java b/src/main/java/ca/tristan/easycommands/commands/prefix/PrefixCommands.java
index 5cd9a8e..48ea610 100644
--- a/src/main/java/ca/tristan/easycommands/commands/prefix/PrefixCommands.java
+++ b/src/main/java/ca/tristan/easycommands/commands/prefix/PrefixCommands.java
@@ -45,13 +45,13 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
if(easyCommands.getExecutors().containsKey(cmdName) && easyCommands.getExecutors().get(cmdName) instanceof PrefixExecutor executor) {
String[] options = event.getMessage().getContentRaw().replace(prefix + cmdName + " ", "").split(" ");
- Logger.log(LogType.WARNING, Arrays.toString(options));
for (int i = 0; i < options.length; i++) {
executor.getOptions().get(i).setStringValue(options[i]);
}
Logger.log(LogType.PREFIXCMD, "'" + cmdName + "' has been triggered.");
if(!executor.getAuthorizedChannels(easyCommands.jda).isEmpty() && !executor.getAuthorizedChannels(easyCommands.jda).contains(event.getChannel())) {
+ Logger.log(LogType.WARNING, "PrefixCommand: '" + cmdName + "' has been triggered but the channel it was executed in isn't authorized.");
return;
}
diff --git a/src/main/java/ca/tristan/easycommands/commands/slash/CommandExecutor.java b/src/main/java/ca/tristan/easycommands/commands/slash/CommandExecutor.java
deleted file mode 100644
index efe4d4a..0000000
--- a/src/main/java/ca/tristan/easycommands/commands/slash/CommandExecutor.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package ca.tristan.easycommands.commands.slash;
-
-import ca.tristan.easycommands.commands.EventData;
-import ca.tristan.easycommands.commands.IExecutor;
-import net.dv8tion.jda.api.JDA;
-import net.dv8tion.jda.api.entities.Role;
-import net.dv8tion.jda.api.entities.channel.Channel;
-import net.dv8tion.jda.api.interactions.commands.build.OptionData;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Deprecated
-public abstract class CommandExecutor implements IExecutor {
-
- public List options = new ArrayList<>();
-
- @Override
- public String getName() {
- return null;
- }
-
- @Override
- public List getAliases() {
- return new ArrayList<>();
- }
-
- @Override
- public String getDescription() {
- return null;
- }
-
- @Override
- public boolean isOwnerOnly() {
- return false;
- }
-
- public List getOptions() {
- return options;
- }
-
- @Override
- public List getAuthorizedChannels(JDA jda) {
- return new ArrayList<>();
- }
-
- @Override
- public List getAuthorizedRoles(JDA jda) {
- return new ArrayList<>();
- }
-
- public void execute(EventData data) {
-
- }
-
-}
diff --git a/src/main/java/ca/tristan/easycommands/embeds/MusicEB.java b/src/main/java/ca/tristan/easycommands/embeds/MusicEB.java
new file mode 100644
index 0000000..fe8604c
--- /dev/null
+++ b/src/main/java/ca/tristan/easycommands/embeds/MusicEB.java
@@ -0,0 +1,36 @@
+package ca.tristan.easycommands.embeds;
+
+import net.dv8tion.jda.api.EmbedBuilder;
+import net.dv8tion.jda.api.entities.emoji.Emoji;
+import net.dv8tion.jda.api.interactions.components.buttons.Button;
+
+import java.awt.*;
+import java.util.List;
+
+public class MusicEB {
+
+ private EmbedBuilder builder;
+ private List