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