Adding rest command for autflow control

This commit is contained in:
Sebastien 2018-03-05 11:17:33 +01:00
parent a9ca04ecef
commit 0e16423ac1
3 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,30 @@
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.AudioM;
import net.Broken.audio.NotConnectedException;
import net.Broken.audio.NullMusicManager;
import net.Broken.audio.TrackScheduler;
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);
try {
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
scheduler.setAutoPlay(false);
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
LogManager.getLogger().catching(nullMusicManager);
return new ResponseEntity<>(new CommandResponseData(data.command,"Not connected", "connect"), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -0,0 +1,31 @@
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.AudioM;
import net.Broken.audio.NotConnectedException;
import net.Broken.audio.NullMusicManager;
import net.Broken.audio.TrackScheduler;
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);
try {
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
scheduler.setAutoPlay(true);
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
LogManager.getLogger().catching(nullMusicManager);
return new ResponseEntity<>(new CommandResponseData(data.command,"Not connected", "connect"), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -176,5 +176,7 @@ public class TrackScheduler extends AudioEventAdapter {
} }
} }
public void setAutoPlay(boolean autoPlay) {
this.autoPlay = autoPlay;
}
} }