Add multi guild support for music
This commit is contained in:
parent
2cdf390c36
commit
2796993fec
@ -7,6 +7,7 @@ import net.Broken.Tools.Command.CommandParser;
|
|||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.Broken.Tools.Moderateur;
|
import net.Broken.Tools.Moderateur;
|
||||||
import net.Broken.Tools.PrivateMessage;
|
import net.Broken.Tools.PrivateMessage;
|
||||||
|
import net.Broken.audio.AudioM;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
@ -78,8 +79,7 @@ public class BotListener extends ListenerAdapter {
|
|||||||
if(event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() == 1){
|
if(event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() == 1){
|
||||||
logger.debug("I'm alone, close audio connection.");
|
logger.debug("I'm alone, close audio connection.");
|
||||||
|
|
||||||
Music music = (Music) MainBot.commandes.get("music");
|
AudioM.getInstance(event.getGuild()).stop();
|
||||||
music.audio.stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,21 +20,20 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class Music implements Commande {
|
public class Music implements Commande {
|
||||||
public AudioM audio;
|
private Logger logger = LogManager.getLogger();
|
||||||
Logger logger = LogManager.getLogger();
|
|
||||||
public Music() {
|
|
||||||
audio = AudioM.getInstance(MainBot.jda.getGuilds().get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
AudioM audio = AudioM.getInstance(event.getGuild());
|
||||||
if(args.length >= 1){
|
if(args.length >= 1){
|
||||||
switch (args[0]){
|
switch (args[0]){
|
||||||
case "play":
|
case "play":
|
||||||
event.getTextChannel().sendTyping().queue();
|
event.getTextChannel().sendTyping().queue();
|
||||||
|
|
||||||
if(args.length>=2){
|
if(args.length>=2){
|
||||||
if(event.getMember().getVoiceState().inVoiceChannel()){
|
if(event.getMember().getVoiceState().inVoiceChannel()){
|
||||||
|
|
||||||
VoiceChannel voiceChanel = event.getMember().getVoiceState().getChannel();
|
VoiceChannel voiceChanel = event.getMember().getVoiceState().getChannel();
|
||||||
logger.info("Connecting to "+voiceChanel.getName()+"...");
|
logger.info("Connecting to "+voiceChanel.getName()+"...");
|
||||||
if(args.length ==2){
|
if(args.length ==2){
|
||||||
@ -170,8 +169,4 @@ public class Music implements Commande {
|
|||||||
public boolean isNSFW() {
|
public boolean isNSFW() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AudioM getAudioManager(){
|
|
||||||
return audio;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package net.Broken.RestApi;
|
|||||||
import net.Broken.Commands.Music;
|
import net.Broken.Commands.Music;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
@ -16,7 +17,8 @@ public interface CommandInterface {
|
|||||||
* @param musicCommande Current guild music command
|
* @param musicCommande Current guild music command
|
||||||
* @param data Received data
|
* @param data Received data
|
||||||
* @param user User who submit RestApi command
|
* @param user User who submit RestApi command
|
||||||
|
* @param guild
|
||||||
* @return HTTP Response
|
* @return HTTP Response
|
||||||
*/
|
*/
|
||||||
ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user);
|
ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.Broken.RestApi.Commands;
|
package net.Broken.RestApi.Commands;
|
||||||
|
|
||||||
import net.Broken.Commands.Music;
|
|
||||||
import net.Broken.RestApi.CommandInterface;
|
import net.Broken.RestApi.CommandInterface;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.WebLoadUtils;
|
import net.Broken.audio.WebLoadUtils;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
*/
|
*/
|
||||||
public class Add implements CommandInterface {
|
public class Add implements CommandInterface {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
return new WebLoadUtils(data, user, true).getResponse();
|
return new WebLoadUtils(data, user, guild, true).getResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,17 @@ import net.Broken.RestApi.CommandInterface;
|
|||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.AudioM;
|
import net.Broken.audio.AudioM;
|
||||||
import net.Broken.audio.NotConnectedException;
|
|
||||||
import net.Broken.audio.NullMusicManager;
|
|
||||||
import net.Broken.audio.TrackScheduler;
|
import net.Broken.audio.TrackScheduler;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
public class AutoFlowOff implements CommandInterface{
|
public class AutoFlowOff implements CommandInterface{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
AudioM audioM = AudioM.getInstance(null);
|
AudioM audioM = AudioM.getInstance(guild);
|
||||||
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
|
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
|
||||||
scheduler.setAutoFlow(false);
|
scheduler.setAutoFlow(false);
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
|
||||||
|
@ -5,19 +5,17 @@ import net.Broken.RestApi.CommandInterface;
|
|||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.AudioM;
|
import net.Broken.audio.AudioM;
|
||||||
import net.Broken.audio.NotConnectedException;
|
|
||||||
import net.Broken.audio.NullMusicManager;
|
|
||||||
import net.Broken.audio.TrackScheduler;
|
import net.Broken.audio.TrackScheduler;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
public class AutoFlowOn implements CommandInterface{
|
public class AutoFlowOn implements CommandInterface{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
AudioM audioM = AudioM.getInstance(null);
|
AudioM audioM = AudioM.getInstance(guild);
|
||||||
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
|
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
|
||||||
scheduler.setAutoFlow(true);
|
scheduler.setAutoFlow(true);
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
|
||||||
|
@ -5,6 +5,7 @@ import net.Broken.RestApi.CommandInterface;
|
|||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.AudioM;
|
import net.Broken.audio.AudioM;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import net.dv8tion.jda.core.entities.VoiceChannel;
|
import net.dv8tion.jda.core.entities.VoiceChannel;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -15,21 +16,21 @@ import org.springframework.http.ResponseEntity;
|
|||||||
*/
|
*/
|
||||||
public class Connect implements CommandInterface{
|
public class Connect implements CommandInterface{
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
AudioM audioM = AudioM.getInstance(null);
|
AudioM audioM = AudioM.getInstance(guild);
|
||||||
if(data.chanelId == null)
|
if(data.chanelId == null)
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Missing chanelId"),HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(new CommandResponseData(data.command,"Missing chanelId"),HttpStatus.BAD_REQUEST);
|
||||||
VoiceChannel voiceChannel = null;
|
VoiceChannel voiceChannel = null;
|
||||||
try{
|
try{
|
||||||
voiceChannel = audioM.getGuild().getVoiceChannelById(data.chanelId);
|
voiceChannel = guild.getVoiceChannelById(data.chanelId);
|
||||||
}catch (NumberFormatException ignored){}
|
}catch (NumberFormatException ignored){}
|
||||||
|
|
||||||
if(voiceChannel == null){
|
if(voiceChannel == null){
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Channel Not found"), HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(new CommandResponseData(data.command,"Channel Not found"), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
audioM.getGuildAudioPlayer(musicCommande.getAudioManager().getGuild());
|
audioM.getGuildAudioPlayer();
|
||||||
audioM.getGuild().getAudioManager().openAudioConnection(audioM.getGuild().getVoiceChannelById(data.chanelId));
|
guild.getAudioManager().openAudioConnection(guild.getVoiceChannelById(data.chanelId));
|
||||||
audioM.setPlayedChanel(voiceChannel);
|
audioM.setPlayedChanel(voiceChannel);
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Accepted"),HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command,"Accepted"),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package net.Broken.RestApi.Commands;
|
package net.Broken.RestApi.Commands;
|
||||||
|
|
||||||
import net.Broken.Commands.Music;
|
import net.Broken.Commands.Music;
|
||||||
|
import net.Broken.MainBot;
|
||||||
import net.Broken.RestApi.CommandInterface;
|
import net.Broken.RestApi.CommandInterface;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.NotConnectedException;
|
import net.Broken.audio.AudioM;
|
||||||
import net.Broken.audio.NullMusicManager;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -15,9 +16,9 @@ import org.springframework.http.ResponseEntity;
|
|||||||
*/
|
*/
|
||||||
public class Dell implements CommandInterface {
|
public class Dell implements CommandInterface {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
if(data.url != null) {
|
if(data.url != null) {
|
||||||
if(musicCommande.getAudioManager().getGuildMusicManager().scheduler.remove(data.url)){
|
if(AudioM.getInstance(guild).getGuildMusicManager().scheduler.remove(data.url)){
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -5,7 +5,8 @@ import net.Broken.MainBot;
|
|||||||
import net.Broken.RestApi.CommandInterface;
|
import net.Broken.RestApi.CommandInterface;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.WebLoadUtils;
|
import net.Broken.audio.AudioM;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -15,9 +16,8 @@ import org.springframework.http.ResponseEntity;
|
|||||||
*/
|
*/
|
||||||
public class Disconnect implements CommandInterface{
|
public class Disconnect implements CommandInterface{
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
Music music = (Music) MainBot.commandes.get("music");
|
AudioM.getInstance(guild).stop();
|
||||||
music.audio.stop();
|
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Ok"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command,"Ok"), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import net.Broken.Commands.Music;
|
|||||||
import net.Broken.RestApi.CommandInterface;
|
import net.Broken.RestApi.CommandInterface;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.NotConnectedException;
|
import net.Broken.audio.AudioM;
|
||||||
import net.Broken.audio.NullMusicManager;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -15,8 +15,8 @@ import org.springframework.http.ResponseEntity;
|
|||||||
*/
|
*/
|
||||||
public class Flush implements CommandInterface {
|
public class Flush implements CommandInterface {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
musicCommande.getAudioManager().getGuildMusicManager().scheduler.flush();
|
AudioM.getInstance(guild).getGuildMusicManager().scheduler.flush();
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ import net.Broken.Commands.Music;
|
|||||||
import net.Broken.RestApi.CommandInterface;
|
import net.Broken.RestApi.CommandInterface;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.NotConnectedException;
|
import net.Broken.audio.AudioM;
|
||||||
import net.Broken.audio.NullMusicManager;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -15,8 +15,8 @@ import org.springframework.http.ResponseEntity;
|
|||||||
*/
|
*/
|
||||||
public class Next implements CommandInterface {
|
public class Next implements CommandInterface {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
musicCommande.getAudioManager().getGuildMusicManager().scheduler.nextTrack();
|
AudioM.getInstance(guild).getGuildMusicManager().scheduler.nextTrack();
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ import net.Broken.Commands.Music;
|
|||||||
import net.Broken.RestApi.CommandInterface;
|
import net.Broken.RestApi.CommandInterface;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.NotConnectedException;
|
import net.Broken.audio.AudioM;
|
||||||
import net.Broken.audio.NullMusicManager;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -15,8 +15,8 @@ import org.springframework.http.ResponseEntity;
|
|||||||
*/
|
*/
|
||||||
public class Pause implements CommandInterface {
|
public class Pause implements CommandInterface {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
musicCommande.getAudioManager().getGuildMusicManager().scheduler.pause();
|
AudioM.getInstance(guild).getGuildMusicManager().scheduler.pause();
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ import net.Broken.Commands.Music;
|
|||||||
import net.Broken.RestApi.CommandInterface;
|
import net.Broken.RestApi.CommandInterface;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
import net.Broken.audio.NotConnectedException;
|
import net.Broken.audio.AudioM;
|
||||||
import net.Broken.audio.NullMusicManager;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -15,8 +15,8 @@ import org.springframework.http.ResponseEntity;
|
|||||||
*/
|
*/
|
||||||
public class Play implements CommandInterface {
|
public class Play implements CommandInterface {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
musicCommande.getAudioManager().getGuildMusicManager().scheduler.resume();
|
AudioM.getInstance(guild).getGuildMusicManager().scheduler.resume();
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import net.Broken.Commands.Music;
|
|||||||
import net.Broken.RestApi.CommandInterface;
|
import net.Broken.RestApi.CommandInterface;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
|
import net.Broken.audio.AudioM;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -14,8 +16,8 @@ import org.springframework.http.ResponseEntity;
|
|||||||
*/
|
*/
|
||||||
public class Stop implements CommandInterface {
|
public class Stop implements CommandInterface {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||||
musicCommande.getAudioManager().stop((MessageReceivedEvent) null);
|
AudioM.getInstance(guild).stop(null);
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,19 +9,16 @@ import net.Broken.MainBot;
|
|||||||
import net.Broken.RestApi.Data.*;
|
import net.Broken.RestApi.Data.*;
|
||||||
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
|
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
|
||||||
import net.Broken.Tools.UserManager.UserUtils;
|
import net.Broken.Tools.UserManager.UserUtils;
|
||||||
|
import net.Broken.audio.AudioM;
|
||||||
import net.Broken.audio.FindGeneral;
|
import net.Broken.audio.FindGeneral;
|
||||||
import net.Broken.audio.NotConnectedException;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.Broken.audio.NullMusicManager;
|
|
||||||
import net.dv8tion.jda.core.entities.VoiceChannel;
|
import net.dv8tion.jda.core.entities.VoiceChannel;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -42,44 +39,66 @@ public class MusicWebAPIController {
|
|||||||
|
|
||||||
|
|
||||||
@RequestMapping("/currentMusicInfo")
|
@RequestMapping("/currentMusicInfo")
|
||||||
public CurrentMusicData getCurrentM(){
|
public ResponseEntity<CurrentMusicData> getCurrentM(@RequestParam(value = "guild") String guildId){
|
||||||
|
Guild guild = MainBot.jda.getGuildById(guildId);
|
||||||
|
if(guild == null ){
|
||||||
|
logger.warn("Request whit no guild!");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
logger.info("currentMusicInfo for " + guild.getName());
|
||||||
|
}
|
||||||
|
|
||||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||||
|
|
||||||
if(musicCommande.audio.getGuild().getAudioManager().isConnected()){
|
if(guild.getAudioManager().isConnected()){
|
||||||
AudioPlayer player = musicCommande.audio.getGuildMusicManager().player;
|
AudioPlayer player = AudioM.getInstance(guild).getGuildMusicManager().player;
|
||||||
AudioTrack currentTrack = player.getPlayingTrack();
|
AudioTrack currentTrack = player.getPlayingTrack();
|
||||||
if(currentTrack == null)
|
if(currentTrack == null)
|
||||||
{
|
{
|
||||||
return new CurrentMusicData(null,0, "STOP",false, musicCommande.audio.getGuildMusicManager().scheduler.isAutoFlow());
|
return new ResponseEntity<>(new CurrentMusicData(null,0, "STOP",false, AudioM.getInstance(guild).getGuildMusicManager().scheduler.isAutoFlow()),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
UserAudioTrackData uat = new UserAudioTrackData(musicCommande.audio.getGuildMusicManager().scheduler.getCurrentPlayingTrack());
|
UserAudioTrackData uat = new UserAudioTrackData(AudioM.getInstance(guild).getGuildMusicManager().scheduler.getCurrentPlayingTrack());
|
||||||
return new CurrentMusicData(uat, currentTrack.getPosition(), currentTrack.getState().toString(), player.isPaused(), musicCommande.audio.getGuildMusicManager().scheduler.isAutoFlow());
|
return new ResponseEntity<>(new CurrentMusicData(uat, currentTrack.getPosition(), currentTrack.getState().toString(), player.isPaused(), AudioM.getInstance(guild).getGuildMusicManager().scheduler.isAutoFlow()),HttpStatus.OK);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
return new CurrentMusicData(null,0, "DISCONNECTED",false, false);
|
return new ResponseEntity<>(new CurrentMusicData(null,0, "DISCONNECTED",false, false),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/getPlaylist")
|
@RequestMapping("/getPlaylist")
|
||||||
public PlaylistData getPlaylist(){
|
public ResponseEntity<PlaylistData> getPlaylist(@RequestParam(value = "guild") String guildId){
|
||||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
Guild guild = MainBot.jda.getGuildById(guildId);
|
||||||
|
if(guild == null ){
|
||||||
|
logger.warn("Request whit no guild!");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
logger.info("getPlaylist for " + guild.getName());
|
||||||
|
}
|
||||||
|
|
||||||
List<UserAudioTrackData> list = null;
|
List<UserAudioTrackData> list = null;
|
||||||
list = musicCommande.getAudioManager().getGuildMusicManager().scheduler.getList();
|
list = AudioM.getInstance(guild).getGuildMusicManager().scheduler.getList();
|
||||||
return new PlaylistData(list);
|
return new ResponseEntity<>(new PlaylistData(list), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/command", method = RequestMethod.POST)
|
@RequestMapping(value = "/command", method = RequestMethod.POST)
|
||||||
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data, HttpServletRequest request){
|
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data, HttpServletRequest request, @RequestParam(value = "guild") String guildId){
|
||||||
|
|
||||||
if(data.command != null) {
|
if(data.command != null) {
|
||||||
if(data.token != null) {
|
if(data.token != null) {
|
||||||
|
Guild guild = MainBot.jda.getGuildById(guildId);
|
||||||
|
if(guild == null ){
|
||||||
|
logger.warn("Request whit no guild!");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
UserEntity user = userUtils.getUserWithApiToken(userRepository, data.token);
|
UserEntity user = userUtils.getUserWithApiToken(userRepository, data.token);
|
||||||
logger.info("receive command " + data.command + " from " + request.getRemoteAddr() + " USER: " + user.getName());
|
logger.info("Receive command " + data.command + " from " + request.getRemoteAddr() + " USER: " + user.getName() + "GUILD: " + guild.getName());
|
||||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
|
||||||
|
|
||||||
if (ApiCommandLoader.apiCommands.containsKey(data.command))
|
if (ApiCommandLoader.apiCommands.containsKey(data.command))
|
||||||
return ApiCommandLoader.apiCommands.get(data.command).action(musicCommande, data, MainBot.jda.getUserById(user.getJdaId()));
|
return ApiCommandLoader.apiCommands.get(data.command).action(data, MainBot.jda.getUserById(user.getJdaId()), guild);
|
||||||
else
|
else
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Unknown Command", "command"), HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Unknown Command", "command"), HttpStatus.BAD_REQUEST);
|
||||||
|
|
||||||
@ -102,12 +121,20 @@ public class MusicWebAPIController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/getChanel", method = RequestMethod.GET)
|
@RequestMapping(value = "/getChanel", method = RequestMethod.GET)
|
||||||
public List<ChanelData> getChanel(){
|
public ResponseEntity<List<ChanelData>> getChanel(@RequestParam(value = "guild") String guildId){
|
||||||
|
Guild guild = MainBot.jda.getGuildById(guildId);
|
||||||
|
if(guild == null ){
|
||||||
|
logger.warn("Request whit no guild!");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
logger.info("getPlaylist for " + guild.getName());
|
||||||
|
}
|
||||||
List<ChanelData> temp = new ArrayList<>();
|
List<ChanelData> temp = new ArrayList<>();
|
||||||
for(VoiceChannel aChanel : FindGeneral.find(MainBot.jda.getGuilds().get(0)).getVoiceChannels()){
|
for(VoiceChannel aChanel : FindGeneral.find(guild).getVoiceChannels()){
|
||||||
temp.add(new ChanelData(aChanel.getName(),aChanel.getId(),aChanel.getPosition()));
|
temp.add(new ChanelData(aChanel.getName(),aChanel.getId(),aChanel.getPosition()));
|
||||||
}
|
}
|
||||||
return temp;
|
return new ResponseEntity<>(temp, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AudioM {
|
public class AudioM {
|
||||||
@ -52,14 +53,14 @@ public class AudioM {
|
|||||||
private Guild guild;
|
private Guild guild;
|
||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
private static AudioM INSTANCE;
|
private static HashMap<Guild,AudioM> INSTANCES = new HashMap<>();
|
||||||
|
|
||||||
public static AudioM getInstance(Guild guild){
|
public static AudioM getInstance(Guild guild){
|
||||||
if(INSTANCE == null){
|
if(!INSTANCES.containsKey(guild)){
|
||||||
INSTANCE = new AudioM(guild);
|
INSTANCES.put(guild, new AudioM(guild));
|
||||||
}
|
}
|
||||||
|
|
||||||
return INSTANCE;
|
return INSTANCES.get(guild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ public class AudioM {
|
|||||||
* @param onHead True for adding audio track on top of playlist
|
* @param onHead True for adding audio track on top of playlist
|
||||||
*/
|
*/
|
||||||
public void loadAndPlay(MessageReceivedEvent event, VoiceChannel voiceChannel, final String trackUrl, int playlistLimit, boolean onHead) {
|
public void loadAndPlay(MessageReceivedEvent event, VoiceChannel voiceChannel, final String trackUrl, int playlistLimit, boolean onHead) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer(guild);
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
playedChanel = voiceChannel;
|
playedChanel = voiceChannel;
|
||||||
|
|
||||||
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
|
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
|
||||||
@ -187,9 +188,9 @@ public class AudioM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public GuildMusicManager getGuildAudioPlayer(Guild guild) {
|
public GuildMusicManager getGuildAudioPlayer() {
|
||||||
if (musicManager == null) {
|
if (musicManager == null) {
|
||||||
musicManager = new GuildMusicManager(playerManager);
|
musicManager = new GuildMusicManager(playerManager, guild);
|
||||||
}
|
}
|
||||||
|
|
||||||
guild.getAudioManager().setSendingHandler(musicManager.getSendHandler());
|
guild.getAudioManager().setSendingHandler(musicManager.getSendHandler());
|
||||||
@ -219,7 +220,7 @@ public class AudioM {
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void skipTrack(MessageReceivedEvent event) {
|
public void skipTrack(MessageReceivedEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
musicManager.scheduler.nextTrack();
|
musicManager.scheduler.nextTrack();
|
||||||
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Musique suivante!")).complete();
|
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Musique suivante!")).complete();
|
||||||
new MessageTimeOut(MainBot.messageTimeOut, message, event.getMessage()).start();
|
new MessageTimeOut(MainBot.messageTimeOut, message, event.getMessage()).start();
|
||||||
@ -230,7 +231,7 @@ public class AudioM {
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void pause(MessageReceivedEvent event) {
|
public void pause(MessageReceivedEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
musicManager.scheduler.pause();
|
musicManager.scheduler.pause();
|
||||||
|
|
||||||
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Musique en pause !")).complete();
|
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Musique en pause !")).complete();
|
||||||
@ -243,7 +244,7 @@ public class AudioM {
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void resume (MessageReceivedEvent event) {
|
public void resume (MessageReceivedEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
musicManager.scheduler.resume();
|
musicManager.scheduler.resume();
|
||||||
|
|
||||||
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Reprise de la piste en cour !")).complete();
|
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Reprise de la piste en cour !")).complete();
|
||||||
@ -255,7 +256,7 @@ public class AudioM {
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void info(MessageReceivedEvent event) {
|
public void info(MessageReceivedEvent event) {
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
AudioTrackInfo info = musicManager.scheduler.getInfo();
|
AudioTrackInfo info = musicManager.scheduler.getInfo();
|
||||||
UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack();
|
UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack();
|
||||||
|
|
||||||
@ -264,7 +265,7 @@ public class AudioM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void flush(MessageReceivedEvent event){
|
public void flush(MessageReceivedEvent event){
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
musicManager.scheduler.flush();
|
musicManager.scheduler.flush();
|
||||||
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("RAZ de la playlist!")).complete();
|
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("RAZ de la playlist!")).complete();
|
||||||
new MessageTimeOut(MainBot.messageTimeOut, event.getMessage(), message).start();
|
new MessageTimeOut(MainBot.messageTimeOut, event.getMessage(), message).start();
|
||||||
@ -275,7 +276,7 @@ public class AudioM {
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void list(MessageReceivedEvent event){
|
public void list(MessageReceivedEvent event){
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
List<UserAudioTrackData> list = musicManager.scheduler.getList();
|
List<UserAudioTrackData> list = musicManager.scheduler.getList();
|
||||||
StringBuilder resp = new StringBuilder();
|
StringBuilder resp = new StringBuilder();
|
||||||
if(list.size() == 0){
|
if(list.size() == 0){
|
||||||
@ -330,7 +331,7 @@ public class AudioM {
|
|||||||
*/
|
*/
|
||||||
public void stop () {
|
public void stop () {
|
||||||
|
|
||||||
GuildMusicManager musicManager = getGuildAudioPlayer(guild);
|
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||||
musicManager.scheduler.stop();
|
musicManager.scheduler.stop();
|
||||||
musicManager.scheduler.flush();
|
musicManager.scheduler.flush();
|
||||||
playedChanel = null;
|
playedChanel = null;
|
||||||
@ -339,8 +340,9 @@ public class AudioM {
|
|||||||
|
|
||||||
public GuildMusicManager getGuildMusicManager(){
|
public GuildMusicManager getGuildMusicManager(){
|
||||||
if( musicManager == null)
|
if( musicManager == null)
|
||||||
musicManager = getGuildAudioPlayer(guild);
|
musicManager = getGuildAudioPlayer();
|
||||||
return musicManager;
|
return musicManager;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Guild getGuild() {
|
public Guild getGuild() {
|
||||||
|
@ -2,6 +2,7 @@ package net.Broken.audio;
|
|||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holder for both the player and a track scheduler for one guild.
|
* Holder for both the player and a track scheduler for one guild.
|
||||||
@ -16,14 +17,17 @@ public class GuildMusicManager {
|
|||||||
*/
|
*/
|
||||||
public final TrackScheduler scheduler;
|
public final TrackScheduler scheduler;
|
||||||
|
|
||||||
|
public final Guild guild;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a player and a track scheduler.
|
* Creates a player and a track scheduler.
|
||||||
* @param manager Audio player manager to use for creating the player.
|
* @param manager Audio player manager to use for creating the player.
|
||||||
*/
|
*/
|
||||||
public GuildMusicManager(AudioPlayerManager manager) {
|
public GuildMusicManager(AudioPlayerManager manager, Guild guild) {
|
||||||
player = manager.createPlayer();
|
player = manager.createPlayer();
|
||||||
scheduler = new TrackScheduler(player);
|
scheduler = new TrackScheduler(player, guild);
|
||||||
player.addListener(scheduler);
|
player.addListener(scheduler);
|
||||||
|
this.guild = guild;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,7 +7,6 @@ import net.Broken.DB.Repository.PlaylistRepository;
|
|||||||
import net.Broken.DB.Repository.TrackRepository;
|
import net.Broken.DB.Repository.TrackRepository;
|
||||||
import net.Broken.DB.Repository.UserRepository;
|
import net.Broken.DB.Repository.UserRepository;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
|
||||||
import net.Broken.RestApi.Data.Playlist.AddToPlaylistData;
|
import net.Broken.RestApi.Data.Playlist.AddToPlaylistData;
|
||||||
import net.Broken.RestApi.Data.Playlist.DeleteTrackData;
|
import net.Broken.RestApi.Data.Playlist.DeleteTrackData;
|
||||||
import net.Broken.RestApi.Data.Playlist.MoveTrackData;
|
import net.Broken.RestApi.Data.Playlist.MoveTrackData;
|
||||||
@ -23,7 +22,6 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import sun.applet.Main;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -68,7 +66,7 @@ public class PlaylistManager {
|
|||||||
|
|
||||||
User jdaUser = MainBot.jda.getUserById(user.getJdaId());
|
User jdaUser = MainBot.jda.getUserById(user.getJdaId());
|
||||||
|
|
||||||
WebLoadUtils webLoadUtils = new WebLoadUtils(data, jdaUser, false);
|
WebLoadUtils webLoadUtils = new WebLoadUtils(data, jdaUser, MainBot.jda.getGuilds().get(0) , false);
|
||||||
webLoadUtils.getResponse();
|
webLoadUtils.getResponse();
|
||||||
|
|
||||||
if(webLoadUtils.userAudioTrack == null){
|
if(webLoadUtils.userAudioTrack == null){
|
||||||
|
@ -9,6 +9,7 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
|||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.RestApi.Data.UserAudioTrackData;
|
import net.Broken.RestApi.Data.UserAudioTrackData;
|
||||||
import net.Broken.audio.Youtube.YoutubeTools;
|
import net.Broken.audio.Youtube.YoutubeTools;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@ -23,19 +24,22 @@ import java.util.concurrent.LinkedBlockingDeque;
|
|||||||
public class TrackScheduler extends AudioEventAdapter {
|
public class TrackScheduler extends AudioEventAdapter {
|
||||||
private final AudioPlayer player;
|
private final AudioPlayer player;
|
||||||
private final BlockingDeque<UserAudioTrack> queue;
|
private final BlockingDeque<UserAudioTrack> queue;
|
||||||
|
private final Guild guild;
|
||||||
|
|
||||||
private UserAudioTrack currentPlayingTrack;
|
private UserAudioTrack currentPlayingTrack;
|
||||||
private boolean autoFlow = false;
|
private boolean autoFlow = false;
|
||||||
private ArrayList<String> history = new ArrayList<>();
|
private ArrayList<String> history = new ArrayList<>();
|
||||||
Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player The audio player this scheduler uses
|
* @param player The audio player this scheduler uses
|
||||||
*/
|
*/
|
||||||
public TrackScheduler(AudioPlayer player) {
|
public TrackScheduler(AudioPlayer player, Guild guild) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
player.setVolume(25);
|
player.setVolume(25);
|
||||||
this.queue = new LinkedBlockingDeque<>();
|
this.queue = new LinkedBlockingDeque<>();
|
||||||
this.currentPlayingTrack = null;
|
this.currentPlayingTrack = null;
|
||||||
|
this.guild = guild;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,8 +181,8 @@ public class TrackScheduler extends AudioEventAdapter {
|
|||||||
private void needAutoPlay(){
|
private void needAutoPlay(){
|
||||||
if((queue.size() < 1) && autoFlow && currentPlayingTrack != null){
|
if((queue.size() < 1) && autoFlow && currentPlayingTrack != null){
|
||||||
logger.debug("Auto add needed!");
|
logger.debug("Auto add needed!");
|
||||||
AudioM audioM = AudioM.getInstance(null);
|
AudioM audioM = AudioM.getInstance(guild);
|
||||||
YoutubeTools youtubeTools = YoutubeTools.getInstance(null);
|
YoutubeTools youtubeTools = YoutubeTools.getInstance();
|
||||||
try {
|
try {
|
||||||
String id = youtubeTools.getRelatedVideo(currentPlayingTrack.getAudioTrack().getInfo().identifier, history);
|
String id = youtubeTools.getRelatedVideo(currentPlayingTrack.getAudioTrack().getInfo().identifier, history);
|
||||||
logger.debug("Related id: "+id);
|
logger.debug("Related id: "+id);
|
||||||
|
@ -7,6 +7,7 @@ import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
|||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||||
import net.Broken.RestApi.Data.CommandPostData;
|
import net.Broken.RestApi.Data.CommandPostData;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
import net.Broken.RestApi.Data.CommandResponseData;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -25,13 +26,14 @@ public class WebLoadUtils {
|
|||||||
* Submit a track or playlist to Music bot
|
* Submit a track or playlist to Music bot
|
||||||
* @param data Received data from API
|
* @param data Received data from API
|
||||||
* @param user User who submit the track
|
* @param user User who submit the track
|
||||||
|
* @param guild
|
||||||
*/
|
*/
|
||||||
public WebLoadUtils(CommandPostData data, User user, boolean submit){
|
public WebLoadUtils(CommandPostData data, User user, Guild guild, boolean submit){
|
||||||
AudioPlayerManager playerM = AudioM.getInstance(null).getPlayerManager();
|
AudioPlayerManager playerM = AudioM.getInstance(guild).getPlayerManager();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
AudioM audioM = AudioM.getInstance(null);
|
AudioM audioM = AudioM.getInstance(guild);
|
||||||
playerM.loadItemOrdered(audioM.getGuildMusicManager(), data.url, new AudioLoadResultHandler() {
|
playerM.loadItemOrdered(audioM.getGuildMusicManager(), data.url, new AudioLoadResultHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void trackLoaded(AudioTrack track) {
|
public void trackLoaded(AudioTrack track) {
|
||||||
|
@ -20,18 +20,16 @@ public class YoutubeTools {
|
|||||||
|
|
||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
private Guild guild;
|
|
||||||
|
|
||||||
private static YoutubeTools INSTANCE ;
|
private static YoutubeTools INSTANCE ;
|
||||||
|
|
||||||
private YoutubeTools(Guild guild){
|
private YoutubeTools(){
|
||||||
|
|
||||||
this.guild = guild;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static YoutubeTools getInstance(Guild guild){
|
public static YoutubeTools getInstance(){
|
||||||
if(INSTANCE == null)
|
if(INSTANCE == null)
|
||||||
INSTANCE = new YoutubeTools(guild);
|
INSTANCE = new YoutubeTools();
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user