aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrandon <bwaggone@umich.edu>2018-04-21 15:38:57 -0400
committerBrandon <bwaggone@umich.edu>2018-04-21 15:38:57 -0400
commit0fe63e59569f161628574159a8f8d318abbe3e0e (patch)
tree94474465a4c727aa92dd9b5fca26b3184b5d05b4 /src
parent70f6beee0fb9569e8549752e627929ae506c5e0c (diff)
downloadSoundChan-0fe63e59569f161628574159a8f8d318abbe3e0e.tar.gz
SoundChan-0fe63e59569f161628574159a8f8d318abbe3e0e.tar.bz2
SoundChan-0fe63e59569f161628574159a8f8d318abbe3e0e.zip
Fix bug
Diffstat (limited to 'src')
-rw-r--r--src/main/java/soundchan/BotListener/BotListener.java6
-rw-r--r--src/main/java/soundchan/BotListener/BotListenerHelpers.java26
-rw-r--r--src/main/java/soundchan/TrackScheduler.java16
3 files changed, 39 insertions, 9 deletions
diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java
index fe148ce..b09fffc 100644
--- a/src/main/java/soundchan/BotListener/BotListener.java
+++ b/src/main/java/soundchan/BotListener/BotListener.java
@@ -31,6 +31,7 @@ public class BotListener extends ListenerAdapter{
private static LocalAudioManager localManager;
private final AudioPlayerManager playerManager;
private final Map<Long, GuildMusicManager> musicManagers;
+ private BotListenerHelpers helper = new BotListenerHelpers();
public BotListener(Properties properties) {
this.musicManagers = new HashMap<>();
@@ -78,7 +79,6 @@ public class BotListener extends ListenerAdapter{
@Override
public void onMessageReceived(MessageReceivedEvent event) {
String[] command = event.getMessage().getContentRaw().split(" ", 2);
- BotListenerHelpers helper = new BotListenerHelpers();
Guild guild = event.getGuild();
MessageChannel channel = helper.GetReplyChannel(event);
@@ -202,8 +202,10 @@ public class BotListener extends ListenerAdapter{
//track.setPosition(long position)
}
- if(!preempt)
+ if(!preempt) {
+ helper.urlToTimeStamp(trackUrl);
channel.sendMessage("Adding to queue " + track.getInfo().title).queue();
+ }
play(monitoredGuild, musicManager, track, preempt);
}
diff --git a/src/main/java/soundchan/BotListener/BotListenerHelpers.java b/src/main/java/soundchan/BotListener/BotListenerHelpers.java
index 6689255..98ad31a 100644
--- a/src/main/java/soundchan/BotListener/BotListenerHelpers.java
+++ b/src/main/java/soundchan/BotListener/BotListenerHelpers.java
@@ -4,6 +4,7 @@ import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
+
public class BotListenerHelpers {
/**
@@ -16,5 +17,30 @@ public class BotListenerHelpers {
return (guild == null) ? event.getPrivateChannel() : event.getTextChannel();
}
+ public long urlToTimeStamp(String url){
+
+ int[] timeConversions = {1, 60, 3600};
+ int position = url.indexOf("?t=");
+ int seekTime = 0;
+
+ if(position != -1){
+ String linkTimestamp = url.substring(position + 3);
+ String[] times = linkTimestamp.split("[hms]");
+ for(int i = 0; i < times.length / 2; i++)
+ {
+ String temp = times[i];
+ times[i] = times[times.length - i - 1];
+ times[times.length - i - 1] = temp;
+ }
+
+ for (int i = 0; i < times.length; i++) {
+ seekTime = seekTime + timeConversions[i]*Integer.parseInt(times[i]);
+ }
+ System.out.println(seekTime);
+
+ }
+ return seekTime;
+ }
+
}
diff --git a/src/main/java/soundchan/TrackScheduler.java b/src/main/java/soundchan/TrackScheduler.java
index cc68335..cf7b1f8 100644
--- a/src/main/java/soundchan/TrackScheduler.java
+++ b/src/main/java/soundchan/TrackScheduler.java
@@ -46,14 +46,16 @@ public class TrackScheduler extends AudioEventAdapter {
public void playNow(AudioTrack track) {
AudioTrack currenlyPlaying = player.getPlayingTrack();
- AudioTrack cloned = currenlyPlaying.makeClone();
- cloned.setPosition(currenlyPlaying.getPosition());
-
- // Don't re-enqueue if its just a soundclip
- if(!(currenlyPlaying.getInfo().uri.contains(".mp3") || currenlyPlaying.getInfo().uri.contains(".wav")))
- // Re-enqueue the track
- queue.addFirst(cloned);
+ // If something is currently playing, pause it and put it back in the queue
+ if(currenlyPlaying != null) {
+ AudioTrack cloned = currenlyPlaying.makeClone();
+ cloned.setPosition(currenlyPlaying.getPosition());
+ // Don't re-enqueue if its just a soundclip
+ if (!(currenlyPlaying.getInfo().uri.contains(".mp3") || currenlyPlaying.getInfo().uri.contains(".wav")))
+ // Re-enqueue the track
+ queue.addFirst(cloned);
+ }
player.startTrack(track, false);
}