@ -35,7 +35,6 @@ import java.nio.file.Path;
|
|||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -95,6 +94,8 @@ public class GuildMusicHandler {
|
|||||||
private ReactionHandler reactionHandler;
|
private ReactionHandler reactionHandler;
|
||||||
private long guildId;
|
private long guildId;
|
||||||
|
|
||||||
|
private GuildPlaylist currentPlaylist;
|
||||||
|
|
||||||
public GuildMusicHandler(Path musicDir, long guildId, Mp3UploadHandler uploadHandler, ReactionHandler reactionHandler, GuildSongRepoService guildSongRepoService) throws IOException {
|
public GuildMusicHandler(Path musicDir, long guildId, Mp3UploadHandler uploadHandler, ReactionHandler reactionHandler, GuildSongRepoService guildSongRepoService) throws IOException {
|
||||||
this.logger = ApplicationLoggerFactory.getLogger(GuildMusicHandler.class);
|
this.logger = ApplicationLoggerFactory.getLogger(GuildMusicHandler.class);
|
||||||
this.playing = new AtomicBoolean(false);
|
this.playing = new AtomicBoolean(false);
|
||||||
@ -113,6 +114,26 @@ public class GuildMusicHandler {
|
|||||||
player.addListener(ts);
|
player.addListener(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void playlist(GuildMessageReceivedEvent event, List<String> commands) throws Exception {
|
||||||
|
|
||||||
|
String command = commands.remove(0);
|
||||||
|
|
||||||
|
switch(command) {
|
||||||
|
case "add":
|
||||||
|
addPlayList(event, commands);
|
||||||
|
return;
|
||||||
|
case "delete":
|
||||||
|
deletePlayList(event, commands);
|
||||||
|
return;
|
||||||
|
case "list":
|
||||||
|
listPlayList(event, commands);
|
||||||
|
return;
|
||||||
|
case "play":
|
||||||
|
playPlayList(event, commands);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Long getCurrentVoiceChannelId() {
|
public Long getCurrentVoiceChannelId() {
|
||||||
return voiceChannelId;
|
return voiceChannelId;
|
||||||
}
|
}
|
||||||
@ -186,14 +207,21 @@ public class GuildMusicHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
playing.set(false);
|
playing.set(false);
|
||||||
stop(event);
|
stop(event, true);
|
||||||
play(event, commands);
|
play(event, commands);
|
||||||
playing.set(true);
|
playing.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(GuildMessageReceivedEvent event) {
|
public void stop(GuildMessageReceivedEvent event) {
|
||||||
|
stop(event, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop(GuildMessageReceivedEvent event, boolean stoppedFromRepeat) {
|
||||||
player.stopTrack();
|
player.stopTrack();
|
||||||
voiceChannelId = null;
|
voiceChannelId = null;
|
||||||
|
if (!stoppedFromRepeat) {
|
||||||
|
currentPlaylist = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void play(GuildMessageReceivedEvent event) throws Exception {
|
public void play(GuildMessageReceivedEvent event) throws Exception {
|
||||||
@ -237,7 +265,7 @@ public class GuildMusicHandler {
|
|||||||
event.getChannel().sendMessageFormat("Unable to find song with identifier: %s", uuid).queue();
|
event.getChannel().sendMessageFormat("Unable to find song with identifier: %s", uuid).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stop(event);
|
stop(event, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ts.hasTracks()) {
|
if (!ts.hasTracks()) {
|
||||||
@ -300,6 +328,30 @@ public class GuildMusicHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void playPlayList(GuildMessageReceivedEvent event, List<String> commands) throws Exception {
|
||||||
|
if (commands == null || commands.isEmpty()) {
|
||||||
|
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " please provide the name of the playlist to play").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String playlist = commands.remove(0);
|
||||||
|
currentPlaylist = guildSongRepoService.getGuildPlaylistRepo().findByGuildAndUserIdAndPlaylist(guildId, event.getMember().getIdLong(), playlist);
|
||||||
|
if (currentPlaylist == null) {
|
||||||
|
event.getChannel().sendMessage(event.getAuthor().getAsMention() + ", no playlist with the name of " + playlist + " exists").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ts.clearTracks();
|
||||||
|
|
||||||
|
for(GuildPlaylistSong gpls : guildSongRepoService.getGuildPlaylistSongRepo().findByGuildPlaylist(currentPlaylist)) {
|
||||||
|
Song s = gpls.getGuildSong().getSong();
|
||||||
|
apm.loadItem(s.getFilePath(), ts).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
playing.set(false);
|
||||||
|
play(event);
|
||||||
|
playing.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
private MessageEmbed error(GuildMessageReceivedEvent event, Throwable ex, String fileName) {
|
private MessageEmbed error(GuildMessageReceivedEvent event, Throwable ex, String fileName) {
|
||||||
return new EmbedBuilder()
|
return new EmbedBuilder()
|
||||||
.setTitle("Unable to upload file: " + fileName)
|
.setTitle("Unable to upload file: " + fileName)
|
||||||
@ -418,7 +470,13 @@ public class GuildMusicHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadRandomSong() throws Exception {
|
private void loadRandomSong() throws Exception {
|
||||||
List<GuildSong> gsList = guildSongRepoService.getGuildSongRepo().findByGuild(guildId);
|
List<GuildSong> gsList = null;
|
||||||
|
|
||||||
|
if (currentPlaylist == null) {
|
||||||
|
gsList = guildSongRepoService.getGuildSongRepo().findByGuild(guildId);
|
||||||
|
} else {
|
||||||
|
gsList = guildSongRepoService.getGuildPlaylistSongRepo().findByGuildPlaylist(currentPlaylist).stream().map(gpl -> gpl.getGuildSong()).collect(Collectors.toList());
|
||||||
|
}
|
||||||
if (gsList == null || gsList.isEmpty()) return;
|
if (gsList == null || gsList.isEmpty()) return;
|
||||||
|
|
||||||
Random random = new Random(System.currentTimeMillis());
|
Random random = new Random(System.currentTimeMillis());
|
||||||
@ -438,24 +496,6 @@ public class GuildMusicHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playlist(GuildMessageReceivedEvent event, List<String> commands) {
|
|
||||||
|
|
||||||
String command = commands.remove(0);
|
|
||||||
|
|
||||||
switch(command) {
|
|
||||||
case "add":
|
|
||||||
addPlayList(event, commands);
|
|
||||||
return;
|
|
||||||
case "delete":
|
|
||||||
deletePlayList(event, commands);
|
|
||||||
return;
|
|
||||||
case "list":
|
|
||||||
listPlayList(event, commands);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void listPlayList(GuildMessageReceivedEvent event, List<String> commands) {
|
private void listPlayList(GuildMessageReceivedEvent event, List<String> commands) {
|
||||||
if (commands == null || commands.isEmpty()) {
|
if (commands == null || commands.isEmpty()) {
|
||||||
List<GuildPlaylist> userPlaylist = guildSongRepoService.getGuildPlaylistRepo().findByGuildAndUserIdFetchSongs(event.getGuild().getIdLong(), event.getMember().getIdLong());
|
List<GuildPlaylist> userPlaylist = guildSongRepoService.getGuildPlaylistRepo().findByGuildAndUserIdFetchSongs(event.getGuild().getIdLong(), event.getMember().getIdLong());
|
||||||
|
@ -79,6 +79,10 @@ public class TrackScheduler extends AudioEventAdapter implements AudioEventListe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearTracks() {
|
||||||
|
trackQueue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void noMatches() {
|
public void noMatches() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
@ -107,5 +111,4 @@ public class TrackScheduler extends AudioEventAdapter implements AudioEventListe
|
|||||||
return started;
|
return started;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user