From b6d8a07ecbfc9fa5298d25c00a8af5e50f5b4a3d Mon Sep 17 00:00:00 2001 From: BrokenFire Date: Sun, 18 Feb 2018 22:50:08 +0100 Subject: [PATCH 1/2] Adding info for Jenkisfile merge --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf971aa..524ffd8 100644 --- a/README.md +++ b/README.md @@ -68,5 +68,14 @@ Devel:
[![Build Status](https://jenkins.seb6596.ovh/buildStatus/icon?job=Br > internal: > external: false > ``` -> Docker hub [repo](https://hub.docker.com/r/brokenfire/brokendiscordbot/) +> Docker hub [repo](https://hub.docker.com/r/brokenfire/brokendiscordbot/) + +#### Jenkisfile +`git config --global merge.ours.driver true` + +``` +[merge "ours"] + name = "Keep ours merge" + driver = true +``` From 1dbedf3e35c23254dbc554b5e811045d762d5600 Mon Sep 17 00:00:00 2001 From: BrokenFire Date: Mon, 19 Feb 2018 18:08:54 +0100 Subject: [PATCH 2/2] Adding who submitted the track #8 and corrent info modal #9 --- .../net/Broken/RestApi/CommandInterface.java | 3 +- .../java/net/Broken/RestApi/Commands/Add.java | 5 ++- .../net/Broken/RestApi/Commands/Connect.java | 3 +- .../net/Broken/RestApi/Commands/Dell.java | 3 +- .../net/Broken/RestApi/Commands/Flush.java | 3 +- .../net/Broken/RestApi/Commands/Next.java | 3 +- .../net/Broken/RestApi/Commands/Pause.java | 3 +- .../net/Broken/RestApi/Commands/Play.java | 3 +- .../net/Broken/RestApi/Commands/Stop.java | 3 +- .../Broken/RestApi/Data/CurrentMusicData.java | 6 +-- .../net/Broken/RestApi/Data/PlaylistData.java | 6 +-- .../RestApi/Data/UserAudioTrackData.java | 35 ++++++++++++++++ .../Broken/RestApi/MusicWebAPIController.java | 7 ++-- src/main/java/net/Broken/audio/AudioM.java | 26 +++++++----- .../java/net/Broken/audio/TrackScheduler.java | 40 +++++++++++++------ .../java/net/Broken/audio/UserAudioTrack.java | 22 ++++++++++ .../java/net/Broken/audio/WebLoadUtils.java | 8 ++-- src/main/resources/static/js/music.js | 25 +++++++----- src/main/resources/templates/music.html | 6 ++- 19 files changed, 153 insertions(+), 57 deletions(-) create mode 100644 src/main/java/net/Broken/RestApi/Data/UserAudioTrackData.java create mode 100644 src/main/java/net/Broken/audio/UserAudioTrack.java diff --git a/src/main/java/net/Broken/RestApi/CommandInterface.java b/src/main/java/net/Broken/RestApi/CommandInterface.java index 6e83427..0e46caf 100644 --- a/src/main/java/net/Broken/RestApi/CommandInterface.java +++ b/src/main/java/net/Broken/RestApi/CommandInterface.java @@ -3,8 +3,9 @@ package net.Broken.RestApi; import net.Broken.Commands.Music; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; +import net.dv8tion.jda.core.entities.User; import org.springframework.http.ResponseEntity; public interface CommandInterface { - ResponseEntity action(Music musicCommande, CommandPostData data); + ResponseEntity action(Music musicCommande, CommandPostData data, User user); } diff --git a/src/main/java/net/Broken/RestApi/Commands/Add.java b/src/main/java/net/Broken/RestApi/Commands/Add.java index ae36e38..fec1b6a 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Add.java +++ b/src/main/java/net/Broken/RestApi/Commands/Add.java @@ -5,11 +5,12 @@ import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.audio.WebLoadUtils; +import net.dv8tion.jda.core.entities.User; import org.springframework.http.ResponseEntity; public class Add implements CommandInterface { @Override - public ResponseEntity action(Music musicCommande, CommandPostData data) { - return new WebLoadUtils(musicCommande ,data).getResponse(); + public ResponseEntity action(Music musicCommande, CommandPostData data, User user) { + return new WebLoadUtils(musicCommande ,data, user).getResponse(); } } diff --git a/src/main/java/net/Broken/RestApi/Commands/Connect.java b/src/main/java/net/Broken/RestApi/Commands/Connect.java index ba307b2..9cf8967 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Connect.java +++ b/src/main/java/net/Broken/RestApi/Commands/Connect.java @@ -5,13 +5,14 @@ import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.audio.AudioM; +import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.entities.VoiceChannel; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; public class Connect implements CommandInterface{ @Override - public ResponseEntity action(Music musicCommande, CommandPostData data) { + public ResponseEntity action(Music musicCommande, CommandPostData data, User user) { AudioM audioM = musicCommande.getAudioManager(); if(data.chanelId == null) return new ResponseEntity<>(new CommandResponseData(data.command,"Missing chanelId"),HttpStatus.BAD_REQUEST); diff --git a/src/main/java/net/Broken/RestApi/Commands/Dell.java b/src/main/java/net/Broken/RestApi/Commands/Dell.java index cb7fbc3..fff542f 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Dell.java +++ b/src/main/java/net/Broken/RestApi/Commands/Dell.java @@ -6,12 +6,13 @@ import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.audio.NotConectedException; import net.Broken.audio.NullMusicManager; +import net.dv8tion.jda.core.entities.User; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; public class Dell implements CommandInterface { @Override - public ResponseEntity action(Music musicCommande, CommandPostData data) { + public ResponseEntity action(Music musicCommande, CommandPostData data, User user) { if(data.url != null) { try { if(musicCommande.getAudioManager().getMusicManager().scheduler.remove(data.url)){ diff --git a/src/main/java/net/Broken/RestApi/Commands/Flush.java b/src/main/java/net/Broken/RestApi/Commands/Flush.java index 25c598f..0bf7e3a 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Flush.java +++ b/src/main/java/net/Broken/RestApi/Commands/Flush.java @@ -6,12 +6,13 @@ import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.audio.NotConectedException; import net.Broken.audio.NullMusicManager; +import net.dv8tion.jda.core.entities.User; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; public class Flush implements CommandInterface { @Override - public ResponseEntity action(Music musicCommande, CommandPostData data) { + public ResponseEntity action(Music musicCommande, CommandPostData data, User user) { try { musicCommande.getAudioManager().getMusicManager().scheduler.flush(); return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK); diff --git a/src/main/java/net/Broken/RestApi/Commands/Next.java b/src/main/java/net/Broken/RestApi/Commands/Next.java index 2338649..d056cd3 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Next.java +++ b/src/main/java/net/Broken/RestApi/Commands/Next.java @@ -6,12 +6,13 @@ import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.audio.NotConectedException; import net.Broken.audio.NullMusicManager; +import net.dv8tion.jda.core.entities.User; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; public class Next implements CommandInterface { @Override - public ResponseEntity action(Music musicCommande, CommandPostData data) { + public ResponseEntity action(Music musicCommande, CommandPostData data, User user) { try { musicCommande.getAudioManager().getMusicManager().scheduler.nextTrack(); return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK); diff --git a/src/main/java/net/Broken/RestApi/Commands/Pause.java b/src/main/java/net/Broken/RestApi/Commands/Pause.java index 89a1c91..f097cb0 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Pause.java +++ b/src/main/java/net/Broken/RestApi/Commands/Pause.java @@ -6,12 +6,13 @@ import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.audio.NotConectedException; import net.Broken.audio.NullMusicManager; +import net.dv8tion.jda.core.entities.User; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; public class Pause implements CommandInterface { @Override - public ResponseEntity action(Music musicCommande, CommandPostData data) { + public ResponseEntity action(Music musicCommande, CommandPostData data, User user) { try { musicCommande.getAudioManager().getMusicManager().scheduler.pause(); return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK); diff --git a/src/main/java/net/Broken/RestApi/Commands/Play.java b/src/main/java/net/Broken/RestApi/Commands/Play.java index 9a03f94..6ea06ef 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Play.java +++ b/src/main/java/net/Broken/RestApi/Commands/Play.java @@ -6,12 +6,13 @@ import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; import net.Broken.audio.NotConectedException; import net.Broken.audio.NullMusicManager; +import net.dv8tion.jda.core.entities.User; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; public class Play implements CommandInterface { @Override - public ResponseEntity action(Music musicCommande, CommandPostData data) { + public ResponseEntity action(Music musicCommande, CommandPostData data, User user) { try { musicCommande.getAudioManager().getMusicManager().scheduler.resume(); return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK); diff --git a/src/main/java/net/Broken/RestApi/Commands/Stop.java b/src/main/java/net/Broken/RestApi/Commands/Stop.java index 7e5958c..387ce38 100644 --- a/src/main/java/net/Broken/RestApi/Commands/Stop.java +++ b/src/main/java/net/Broken/RestApi/Commands/Stop.java @@ -4,13 +4,14 @@ import net.Broken.Commands.Music; import net.Broken.RestApi.CommandInterface; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; +import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; public class Stop implements CommandInterface { @Override - public ResponseEntity action(Music musicCommande, CommandPostData data) { + public ResponseEntity action(Music musicCommande, CommandPostData data, User user) { musicCommande.getAudioManager().stop((MessageReceivedEvent) null); return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK); diff --git a/src/main/java/net/Broken/RestApi/Data/CurrentMusicData.java b/src/main/java/net/Broken/RestApi/Data/CurrentMusicData.java index 6b2e92a..9e23a62 100644 --- a/src/main/java/net/Broken/RestApi/Data/CurrentMusicData.java +++ b/src/main/java/net/Broken/RestApi/Data/CurrentMusicData.java @@ -8,20 +8,20 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackState; @JsonInclude(JsonInclude.Include.NON_NULL) public class CurrentMusicData { - private final AudioTrackInfo info; + private final UserAudioTrackData info; private final long currentPos; private final String state; private final boolean pause; - public CurrentMusicData(AudioTrackInfo info, long currentPos, String state, boolean pause) { + public CurrentMusicData(UserAudioTrackData info, long currentPos, String state, boolean pause) { this.info = info; this.currentPos = currentPos; this.state = state; this.pause = pause; } - public AudioTrackInfo getInfo() { + public UserAudioTrackData getInfo() { return info; } diff --git a/src/main/java/net/Broken/RestApi/Data/PlaylistData.java b/src/main/java/net/Broken/RestApi/Data/PlaylistData.java index 04f5000..97992aa 100644 --- a/src/main/java/net/Broken/RestApi/Data/PlaylistData.java +++ b/src/main/java/net/Broken/RestApi/Data/PlaylistData.java @@ -6,13 +6,13 @@ import java.util.List; public class PlaylistData { - private List list; + private List list; - public PlaylistData(List list) { + public PlaylistData(List list) { this.list = list; } - public List getList() { + public List getList() { return list; } } diff --git a/src/main/java/net/Broken/RestApi/Data/UserAudioTrackData.java b/src/main/java/net/Broken/RestApi/Data/UserAudioTrackData.java new file mode 100644 index 0000000..d834fa0 --- /dev/null +++ b/src/main/java/net/Broken/RestApi/Data/UserAudioTrackData.java @@ -0,0 +1,35 @@ +package net.Broken.RestApi.Data; + +import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo; +import net.Broken.audio.UserAudioTrack; + +public class UserAudioTrackData { + private String user; + private AudioTrackInfo audioTrackInfo; + + public UserAudioTrackData(String user, AudioTrackInfo audioTrackInfo) { + this.user = user; + this.audioTrackInfo = audioTrackInfo; + } + + public UserAudioTrackData(UserAudioTrack userAudioTrack){ + this.audioTrackInfo = userAudioTrack.getAudioTrack().getInfo(); + this.user = userAudioTrack.getSubmitedUser().getName(); + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public AudioTrackInfo getAudioTrackInfo() { + return audioTrackInfo; + } + + public void setAudioTrackInfo(AudioTrackInfo audioTrackInfo) { + this.audioTrackInfo = audioTrackInfo; + } +} diff --git a/src/main/java/net/Broken/RestApi/MusicWebAPIController.java b/src/main/java/net/Broken/RestApi/MusicWebAPIController.java index 987b7fd..f282132 100644 --- a/src/main/java/net/Broken/RestApi/MusicWebAPIController.java +++ b/src/main/java/net/Broken/RestApi/MusicWebAPIController.java @@ -57,7 +57,8 @@ public class MusicWebAPIController { { return new CurrentMusicData(null,0, "STOP",false); } - return new CurrentMusicData(currentTrack.getInfo(),currentTrack.getPosition(), currentTrack.getState().toString(), player.isPaused()); + UserAudioTrackData uat = new UserAudioTrackData(musicCommande.audio.getMusicManager().scheduler.getCurrentPlayingTrack()); + return new CurrentMusicData(uat, currentTrack.getPosition(), currentTrack.getState().toString(), player.isPaused()); } catch (NullMusicManager | NotConectedException nullMusicManager) { return new CurrentMusicData(null,0, "STOP",false); } @@ -70,7 +71,7 @@ public class MusicWebAPIController { @RequestMapping("/getPlaylist") public PlaylistData getPlaylist(){ Music musicCommande = (Music) MainBot.commandes.get("music"); - List list = null; + List list = null; try { list = musicCommande.getAudioManager().getMusicManager().scheduler.getList(); return new PlaylistData(list); @@ -90,7 +91,7 @@ public class MusicWebAPIController { Music musicCommande = (Music) MainBot.commandes.get("music"); if (ApiCommandLoader.apiCommands.containsKey(data.command)) - return ApiCommandLoader.apiCommands.get(data.command).action(musicCommande, data); + return ApiCommandLoader.apiCommands.get(data.command).action(musicCommande, data, MainBot.jda.getUserById(user.getJdaId())); else return new ResponseEntity<>(new CommandResponseData(data.command, "Unknown Command", "command"), HttpStatus.BAD_REQUEST); diff --git a/src/main/java/net/Broken/audio/AudioM.java b/src/main/java/net/Broken/audio/AudioM.java index d608d67..0180c04 100644 --- a/src/main/java/net/Broken/audio/AudioM.java +++ b/src/main/java/net/Broken/audio/AudioM.java @@ -4,21 +4,25 @@ import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; 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.source.youtube.YoutubeAudioSourceManager; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo; import net.Broken.MainBot; +import net.Broken.RestApi.Data.UserAudioTrackData; import net.Broken.Tools.EmbedMessageUtils; import net.Broken.Tools.MessageTimeOut; import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.Message; +import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.entities.VoiceChannel; import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import javax.jws.soap.SOAPBinding; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -51,7 +55,7 @@ public class AudioM { @Override public void trackLoaded(AudioTrack track) { logger.info("Single Track detected!"); - + UserAudioTrack uat = new UserAudioTrack(event.getAuthor(), track); Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Ajout de "+track.getInfo().title+" à la file d'attente!")).complete(); List messages = new ArrayList(){{ add(message); @@ -59,7 +63,7 @@ public class AudioM { }}; new MessageTimeOut(messages, MainBot.messageTimeOut).start(); - play(guild, voiceChannel, musicManager, track, onHead); + play(guild, voiceChannel, musicManager, uat, onHead); } @Override @@ -74,7 +78,7 @@ public class AudioM { }}; new MessageTimeOut(messages, MainBot.messageTimeOut).start(); - playListLoader(playlist, playlistLimit, onHead); + playListLoader(playlist, playlistLimit ,event.getAuthor() , onHead); @@ -105,14 +109,15 @@ public class AudioM { }); } - public void playListLoader(AudioPlaylist playlist,int playlistLimit, boolean onHead){ + public void playListLoader(AudioPlaylist playlist, int playlistLimit, User user, boolean onHead){ int i = 0; List tracks = playlist.getTracks(); if(onHead) Collections.reverse(tracks); for(AudioTrack track : playlist.getTracks()){ - play(guild, playedChanel, musicManager, track, onHead); + UserAudioTrack uat = new UserAudioTrack(user, track); + play(guild, playedChanel, musicManager, uat, onHead); i++; if((i>=playlistLimit && i!=-1) || i>listExtremLimit) break; @@ -130,7 +135,7 @@ public class AudioM { return musicManager; } - public void play(Guild guild, VoiceChannel channel, GuildMusicManager musicManager, AudioTrack track,boolean onHead) { + public void play(Guild guild, VoiceChannel channel, GuildMusicManager musicManager, UserAudioTrack track,boolean onHead) { if(!guild.getAudioManager().isConnected()) guild.getAudioManager().openAudioConnection(channel); if(!onHead) @@ -178,8 +183,9 @@ public class AudioM { public void info(MessageReceivedEvent event){ GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild()); AudioTrackInfo info = musicManager.scheduler.getInfo(); + UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack(); - Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk(info.title+"\n"+info.uri)).complete(); + Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk(info.title+"\n"+info.uri+"\nSubmitted by: "+userAudioTrack.getSubmitedUser().getName())).complete(); List messages = new ArrayList(){{ add(message); add(event.getMessage()); @@ -200,16 +206,16 @@ public class AudioM { public void list(MessageReceivedEvent event){ GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild()); - List list = musicManager.scheduler.getList(); + List list = musicManager.scheduler.getList(); StringBuilder resp = new StringBuilder(); if(list.size() == 0){ resp.append("Oh mon dieux!\nElle est vide! \n:astonished: "); } else { - for(AudioTrackInfo trackInfo : list){ + for(UserAudioTrackData trackInfo : list){ resp.append("- "); - resp.append(trackInfo.title); + resp.append(trackInfo.getAudioTrackInfo().title); resp.append("\n"); } } diff --git a/src/main/java/net/Broken/audio/TrackScheduler.java b/src/main/java/net/Broken/audio/TrackScheduler.java index 6b6e0e5..1c032f5 100644 --- a/src/main/java/net/Broken/audio/TrackScheduler.java +++ b/src/main/java/net/Broken/audio/TrackScheduler.java @@ -5,6 +5,7 @@ import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason; import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo; +import net.Broken.RestApi.Data.UserAudioTrackData; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -20,7 +21,8 @@ import java.util.concurrent.LinkedBlockingQueue; */ public class TrackScheduler extends AudioEventAdapter { private final AudioPlayer player; - private final BlockingDeque queue; + private final BlockingDeque queue; + private UserAudioTrack currentPlayingTrack; Logger logger = LogManager.getLogger(); /** @@ -30,6 +32,7 @@ public class TrackScheduler extends AudioEventAdapter { this.player = player; player.setVolume(25); this.queue = new LinkedBlockingDeque<>(); + this.currentPlayingTrack = null; } /** @@ -37,21 +40,27 @@ public class TrackScheduler extends AudioEventAdapter { * * @param track The track to play or add to queue. */ - public void queue(AudioTrack track) { + public void queue(UserAudioTrack track) { // Calling startTrack with the noInterrupt set to true will start the track only if nothing is currently playing. If // something is playing, it returns false and does nothing. In that case the player was already playing so this // track goes to the queue instead. - if (!player.startTrack(track, true)) { + if (!player.startTrack(track.getAudioTrack(), true)) { queue.offer(track); } + else{ + currentPlayingTrack = track; + } } - public void addNext(AudioTrack track) { + public void addNext(UserAudioTrack track) { // Calling startTrack with the noInterrupt set to true will start the track only if nothing is currently playing. If // something is playing, it returns false and does nothing. In that case the player was already playing so this // track goes to the queue instead. - if (!player.startTrack(track, true)) { + if (!player.startTrack(track.getAudioTrack(), true)) { queue.addFirst(track); } + else{ + currentPlayingTrack = track; + } } public void pause() { @@ -65,6 +74,7 @@ public class TrackScheduler extends AudioEventAdapter { public void stop(){ player.stopTrack(); + this.currentPlayingTrack = null; player.destroy(); } @@ -72,14 +82,14 @@ public class TrackScheduler extends AudioEventAdapter { queue.clear(); } - public List getList(){ + public List getList(){ // AudioTrack[] test = (AudioTrack[]) queue.toArray(); - List temp = new ArrayList<>(); + List temp = new ArrayList<>(); Object[] test = queue.toArray(); for(Object track: test){ - AudioTrack casted = (AudioTrack) track; - temp.add(casted.getInfo()); + UserAudioTrack casted = (UserAudioTrack) track; + temp.add(new UserAudioTrackData(casted.getSubmitedUser().getName(), casted.getAudioTrack().getInfo())); } return temp; } @@ -88,9 +98,13 @@ public class TrackScheduler extends AudioEventAdapter { return player.getPlayingTrack().getInfo(); } + public UserAudioTrack getCurrentPlayingTrack() { + return currentPlayingTrack; + } + public boolean remove(String uri){ - for(AudioTrack track : queue){ - if(track.getInfo().uri.equals(uri)){ + for(UserAudioTrack track : queue){ + if(track.getAudioTrack().getInfo().uri.equals(uri)){ if(!queue.remove(track)) { logger.info("Delete failure!"); return false; @@ -110,7 +124,9 @@ public class TrackScheduler extends AudioEventAdapter { public void nextTrack() { // Start the next track, regardless of if something is already playing or not. In case queue was empty, we are // giving null to startTrack, which is a valid argument and will simply stop the player. - player.startTrack(queue.poll(), false); + UserAudioTrack track = queue.poll(); + this.currentPlayingTrack = track; + player.startTrack(track.getAudioTrack(), false); } @Override diff --git a/src/main/java/net/Broken/audio/UserAudioTrack.java b/src/main/java/net/Broken/audio/UserAudioTrack.java new file mode 100644 index 0000000..85fbc8a --- /dev/null +++ b/src/main/java/net/Broken/audio/UserAudioTrack.java @@ -0,0 +1,22 @@ +package net.Broken.audio; + +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import net.dv8tion.jda.core.entities.User; + +public class UserAudioTrack{ + private User user; + private AudioTrack audioTrack; + + public UserAudioTrack(User user, AudioTrack audioTrack) { + this.user = user; + this.audioTrack = audioTrack; + } + + public User getSubmitedUser() { + return user; + } + + public AudioTrack getAudioTrack() { + return audioTrack; + } +} diff --git a/src/main/java/net/Broken/audio/WebLoadUtils.java b/src/main/java/net/Broken/audio/WebLoadUtils.java index dd9c56c..3a5bf50 100644 --- a/src/main/java/net/Broken/audio/WebLoadUtils.java +++ b/src/main/java/net/Broken/audio/WebLoadUtils.java @@ -8,6 +8,7 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import net.Broken.Commands.Music; import net.Broken.RestApi.Data.CommandPostData; import net.Broken.RestApi.Data.CommandResponseData; +import net.dv8tion.jda.core.entities.User; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.http.HttpStatus; @@ -17,7 +18,7 @@ public class WebLoadUtils { ResponseEntity response; Logger logger = LogManager.getLogger(); - public WebLoadUtils(Music musicCommande, CommandPostData data){ + public WebLoadUtils(Music musicCommande, CommandPostData data, User user){ AudioPlayerManager playerM = musicCommande.getAudioManager().getPlayerManager(); try { @@ -28,7 +29,8 @@ public class WebLoadUtils { logger.info("Single Track detected from web!"); try { - audioM.play(audioM.getGuild(), audioM.getPlayedChanel(), audioM.getMusicManager(), track, data.onHead); + UserAudioTrack userAudioTrack = new UserAudioTrack(user, track); //TODO + audioM.play(audioM.getGuild(), audioM.getPlayedChanel(), audioM.getMusicManager(), userAudioTrack, data.onHead); response = new ResponseEntity<>(new CommandResponseData("ADD", "Loaded"), HttpStatus.OK); } catch (NullMusicManager | NotConectedException nullMusicManager) { nullMusicManager.printStackTrace(); @@ -40,7 +42,7 @@ public class WebLoadUtils { public void playlistLoaded(AudioPlaylist playlist) { logger.info("Playlist detected from web! Limit: " + data.playlistLimit); - audioM.playListLoader(playlist,data.playlistLimit,data.onHead); + audioM.playListLoader(playlist, data.playlistLimit, user, data.onHead); response = new ResponseEntity<>(new CommandResponseData("ADD", "Loaded"), HttpStatus.OK); } diff --git a/src/main/resources/static/js/music.js b/src/main/resources/static/js/music.js index 99fde47..5e46b9c 100644 --- a/src/main/resources/static/js/music.js +++ b/src/main/resources/static/js/music.js @@ -8,6 +8,7 @@ $(document).ready(function() { setInterval("getCurentMusic()",1000); // the "href" attribute of the modal trigger must specify the modal ID that wants to be triggered $('#modalAdd').modal(); + $('#modal_current_info').modal(); $('#modalChanels').modal({ dismissible: false // Modal can be dismissed by clicking outside of the modal @@ -292,10 +293,11 @@ function getPlayList() { template.removeAttr("id"); template.removeAttr("style"); var content = template.html(); - content = content.replace("@title", element.title); - content = content.replace("@author", element.author); - content = content.replace("@lenght", msToTime(element.length)); - content = content.replace(/@url/g, element.uri); + content = content.replace("@title", element.audioTrackInfo.title); + content = content.replace("@author", element.audioTrackInfo.author); + content = content.replace("@lenght", msToTime(element.audioTrackInfo.length)); + content = content.replace(/@url/g, element.audioTrackInfo.uri); + content = content.replace(/@user/g, element.user); template.html(content); $('#playlist_list').append(template); @@ -349,18 +351,19 @@ function getChannels(){ } function updateModal(data){ - $('#modal_title').text("Title: "+ data.info.title); + $('#modal_title').text("Title: "+ data.info.audioTrackInfo.title); $('#modal_author').text("Author: "+ data.info.author); - $('#modal_lenght').text("Duration: "+ msToTime(data.info.length)); - $('#modal_url').text("URL: "+ data.info.uri); + $('#modal_lenght').text("Duration: "+ msToTime(data.info.audioTrackInfo.length)); + $('#modal_url').text("URL: "+ data.info.audioTrackInfo.uri); + $('#modal_submit').text("Submitted by: "+ data.info.user); } function updateControl(data){ - $('#music_text').text(data.info.title); - var percent = (data.currentPos / data.info.length) * 100; + $('#music_text').text(data.info.audioTrackInfo.title); + var percent = (data.currentPos / data.info.audioTrackInfo.length) * 100; // console.log(percent) if (!$('#music_progress').hasClass("indeterminate")) { $('#music_progress').addClass("determinate").removeClass("indeterminate"); @@ -412,9 +415,9 @@ function updateControl(data){ } - $('#music_img').attr("src","https://img.youtube.com/vi/"+data.info.identifier+"/hqdefault.jpg"); + $('#music_img').attr("src","https://img.youtube.com/vi/"+data.info.audioTrackInfo.identifier+"/hqdefault.jpg"); // console.log(data); - $('#total_time').text(msToTime(data.info.length)); + $('#total_time').text(msToTime(data.info.audioTrackInfo.length)); $('#current_time').text(msToTime(data.currentPos)); updateModal(data); } diff --git a/src/main/resources/templates/music.html b/src/main/resources/templates/music.html index e27a859..c3ef9dc 100644 --- a/src/main/resources/templates/music.html +++ b/src/main/resources/templates/music.html @@ -152,7 +152,7 @@
@@ -232,13 +232,14 @@ -