From e051c8122129c72029760fdbe40e24ced54481cb Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 01:04:10 +0100 Subject: [PATCH 01/18] A new command? :thinking: --- src/main/java/com/bbn/hadder/Hadder.java | 1 + src/main/resources/Translations/Translations_en.properties | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index f96792f..e6c8972 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -88,6 +88,7 @@ public class Hadder { new AboutCommand(), new LanguageCommand(), new ClydeCommand(), + new PlayCommand(), new StarBoardCommand()), config, helpCommand); builder.addEventListeners( diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index c72b94c..c5b75dc 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -178,6 +178,8 @@ commands.music.leave.success.description = I successfully disconnected from the commands.music.leave.error.tile = Not connected commands.music.leave.error.description = I'm currently in no Voice Channel on this Guild commands.music.leave.help.description = Leaves a voice channel +commands.music.play.success.title = %extra% Now playing %extra% +commands.music.play.success.description = Playing some cool stuff xD commands.nsfw.gif.error.title = GIF not showing? Click here commands.nsfw.img.error.title = Image not showing? Click here From 895d06d7148b03afe4c07f6eba7a172be853cf60 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 09:57:40 +0100 Subject: [PATCH 02/18] Screenshare is back --- src/main/java/com/bbn/hadder/Hadder.java | 4 ++- .../hadder/commands/music/StopCommand.java | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bbn/hadder/commands/music/StopCommand.java diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index e6c8972..9fbd153 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -57,6 +57,7 @@ public class Hadder { new RebootCommand(), new EqualsCommand(), new InviteCommand(), + new ScreenShareCommand(), new NickCommand(), new PrefixCommand(), new BlowjobCommand(), @@ -89,7 +90,8 @@ public class Hadder { new LanguageCommand(), new ClydeCommand(), new PlayCommand(), - new StarBoardCommand()), config, helpCommand); + new StarBoardCommand(), + new StopCommand()), config, helpCommand); builder.addEventListeners( new MentionListener(rethink), diff --git a/src/main/java/com/bbn/hadder/commands/music/StopCommand.java b/src/main/java/com/bbn/hadder/commands/music/StopCommand.java new file mode 100644 index 0000000..da77b5e --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/music/StopCommand.java @@ -0,0 +1,31 @@ +package com.bbn.hadder.commands.music; + +import com.bbn.hadder.commands.Command; +import com.bbn.hadder.commands.CommandEvent; + +/** + * @author Skidder / GregTCLTK + */ + +public class StopCommand implements Command { + + @Override + public void executed(String[] args, CommandEvent event) { + + } + + @Override + public String[] labels() { + return new String[]{"stop"}; + } + + @Override + public String description() { + return "Stops the song"; + } + + @Override + public String usage() { + return ""; + } +} From 4f7f675a8a10105904cd0aa947120d0bc1781dd0 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 11:12:01 +0100 Subject: [PATCH 03/18] Update --- src/main/java/com/bbn/hadder/utils/MessageEditor.java | 2 +- .../resources/Translations/Translations_en.properties | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbn/hadder/utils/MessageEditor.java b/src/main/java/com/bbn/hadder/utils/MessageEditor.java index 2f22d85..c7205f1 100644 --- a/src/main/java/com/bbn/hadder/utils/MessageEditor.java +++ b/src/main/java/com/bbn/hadder/utils/MessageEditor.java @@ -56,7 +56,7 @@ public class MessageEditor { switch (type) { case INFO: builder - .setColor(new Color(47, 94, 105)) + .setColor(new Color(78, 156, 174)) .setFooter("Hadder", "https://bigbotnetwork.com/images/Hadder.png") .setTimestamp(Instant.now()); break; diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index c5b75dc..feb12e4 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -178,8 +178,14 @@ commands.music.leave.success.description = I successfully disconnected from the commands.music.leave.error.tile = Not connected commands.music.leave.error.description = I'm currently in no Voice Channel on this Guild commands.music.leave.help.description = Leaves a voice channel +commands.music.play.load.title = %extra% Now loading %extra% +commands.music.play.load.description = Trying to load the song... commands.music.play.success.title = %extra% Now playing %extra% -commands.music.play.success.description = Playing some cool stuff xD +commands.music.play.success.description = Now playing %extra% +commands.music.play.error.load.title = %extra% Load failed %extra% +commands.music.play.error.load.description = Unfortunately I can not load the given song. +commands.music.play.error.match.title = %extra% No matches %extra% +commands.music.play.error.match.description = I can not find a song named this on YouTube. commands.nsfw.gif.error.title = GIF not showing? Click here commands.nsfw.img.error.title = Image not showing? Click here From b1f82ae79d9a82226d6d3b7836728877834607f0 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 12:24:48 +0100 Subject: [PATCH 04/18] Better Starboard --- .../com/bbn/hadder/commands/moderation/StarBoardCommand.java | 2 +- src/main/resources/Translations/Translations_en.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbn/hadder/commands/moderation/StarBoardCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/StarBoardCommand.java index 50d6987..3371eec 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/StarBoardCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/StarBoardCommand.java @@ -14,7 +14,7 @@ public class StarBoardCommand implements Command { event.getChannel().sendMessage( event.getMessageEditor().getMessage( MessageEditor.MessageType.INFO, - "commands.moderation.starboard.successchannel","") + "commands.moderation.starboard.success.title","") .build()) .queue(); } else { diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index 2fd24e1..dc6faa8 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -162,7 +162,7 @@ commands.moderation.rules.emote.error.equal.description = The 1st and 2nd emote commands.moderation.rules.emoji.decline.description = The first emote has been successfully set. Please send me now the decline emote. commands.moderation.rules.emoji.error.description = The given emote can't be used. commands.moderation.rules.help.description = Setup the rules on your Discord server -commands.moderation.starboard.successchannel=Successfully set the Channel\! +commands.moderation.starboard.success.title = Successfully set the Channel\! commands.music.join.success.title = Successfully connected commands.music.join.success.description = I successfully connected to %extra%. From a7c9578ee545094b1329cb98d3f5526fb5f6562a Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 14:46:21 +0100 Subject: [PATCH 05/18] Music stuff yk --- .../hadder/utils/AudioPlayerSendHandler.java | 25 ------------------- .../Translations/Translations_en.properties | 10 ++++++-- 2 files changed, 8 insertions(+), 27 deletions(-) delete mode 100644 src/main/java/com/bbn/hadder/utils/AudioPlayerSendHandler.java diff --git a/src/main/java/com/bbn/hadder/utils/AudioPlayerSendHandler.java b/src/main/java/com/bbn/hadder/utils/AudioPlayerSendHandler.java deleted file mode 100644 index ff3f483..0000000 --- a/src/main/java/com/bbn/hadder/utils/AudioPlayerSendHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.bbn.hadder.utils; - -/* - * @author Skidder / GregTCLTK - */ - -import net.dv8tion.jda.api.audio.AudioSendHandler; - -import javax.annotation.Nullable; -import java.nio.ByteBuffer; - -public class AudioPlayerSendHandler implements AudioSendHandler { - - @Override - public boolean canProvide() { - return false; - } - - @Nullable - @Override - public ByteBuffer provide20MsAudio() { - - return null; - } -} diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index dc6faa8..078cf78 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -180,12 +180,18 @@ commands.music.leave.error.description = I'm currently in no Voice Channel on th commands.music.leave.help.description = Leaves a voice channel commands.music.play.load.title = %extra% Now loading %extra% commands.music.play.load.description = Trying to load the song... -commands.music.play.success.title = %extra% Now playing %extra% -commands.music.play.success.description = Now playing %extra% +commands.music.play.success.loading.title = %extra% Now playing %extra% commands.music.play.error.load.title = %extra% Load failed %extra% commands.music.play.error.load.description = Unfortunately I can not load the given song. commands.music.play.error.match.title = %extra% No matches %extra% commands.music.play.error.match.description = I can not find a song named this on YouTube. +commands.music.play.success.title = Title +commands.music.play.success.author = Author +commands.music.play.success.length = Length +commands.music.play.help.description = Plays a song +commands.music.stop.success.title = Successfully stopped +commands.music.stop.success.description = I successfully stopped the song. +commands.music.stop.help.description = Stops the playing song commands.nsfw.gif.error.title = GIF not showing? Click here commands.nsfw.img.error.title = Image not showing? Click here From 869c9987ab270fadcd5c6940a0ec70ffdb37cbbc Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 15:25:54 +0100 Subject: [PATCH 06/18] i18n stuff --- src/main/resources/Translations/Translations_en.properties | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index 078cf78..7281940 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -15,6 +15,7 @@ user+nickname = <@user> region = guildid = content = +song = error = Error none = None @@ -173,7 +174,7 @@ commands.music.join.error.connecting.trying.description = Hadder is already tryi commands.music.join.error.channel.title = No Voice Channel commands.music.join.error.channel.description = You aren't in a Voice Channel. commands.music.join.help.description = Joins your voice channel -commands.music.leave.success.title = \= Successfully disconnected +commands.music.leave.success.title = Successfully disconnected commands.music.leave.success.description = I successfully disconnected from the Voice Channel commands.music.leave.error.tile = Not connected commands.music.leave.error.description = I'm currently in no Voice Channel on this Guild @@ -191,7 +192,7 @@ commands.music.play.success.length = Length commands.music.play.help.description = Plays a song commands.music.stop.success.title = Successfully stopped commands.music.stop.success.description = I successfully stopped the song. -commands.music.stop.help.description = Stops the playing song +commands.music.stop.help.description = Stops the song commands.nsfw.gif.error.title = GIF not showing? Click here commands.nsfw.img.error.title = Image not showing? Click here From 7738951911ab1779d9c47bb81b2b47e6029ba6fb Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 15:26:32 +0100 Subject: [PATCH 07/18] AudioPlayerSendHandler leak^^ --- .../hadder/audio/AudioPlayerSendHandler.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/com/bbn/hadder/audio/AudioPlayerSendHandler.java diff --git a/src/main/java/com/bbn/hadder/audio/AudioPlayerSendHandler.java b/src/main/java/com/bbn/hadder/audio/AudioPlayerSendHandler.java new file mode 100644 index 0000000..1863de2 --- /dev/null +++ b/src/main/java/com/bbn/hadder/audio/AudioPlayerSendHandler.java @@ -0,0 +1,49 @@ +package com.bbn.hadder.audio; + +import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; +import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; +import net.dv8tion.jda.api.audio.AudioSendHandler; + +import javax.annotation.Nullable; +import java.nio.ByteBuffer; + +/** + * @author Skidder / GregTCLTK + */ + +public class AudioPlayerSendHandler implements AudioSendHandler { + + private final AudioPlayer audioPlayer; + private AudioFrame lastFrame; + + public AudioPlayerSendHandler(AudioPlayer audioPlayer) { + this.audioPlayer = audioPlayer; + } + + @Override + public boolean canProvide() { + if (lastFrame == null) { + lastFrame = audioPlayer.provide(); + } + + return lastFrame != null; + } + + @Nullable + @Override + public ByteBuffer provide20MsAudio() { + if (lastFrame == null) { + lastFrame = audioPlayer.provide(); + } + + byte[] data = lastFrame != null ? lastFrame.getData() : null; + lastFrame = null; + + return ByteBuffer.wrap(data); + } + + @Override + public boolean isOpus() { + return true; + } +} From 88bff41e9a709510a702d2aa92110fe82ce59152 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 15:30:39 +0100 Subject: [PATCH 08/18] Uh a AudioManager --- src/main/java/com/bbn/hadder/audio/AudioManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/bbn/hadder/audio/AudioManager.java diff --git a/src/main/java/com/bbn/hadder/audio/AudioManager.java b/src/main/java/com/bbn/hadder/audio/AudioManager.java new file mode 100644 index 0000000..b133dca --- /dev/null +++ b/src/main/java/com/bbn/hadder/audio/AudioManager.java @@ -0,0 +1,9 @@ +package com.bbn.hadder.audio; + +/** + * @author Skidder / GregTCLTK + */ + +public class AudioManager { + +} From 7907bedf154dbddbe56dcb015f8927a98825a3b0 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 16:43:37 +0100 Subject: [PATCH 09/18] Fix --- src/main/resources/Translations/Translations_en.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index 7281940..8544d79 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -115,7 +115,7 @@ commands.moderation.kick.success.description = I successfully kicked %extra%. commands.moderation.kick.error.title = Not possible commands.moderation.kick.myself.error.description = I can not kick myself\! commands.moderation.kick.yourself.error.description = You can't kick yourself. -commands.moderation.kick.mass.success.description = I successfully kicked 69 Members\! +commands.moderation.kick.mass.success.description = I successfully kicked %extra% Members\! commands.moderation.kick.help.description = Kicks one or more user from the server. commands.moderation.kick.masskick.success.description = I successfully kicked %extra% members. commands.moderation.link.request.success.description = If i'm on this guild i sent a message to accept the link. From f373b5e9692318f8dc2a5eb8a2c5c6f60c041c2a Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 16:47:37 +0100 Subject: [PATCH 10/18] Music pre-release!!! --- .../java/com/bbn/hadder/audio/AudioInfo.java | 28 +++++ .../com/bbn/hadder/audio/AudioManager.java | 100 ++++++++++++++++ .../com/bbn/hadder/audio/TrackManager.java | 73 ++++++++++++ .../hadder/commands/music/PlayCommand.java | 109 ++++++++++++++++++ .../hadder/commands/music/StopCommand.java | 12 +- 5 files changed, 320 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/bbn/hadder/audio/AudioInfo.java create mode 100644 src/main/java/com/bbn/hadder/audio/TrackManager.java create mode 100644 src/main/java/com/bbn/hadder/commands/music/PlayCommand.java diff --git a/src/main/java/com/bbn/hadder/audio/AudioInfo.java b/src/main/java/com/bbn/hadder/audio/AudioInfo.java new file mode 100644 index 0000000..8aa35e9 --- /dev/null +++ b/src/main/java/com/bbn/hadder/audio/AudioInfo.java @@ -0,0 +1,28 @@ +package com.bbn.hadder.audio; + +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import net.dv8tion.jda.api.entities.Member; + +/** + * @author Skidder / GregTCLTK + */ + +public class AudioInfo { + + private final AudioTrack track; + private final Member author; + + AudioInfo(AudioTrack track, Member author) { + this.track = track; + this.author = author; + } + + public AudioTrack getTrack() { + return track; + } + + public Member getAuthor() { + return author; + } + +} diff --git a/src/main/java/com/bbn/hadder/audio/AudioManager.java b/src/main/java/com/bbn/hadder/audio/AudioManager.java index b133dca..60db2f8 100644 --- a/src/main/java/com/bbn/hadder/audio/AudioManager.java +++ b/src/main/java/com/bbn/hadder/audio/AudioManager.java @@ -1,9 +1,109 @@ package com.bbn.hadder.audio; +import com.bbn.hadder.commands.CommandEvent; +import com.bbn.hadder.utils.MessageEditor; +import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; +import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; +import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; +import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Message; + +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + /** * @author Skidder / GregTCLTK */ public class AudioManager { + public static final Map> players = new HashMap<>(); + public static final AudioPlayerManager myManager = new DefaultAudioPlayerManager(); + + public static void loadTrack(String identifier, CommandEvent event, Message msg) { + + Guild guild = event.getGuild(); + AudioManager.getPlayer(guild); + + myManager.loadItemOrdered(guild, identifier, new AudioLoadResultHandler() { + + @Override + public void trackLoaded(AudioTrack track) { + AudioManager.getTrackManager(guild).queue(track, event.getMember()); + msg.editMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.play.success.loading.title", "⏯", + "", "") + .addField(event.getMessageEditor().getTerm("commands.music.play.success.title"), track.getInfo().title, false) + .addField(event.getMessageEditor().getTerm("commands.music.play.success.author"), track.getInfo().author, true) + .addField(event.getMessageEditor().getTerm("commands.music.play.success.length"), + String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(track.getInfo().length), + TimeUnit.MILLISECONDS.toMinutes(track.getInfo().length) % TimeUnit.HOURS.toMinutes(1), + TimeUnit.MILLISECONDS.toSeconds(track.getInfo().length) % TimeUnit.MINUTES.toSeconds(1)), true) + .build()).queue(); + } + + @Override + public void playlistLoaded(AudioPlaylist playlist) { + if (playlist.getSelectedTrack() != null) { + trackLoaded(playlist.getSelectedTrack()); + } else if (playlist.isSearchResult()) { + trackLoaded(playlist.getTracks().get(0)); + } else { + for (int i = 0; i < Math.min(playlist.getTracks().size(), 200); i++) { + AudioManager.getTrackManager(guild).queue(playlist.getTracks().get(i), event.getMember()); + } + } + } + + @Override + public void noMatches() { + msg.editMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.play.error.match.title", "❌", + "commands.music.play.error.match.description", "") + .build()).queue(); + } + + @Override + public void loadFailed(FriendlyException e) { + msg.editMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.play.error.load.title", "❌", + "commands.music.play.error.load.description", "") + .build()).queue(); + } + }); + } + + public static boolean hasPlayer(Guild guild) { + return players.containsKey(guild.getId()); + } + + public static AudioPlayer getPlayer(Guild guild) { + AudioPlayer p; + if (hasPlayer(guild)) { + p = players.get(guild.getId()).getKey(); + } else { + p = createPlayer(guild); + } + return p; + } + + public static TrackManager getTrackManager(Guild guild) { + return players.get(guild.getId()).getValue(); + } + + public static AudioPlayer createPlayer(Guild guild) { + AudioPlayer nPlayer = myManager.createPlayer(); + TrackManager manager = new TrackManager(nPlayer); + nPlayer.addListener(manager); + guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(nPlayer)); + players.put(guild.getId(), new AbstractMap.SimpleEntry<>(nPlayer, manager)); + return nPlayer; + } + } diff --git a/src/main/java/com/bbn/hadder/audio/TrackManager.java b/src/main/java/com/bbn/hadder/audio/TrackManager.java new file mode 100644 index 0000000..b4c1e9a --- /dev/null +++ b/src/main/java/com/bbn/hadder/audio/TrackManager.java @@ -0,0 +1,73 @@ +package com.bbn.hadder.audio; + +import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; +import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter; +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.VoiceChannel; + +import java.util.*; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * @author Skidder / GregTCLTK + */ + +public class TrackManager extends AudioEventAdapter { + + private final AudioPlayer player; + private final Queue queue; + + public TrackManager(AudioPlayer player) { + this.player = player; + this.queue = new LinkedBlockingQueue<>(); + } + + public void queue(AudioTrack track, Member author) { + AudioInfo info = new AudioInfo(track, author); + queue.add(info); + + if (player.getPlayingTrack() == null) { + player.playTrack(track); + } + } + + @Override + public void onTrackStart(AudioPlayer player, AudioTrack track) { + AudioInfo info = queue.element(); + VoiceChannel vChan = info.getAuthor().getVoiceState().getChannel(); + if (vChan == null) { + player.stopTrack(); + } else { + info.getAuthor().getGuild().getAudioManager().openAudioConnection(vChan); + } + } + + @Override + public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { + Guild g = queue.poll().getAuthor().getGuild(); + if (queue.isEmpty()) { + g.getAudioManager().closeAudioConnection(); + } else { + player.playTrack(queue.element().getTrack()); + } + } + + public Set getQueuedTracks() { + return new LinkedHashSet<>(queue); + } + + public void purgeQueue() { + queue.clear(); + } + + public void remove(AudioInfo entry) { + queue.remove(entry); + } + + public AudioInfo getTrackInfo(AudioTrack track) { + return queue.stream().filter(audioInfo -> audioInfo.getTrack().equals(track)).findFirst().orElse(null); + } +} diff --git a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java new file mode 100644 index 0000000..9e34f3e --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java @@ -0,0 +1,109 @@ +package com.bbn.hadder.commands.music; + +import com.bbn.hadder.audio.AudioInfo; +import com.bbn.hadder.audio.AudioManager; +import com.bbn.hadder.audio.AudioPlayerSendHandler; +import com.bbn.hadder.audio.TrackManager; +import com.bbn.hadder.commands.Command; +import com.bbn.hadder.commands.CommandEvent; +import com.bbn.hadder.utils.MessageEditor; +import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; +import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; +import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; +import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; +import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Message; + +import java.net.URL; +import java.sql.Timestamp; +import java.util.*; +import java.util.concurrent.TimeUnit; + +import static com.bbn.hadder.audio.AudioManager.myManager; + +/** + * @author Skidder / GregTCLTK + */ + +public class PlayCommand implements Command { + + /* + private static final String CD = "\uD83D\uDCBF"; + private static final String MIC = "\uD83C\uDFA4 **|>** "; */ + + @Override + public void executed(String[] args, CommandEvent event) { + if (args.length > 0) { + if (event.getMember().getVoiceState().inVoiceChannel()) { + String input = event.getMessage().getContentRaw().replaceFirst(event.getRethink().getGuildPrefix(event.getGuild().getId()) + "play ", "").replaceFirst(event.getRethink().getUserPrefix(event.getAuthor().getId()) + "play ", ""); + try { + new URL(input).toURI(); + Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.play.load.title", "⭕", + "commands.music.play.load.description", "").build()).complete(); + AudioManager.loadTrack(input, event, msg); + } catch (Exception ignore) { + Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.play.load.title", "⏯", + "commands.music.play.load.description", "").build()).complete(); + AudioManager.loadTrack("ytsearch: " + input, event, msg); + } + } else { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( + MessageEditor.MessageType.WARNING, + "commands.music.join.error.channel.title", + "commands.music.join.error.channel.description") + .build()).queue(); + } + } else event.getHelpCommand().sendHelp(this, event); + + /* OUTSOURCE THIS + Guild guild = event.getGuild(); + if (args.length == 1) { + switch (args[0].toLowerCase()) { + case "info": + if (!hasPlayer(guild) || getPlayer(guild).getPlayingTrack() == null) { // No song is playing + event.getTextChannel().sendMessage("No song is being played at the moment! *It's your time to shine..*").queue(); + } else { + AudioTrack track = getPlayer(guild).getPlayingTrack(); + event.getTextChannel().sendMessage("Track Info" + String.format(QUEUE_DESCRIPTION, CD, getOrNull(track.getInfo().title), + "\n\u23F1 **|>** `[ " + getTimestamp(track.getPosition()) + " / " + getTimestamp(track.getInfo().length) + " ]`", + "\n" + MIC, getOrNull(track.getInfo().author), + "\n\uD83C\uDFA7 **|>** " + "")).queue(); + } + break; + + case "queue": + if (!hasPlayer(guild) || getTrackManager(guild).getQueuedTracks().isEmpty()) { + event.getTextChannel().sendMessage("The queue is empty! Load a song with **" + + "dd" + "music play**!").queue(); + } else { + StringBuilder sb = new StringBuilder(); + Set queue = getTrackManager(guild).getQueuedTracks(); + queue.forEach(audioInfo -> sb.append(buildQueueMessage(audioInfo))); + } + break; + } + } */ + + } + + @Override + public String[] labels() { + return new String[]{"play"}; + } + + @Override + public String description() { + return "commands.music.play.help.description"; + } + + @Override + public String usage() { + return "song"; + } +} diff --git a/src/main/java/com/bbn/hadder/commands/music/StopCommand.java b/src/main/java/com/bbn/hadder/commands/music/StopCommand.java index da77b5e..1adeb88 100644 --- a/src/main/java/com/bbn/hadder/commands/music/StopCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/StopCommand.java @@ -1,7 +1,9 @@ package com.bbn.hadder.commands.music; +import com.bbn.hadder.audio.AudioManager; import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; +import com.bbn.hadder.utils.MessageEditor; /** * @author Skidder / GregTCLTK @@ -11,7 +13,13 @@ public class StopCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { - + AudioManager.players.remove(event.getGuild().getId()); + AudioManager.getPlayer(event.getGuild()).destroy(); + AudioManager.getTrackManager(event.getGuild()).purgeQueue(); + event.getGuild().getAudioManager().closeAudioConnection(); + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.stop.success.title", + "commands.music.stop.success.description").build()).queue(); } @Override @@ -21,7 +29,7 @@ public class StopCommand implements Command { @Override public String description() { - return "Stops the song"; + return "commands.music.stop.help.description"; } @Override From 4814cb00a02e04595e45d0d0b212c7b259b503c9 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 16:50:06 +0100 Subject: [PATCH 11/18] Unused import fix --- .../bbn/hadder/commands/music/PlayCommand.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java index 9e34f3e..37854d0 100644 --- a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java @@ -1,29 +1,13 @@ package com.bbn.hadder.commands.music; -import com.bbn.hadder.audio.AudioInfo; import com.bbn.hadder.audio.AudioManager; -import com.bbn.hadder.audio.AudioPlayerSendHandler; -import com.bbn.hadder.audio.TrackManager; import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.utils.MessageEditor; -import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; -import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; -import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; -import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; -import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; -import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; -import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; -import com.sedmelluq.discord.lavaplayer.track.AudioTrack; -import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; import java.net.URL; -import java.sql.Timestamp; -import java.util.*; -import java.util.concurrent.TimeUnit; -import static com.bbn.hadder.audio.AudioManager.myManager; /** * @author Skidder / GregTCLTK From 29a1b3947d69ac7ed3de9dda782c1a2e0be18cfe Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 20:17:05 +0100 Subject: [PATCH 12/18] Remove Link command strings --- src/main/resources/Translations/Translations_en.properties | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index 8544d79..67a2706 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -118,13 +118,6 @@ commands.moderation.kick.yourself.error.description = You can't kick yourself. commands.moderation.kick.mass.success.description = I successfully kicked %extra% Members\! commands.moderation.kick.help.description = Kicks one or more user from the server. commands.moderation.kick.masskick.success.description = I successfully kicked %extra% members. -commands.moderation.link.request.success.description = If i'm on this guild i sent a message to accept the link. -commands.moderation.link.error.title = Wait that's illegal. -commands.moderation.link.request.error.description = You specified the same guild as the guild on which you're reading this -commands.moderation.link.request.accept.title = ) wants to link guilds\! -commands.moderation.link.request.accept.description = React with the reactions to accept or decline it -commands.moderation.link.set.title = Set the thing boi -commands.moderation.link.help.description = Links two or more servers. commands.moderation.nick.success.title = %extra% Successfully nicked %extra% commands.moderation.nick.success.description = I successfully nicked %extra%. commands.moderation.nick.myself.success.description = I successfully changed my nickname. From d462b0822dce334a8ba42edc25738684b5ed8473 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 20:28:00 +0100 Subject: [PATCH 13/18] Fix --- .../com/bbn/hadder/audio/AudioManager.java | 26 ++++++++++++------- .../hadder/commands/music/PlayCommand.java | 15 ++++++++--- .../hadder/commands/music/StopCommand.java | 6 ++--- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/bbn/hadder/audio/AudioManager.java b/src/main/java/com/bbn/hadder/audio/AudioManager.java index 60db2f8..9f54aab 100644 --- a/src/main/java/com/bbn/hadder/audio/AudioManager.java +++ b/src/main/java/com/bbn/hadder/audio/AudioManager.java @@ -6,6 +6,7 @@ import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; +import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; @@ -23,19 +24,24 @@ import java.util.concurrent.TimeUnit; public class AudioManager { - public static final Map> players = new HashMap<>(); - public static final AudioPlayerManager myManager = new DefaultAudioPlayerManager(); - public static void loadTrack(String identifier, CommandEvent event, Message msg) { + public AudioManager() { + AudioSourceManagers.registerRemoteSources(myManager); + } + + public final Map> players = new HashMap<>(); + public final AudioPlayerManager myManager = new DefaultAudioPlayerManager(); + + public void loadTrack(String identifier, CommandEvent event, Message msg) { Guild guild = event.getGuild(); - AudioManager.getPlayer(guild); + getPlayer(guild); myManager.loadItemOrdered(guild, identifier, new AudioLoadResultHandler() { @Override public void trackLoaded(AudioTrack track) { - AudioManager.getTrackManager(guild).queue(track, event.getMember()); + getTrackManager(guild).queue(track, event.getMember()); msg.editMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, "commands.music.play.success.loading.title", "⏯", "", "") @@ -56,7 +62,7 @@ public class AudioManager { trackLoaded(playlist.getTracks().get(0)); } else { for (int i = 0; i < Math.min(playlist.getTracks().size(), 200); i++) { - AudioManager.getTrackManager(guild).queue(playlist.getTracks().get(i), event.getMember()); + getTrackManager(guild).queue(playlist.getTracks().get(i), event.getMember()); } } } @@ -79,11 +85,11 @@ public class AudioManager { }); } - public static boolean hasPlayer(Guild guild) { + public boolean hasPlayer(Guild guild) { return players.containsKey(guild.getId()); } - public static AudioPlayer getPlayer(Guild guild) { + public AudioPlayer getPlayer(Guild guild) { AudioPlayer p; if (hasPlayer(guild)) { p = players.get(guild.getId()).getKey(); @@ -93,11 +99,11 @@ public class AudioManager { return p; } - public static TrackManager getTrackManager(Guild guild) { + public TrackManager getTrackManager(Guild guild) { return players.get(guild.getId()).getValue(); } - public static AudioPlayer createPlayer(Guild guild) { + public AudioPlayer createPlayer(Guild guild) { AudioPlayer nPlayer = myManager.createPlayer(); TrackManager manager = new TrackManager(nPlayer); nPlayer.addListener(manager); diff --git a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java index 37854d0..a4b8019 100644 --- a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java @@ -1,13 +1,17 @@ package com.bbn.hadder.commands.music; import com.bbn.hadder.audio.AudioManager; +import com.bbn.hadder.audio.TrackManager; import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.utils.MessageEditor; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; +import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; import net.dv8tion.jda.api.entities.Message; import java.net.URL; - +import java.util.*; /** * @author Skidder / GregTCLTK @@ -15,10 +19,14 @@ import java.net.URL; public class PlayCommand implements Command { + private final AudioPlayerManager myManager = new DefaultAudioPlayerManager(); + public final Map> players = new HashMap<>(); + /* private static final String CD = "\uD83D\uDCBF"; private static final String MIC = "\uD83C\uDFA4 **|>** "; */ + @Override public void executed(String[] args, CommandEvent event) { if (args.length > 0) { @@ -29,12 +37,12 @@ public class PlayCommand implements Command { Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, "commands.music.play.load.title", "⭕", "commands.music.play.load.description", "").build()).complete(); - AudioManager.loadTrack(input, event, msg); + new AudioManager().loadTrack(input, event, msg); } catch (Exception ignore) { Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, "commands.music.play.load.title", "⏯", "commands.music.play.load.description", "").build()).complete(); - AudioManager.loadTrack("ytsearch: " + input, event, msg); + new AudioManager().loadTrack("ytsearch: " + input, event, msg); } } else { event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( @@ -45,6 +53,7 @@ public class PlayCommand implements Command { } } else event.getHelpCommand().sendHelp(this, event); + /* OUTSOURCE THIS Guild guild = event.getGuild(); if (args.length == 1) { diff --git a/src/main/java/com/bbn/hadder/commands/music/StopCommand.java b/src/main/java/com/bbn/hadder/commands/music/StopCommand.java index 1adeb88..ab03799 100644 --- a/src/main/java/com/bbn/hadder/commands/music/StopCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/StopCommand.java @@ -13,9 +13,9 @@ public class StopCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { - AudioManager.players.remove(event.getGuild().getId()); - AudioManager.getPlayer(event.getGuild()).destroy(); - AudioManager.getTrackManager(event.getGuild()).purgeQueue(); + new AudioManager().players.remove(event.getGuild().getId()); + new AudioManager().getPlayer(event.getGuild()).destroy(); + new AudioManager().getTrackManager(event.getGuild()).purgeQueue(); event.getGuild().getAudioManager().closeAudioConnection(); event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, "commands.music.stop.success.title", From 7bc151fc48c6f8f06f02b3f97a15ec7d49136f8c Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 20:30:36 +0100 Subject: [PATCH 14/18] Removed unused imports --- .../com/bbn/hadder/commands/music/PlayCommand.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java index a4b8019..118b7a2 100644 --- a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java @@ -1,17 +1,12 @@ package com.bbn.hadder.commands.music; import com.bbn.hadder.audio.AudioManager; -import com.bbn.hadder.audio.TrackManager; import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.utils.MessageEditor; -import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; -import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; -import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; import net.dv8tion.jda.api.entities.Message; import java.net.URL; -import java.util.*; /** * @author Skidder / GregTCLTK @@ -19,9 +14,6 @@ import java.util.*; public class PlayCommand implements Command { - private final AudioPlayerManager myManager = new DefaultAudioPlayerManager(); - public final Map> players = new HashMap<>(); - /* private static final String CD = "\uD83D\uDCBF"; private static final String MIC = "\uD83C\uDFA4 **|>** "; */ @@ -40,7 +32,7 @@ public class PlayCommand implements Command { new AudioManager().loadTrack(input, event, msg); } catch (Exception ignore) { Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, - "commands.music.play.load.title", "⏯", + "commands.music.play.load.title", "⭕", "commands.music.play.load.description", "").build()).complete(); new AudioManager().loadTrack("ytsearch: " + input, event, msg); } From 6ea63342af2e49790ace0678f66c38a0d50c395d Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Dec 2019 20:48:11 +0100 Subject: [PATCH 15/18] Outsource yk --- src/main/java/com/bbn/hadder/Hadder.java | 1 + .../hadder/commands/music/PlayCommand.java | 20 +-------- .../hadder/commands/music/QueueCommand.java | 42 +++++++++++++++++++ 3 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/bbn/hadder/commands/music/QueueCommand.java diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index 9fbd153..c9c2f77 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -91,6 +91,7 @@ public class Hadder { new ClydeCommand(), new PlayCommand(), new StarBoardCommand(), + new QueueCommand(), new StopCommand()), config, helpCommand); builder.addEventListeners( diff --git a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java index 118b7a2..bae30df 100644 --- a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java @@ -18,7 +18,6 @@ public class PlayCommand implements Command { private static final String CD = "\uD83D\uDCBF"; private static final String MIC = "\uD83C\uDFA4 **|>** "; */ - @Override public void executed(String[] args, CommandEvent event) { if (args.length > 0) { @@ -48,9 +47,6 @@ public class PlayCommand implements Command { /* OUTSOURCE THIS Guild guild = event.getGuild(); - if (args.length == 1) { - switch (args[0].toLowerCase()) { - case "info": if (!hasPlayer(guild) || getPlayer(guild).getPlayingTrack() == null) { // No song is playing event.getTextChannel().sendMessage("No song is being played at the moment! *It's your time to shine..*").queue(); } else { @@ -59,21 +55,7 @@ public class PlayCommand implements Command { "\n\u23F1 **|>** `[ " + getTimestamp(track.getPosition()) + " / " + getTimestamp(track.getInfo().length) + " ]`", "\n" + MIC, getOrNull(track.getInfo().author), "\n\uD83C\uDFA7 **|>** " + "")).queue(); - } - break; - - case "queue": - if (!hasPlayer(guild) || getTrackManager(guild).getQueuedTracks().isEmpty()) { - event.getTextChannel().sendMessage("The queue is empty! Load a song with **" - + "dd" + "music play**!").queue(); - } else { - StringBuilder sb = new StringBuilder(); - Set queue = getTrackManager(guild).getQueuedTracks(); - queue.forEach(audioInfo -> sb.append(buildQueueMessage(audioInfo))); - } - break; - } - } */ + }*/ } diff --git a/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java b/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java new file mode 100644 index 0000000..8756e38 --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java @@ -0,0 +1,42 @@ +package com.bbn.hadder.commands.music; + +import com.bbn.hadder.audio.AudioInfo; +import com.bbn.hadder.audio.AudioManager; +import com.bbn.hadder.commands.Command; +import com.bbn.hadder.commands.CommandEvent; +import com.bbn.hadder.utils.MessageEditor; + +import java.util.Set; + +/** + * @author Skidder / GregTCLTK + */ + +public class QueueCommand implements Command { + + @Override + public void executed(String[] args, CommandEvent event) { + if (!new AudioManager().hasPlayer(event.getGuild()) || new AudioManager().getTrackManager(event.getGuild()).getQueuedTracks().isEmpty()) { + event.getTextChannel().sendMessage( + event.getMessageEditor().getMessage(MessageEditor.MessageType.WARNING, "", "").build()).queue(); + } else { + Set queue = new AudioManager().getTrackManager(event.getGuild()).getQueuedTracks(); + // Insert message here + } + } + + @Override + public String[] labels() { + return new String[]{"queue"}; + } + + @Override + public String description() { + return "Shows the music queue."; + } + + @Override + public String usage() { + return ""; + } +} From 1954198f717d4a2d8d5f295abf43ea4876a63963 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2019 13:22:04 +0000 Subject: [PATCH 16/18] Bump JDA from 4.0.0_79 to 4.1.0_81 Bumps JDA from 4.0.0_79 to 4.1.0_81. Signed-off-by: dependabot-preview[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7346825..dbf03e6 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ net.dv8tion JDA - 4.0.0_79 + 4.1.0_81 org.json From ef74e3240bbd2fe9a9ebcd9c2aafad5c94c13215 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Mon, 23 Dec 2019 15:32:34 +0100 Subject: [PATCH 17/18] Queue Command but queue is not working --- .../java/com/bbn/hadder/audio/AudioManager.java | 1 - .../bbn/hadder/commands/music/QueueCommand.java | 16 +++++++++++++--- .../Translations/Translations_en.properties | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbn/hadder/audio/AudioManager.java b/src/main/java/com/bbn/hadder/audio/AudioManager.java index 9f54aab..835800f 100644 --- a/src/main/java/com/bbn/hadder/audio/AudioManager.java +++ b/src/main/java/com/bbn/hadder/audio/AudioManager.java @@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit; public class AudioManager { - public AudioManager() { AudioSourceManagers.registerRemoteSources(myManager); } diff --git a/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java b/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java index 8756e38..d2178f9 100644 --- a/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java @@ -5,6 +5,7 @@ import com.bbn.hadder.audio.AudioManager; import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.utils.MessageEditor; +import net.dv8tion.jda.api.EmbedBuilder; import java.util.Set; @@ -17,11 +18,20 @@ public class QueueCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { if (!new AudioManager().hasPlayer(event.getGuild()) || new AudioManager().getTrackManager(event.getGuild()).getQueuedTracks().isEmpty()) { - event.getTextChannel().sendMessage( - event.getMessageEditor().getMessage(MessageEditor.MessageType.WARNING, "", "").build()).queue(); + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.WARNING, + "commands.music.queue.error.title", + "commands.music.queue.error.description" + ).build()).queue(); } else { Set queue = new AudioManager().getTrackManager(event.getGuild()).getQueuedTracks(); - // Insert message here + EmbedBuilder b = event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.queue.success.title", + "commands.music.queue.success.description") + .addField("Queued songs", String.valueOf(queue.size()), true); + for (AudioInfo g : queue) { + b.addField(g.getTrack().getInfo().author, g.getTrack().getInfo().title, true); + } + event.getTextChannel().sendMessage(b.build()).queue(); } } diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index 67a2706..2be420e 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -186,6 +186,10 @@ commands.music.play.help.description = Plays a song commands.music.stop.success.title = Successfully stopped commands.music.stop.success.description = I successfully stopped the song. commands.music.stop.help.description = Stops the song +commands.music.queue.error.title = No queue +commands.music.queue.error.description = There are no queued songs at the moment +commands.music.queue.success.title = Queue +commands.music.queue.success.description = This is the queue: %extra% commands.nsfw.gif.error.title = GIF not showing? Click here commands.nsfw.img.error.title = Image not showing? Click here From 6c021cd07ae43587afd520efd66d5ed789fedc2a Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Mon, 23 Dec 2019 16:10:49 +0100 Subject: [PATCH 18/18] Info stuff --- src/main/java/com/bbn/hadder/Hadder.java | 1 + .../com/bbn/hadder/audio/AudioManager.java | 4 ++ .../hadder/commands/general/AboutCommand.java | 2 +- .../hadder/commands/music/InfoCommand.java | 57 +++++++++++++++++++ .../hadder/commands/music/PlayCommand.java | 18 ------ 5 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/bbn/hadder/commands/music/InfoCommand.java diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index c9c2f77..f89a23c 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -92,6 +92,7 @@ public class Hadder { new PlayCommand(), new StarBoardCommand(), new QueueCommand(), + new InfoCommand(), new StopCommand()), config, helpCommand); builder.addEventListeners( diff --git a/src/main/java/com/bbn/hadder/audio/AudioManager.java b/src/main/java/com/bbn/hadder/audio/AudioManager.java index 835800f..7c0d6dd 100644 --- a/src/main/java/com/bbn/hadder/audio/AudioManager.java +++ b/src/main/java/com/bbn/hadder/audio/AudioManager.java @@ -111,4 +111,8 @@ public class AudioManager { return nPlayer; } + public String getOrNull(String s) { + return s.isEmpty() ? "N/A" : s; + } + } diff --git a/src/main/java/com/bbn/hadder/commands/general/AboutCommand.java b/src/main/java/com/bbn/hadder/commands/general/AboutCommand.java index 82d17eb..3800836 100644 --- a/src/main/java/com/bbn/hadder/commands/general/AboutCommand.java +++ b/src/main/java/com/bbn/hadder/commands/general/AboutCommand.java @@ -24,7 +24,7 @@ public class AboutCommand implements Command { @Override public String[] labels() { - return new String[]{"about", "info"}; + return new String[]{"about"}; } @Override diff --git a/src/main/java/com/bbn/hadder/commands/music/InfoCommand.java b/src/main/java/com/bbn/hadder/commands/music/InfoCommand.java new file mode 100644 index 0000000..85605b3 --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/music/InfoCommand.java @@ -0,0 +1,57 @@ +package com.bbn.hadder.commands.music; + +import com.bbn.hadder.audio.AudioManager; +import com.bbn.hadder.commands.Command; +import com.bbn.hadder.commands.CommandEvent; +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; + +/** + * @author Skidder / GregTCLTK + */ + +public class InfoCommand implements Command { + + private static final String CD = "\uD83D\uDCBF"; + private static final String MIC = "\uD83C\uDFA4"; + + private static final String QUEUE_TITLE = "__%s has added %d new track%s to the Queue:__"; + private static final String QUEUE_DESCRIPTION = "%s **|>** %s\n%s\n%s %s\n%s"; + private static final String QUEUE_INFO = "Info about the Queue: (Size - %d)"; + private static final String ERROR = "Error while loading \"%s\""; + @Override + public void executed(String[] args, CommandEvent event) { + if (!new AudioManager().hasPlayer(event.getGuild()) || new AudioManager().getPlayer(event.getGuild()).getPlayingTrack() == null) { + event.getTextChannel().sendMessage("No song is being played at the moment! *It's your time to shine..*").queue(); + } else { + AudioTrack track = new AudioManager().getPlayer(event.getGuild()).getPlayingTrack(); + event.getTextChannel().sendMessage("Track Info" + String.format(QUEUE_DESCRIPTION, CD, new AudioManager().getOrNull(track.getInfo().title), + "\n\u23F1 **|>** `[ " + getTimestamp(track.getPosition()) + " / " + getTimestamp(track.getInfo().length) + " ]`", + "\n" + MIC, new AudioManager().getOrNull(track.getInfo().author), + "\n\uD83C\uDFA7 **|>** " + "")).queue(); + } + } + + private String getTimestamp(long milis) { + long seconds = milis / 1000; + long hours = Math.floorDiv(seconds, 3600); + seconds = seconds - (hours * 3600); + long mins = Math.floorDiv(seconds, 60); + seconds = seconds - (mins * 60); + return (hours == 0 ? "" : hours + ":") + String.format("%02d", mins) + ":" + String.format("%02d", seconds); + } + + @Override + public String[] labels() { + return new String[]{"info"}; + } + + @Override + public String description() { + return "Shows information about the playing song"; + } + + @Override + public String usage() { + return ""; + } +} diff --git a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java index bae30df..ddb5c92 100644 --- a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java @@ -14,10 +14,6 @@ import java.net.URL; public class PlayCommand implements Command { - /* - private static final String CD = "\uD83D\uDCBF"; - private static final String MIC = "\uD83C\uDFA4 **|>** "; */ - @Override public void executed(String[] args, CommandEvent event) { if (args.length > 0) { @@ -43,20 +39,6 @@ public class PlayCommand implements Command { .build()).queue(); } } else event.getHelpCommand().sendHelp(this, event); - - - /* OUTSOURCE THIS - Guild guild = event.getGuild(); - if (!hasPlayer(guild) || getPlayer(guild).getPlayingTrack() == null) { // No song is playing - event.getTextChannel().sendMessage("No song is being played at the moment! *It's your time to shine..*").queue(); - } else { - AudioTrack track = getPlayer(guild).getPlayingTrack(); - event.getTextChannel().sendMessage("Track Info" + String.format(QUEUE_DESCRIPTION, CD, getOrNull(track.getInfo().title), - "\n\u23F1 **|>** `[ " + getTimestamp(track.getPosition()) + " / " + getTimestamp(track.getInfo().length) + " ]`", - "\n" + MIC, getOrNull(track.getInfo().author), - "\n\uD83C\uDFA7 **|>** " + "")).queue(); - }*/ - } @Override