aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2018-04-07 20:01:46 -0400
committerMatt Kohls <mattkohls13@gmail.com>2018-04-07 20:01:46 -0400
commit02dbcc2e9eea74f0ecd40efcd12ec49f3073afe7 (patch)
tree16cb93c04b015c407ea95d9a30bc565d72670510 /src/main
parent34f2676644bf6d76b2024e873a0a7ea35fffe37d (diff)
parent05395d976b90ec672a6edc7b81180fff3a679140 (diff)
downloadSoundChan-02dbcc2e9eea74f0ecd40efcd12ec49f3073afe7.tar.gz
SoundChan-02dbcc2e9eea74f0ecd40efcd12ec49f3073afe7.tar.bz2
SoundChan-02dbcc2e9eea74f0ecd40efcd12ec49f3073afe7.zip
Merge branch 'master' of https://github.com/bwaggone/SoundChan into following
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/soundchan/Main.java47
-rw-r--r--src/main/java/soundchan/TrackScheduler.java16
2 files changed, 53 insertions, 10 deletions
diff --git a/src/main/java/soundchan/Main.java b/src/main/java/soundchan/Main.java
index 514d7be..3d0b9b6 100644
--- a/src/main/java/soundchan/Main.java
+++ b/src/main/java/soundchan/Main.java
@@ -33,6 +33,8 @@ public class Main extends ListenerAdapter {
.setToken(properties.getProperty("botToken"))
.buildBlocking();
+ localFilePath = properties.getProperty("localFilePath");
+
jda.addEventListener(new Main());
followingUser = properties.getProperty("followingUser");
}
@@ -59,6 +61,7 @@ public class Main extends ListenerAdapter {
private long monitoredGuildId = -1;
private Guild monitoredGuild;
private static String followingUser;
+ private static String localFilePath;
private final AudioPlayerManager playerManager;
private final Map<Long, GuildMusicManager> musicManagers;
@@ -135,17 +138,29 @@ public class Main extends ListenerAdapter {
}
if(monitoredGuild != null){
- if ("~play".equals(command[0]) && command.length == 2) {
- loadAndPlay(channel, command[1]);
- } else if ("~skip".equals(command[0])) {
- skipTrack(channel);
- } else if ("~volume".equals(command[0]) && command.length == 2) {
- changeVolume(channel, command[1]);
- } else if ("~pause".equals(command[0])) {
- pauseTrack(channel);
- } else if ("~unpause".equals(command[0])) {
- unpauseTrack(channel);
+
+ // "!" Signifies that you're looking to play a sound effect
+ if(command[0].startsWith("!") && command[0].length() > 1){
+ loadAndPlay(channel, localFilePath + "\\" + command[0].substring(1) + ".mp3");
+ }
+
+ // "~" Signifies that you're looking to play a song/sound from a url
+ if(command[0].startsWith("~") && command[0].length() > 1){
+ if ("~play".equals(command[0]) && command.length == 2) {
+ loadAndPlay(channel, command[1]);
+ } else if ("~skip".equals(command[0])) {
+ skipTrack(channel);
+ } else if ("~volume".equals(command[0]) && command.length == 2) {
+ changeVolume(channel, command[1]);
+ } else if ("~pause".equals(command[0])) {
+ pauseTrack(channel);
+ } else if ("~unpause".equals(command[0])) {
+ unpauseTrack(channel);
+ } else if ("~list".equals(command[0])) {
+ listTracks(channel);
+ }
}
+
}
super.onMessageReceived(event);
@@ -157,6 +172,17 @@ public class Main extends ListenerAdapter {
channel.sendMessage("Volume now set to " + volume + "%").queue();
}
+ private void listTracks(final MessageChannel channel) {
+ GuildMusicManager musicManager = getGuildAudioPlayer();
+ List<String> queueContents = musicManager.scheduler.getQueueContents();
+ String printMessage = "Tracks in the queue:\n";
+ for (String track:
+ queueContents) {
+ printMessage = printMessage + track + "\n";
+ }
+ channel.sendMessage(printMessage).queue();
+ }
+
private void pauseTrack(final MessageChannel channel){
GuildMusicManager musicManager = getGuildAudioPlayer();
musicManager.player.setPaused(true);
@@ -178,6 +204,7 @@ public class Main extends ListenerAdapter {
int timeStart = trackUrl.lastIndexOf('=');
if(timeStart != -1){
String timeString = trackUrl.substring(timeStart);
+
//The format will be 1h2m53s, need to parse that into seconds and then call
//track.setPosition(long position)
diff --git a/src/main/java/soundchan/TrackScheduler.java b/src/main/java/soundchan/TrackScheduler.java
index 7f1c258..21bb6d4 100644
--- a/src/main/java/soundchan/TrackScheduler.java
+++ b/src/main/java/soundchan/TrackScheduler.java
@@ -2,9 +2,14 @@ package soundchan;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
+import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
+import com.sedmelluq.discord.lavaplayer.track.DelegatedAudioTrack;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -37,6 +42,17 @@ public class TrackScheduler extends AudioEventAdapter {
}
}
+ public List<String> getQueueContents() {
+ // Returns a list of the tracks in the queue
+ Object[] queueInfo = queue.toArray();
+ List<String> tracks = new ArrayList<>();
+ for (Object item:
+ queueInfo) {
+ tracks.add(((DelegatedAudioTrack) item).getInfo().title);
+ }
+ return tracks;
+ }
+
/**
* Start the next track, stopping the current one if it is playing.
*/