|
15 | 15 | */
|
16 | 16 | package com.jagrosh.jmusicbot.audio;
|
17 | 17 |
|
| 18 | +import java.nio.ByteBuffer; |
| 19 | +import java.util.HashSet; |
| 20 | +import java.util.LinkedList; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Set; |
| 23 | + |
| 24 | +import org.slf4j.LoggerFactory; |
| 25 | + |
18 | 26 | import com.jagrosh.jmusicbot.playlist.PlaylistLoader.Playlist;
|
19 | 27 | import com.jagrosh.jmusicbot.queue.AbstractQueue;
|
20 | 28 | import com.jagrosh.jmusicbot.settings.QueueType;
|
21 |
| -import com.jagrosh.jmusicbot.utils.TimeUtil; |
22 | 29 | import com.jagrosh.jmusicbot.settings.RepeatMode;
|
| 30 | +import com.jagrosh.jmusicbot.settings.Settings; |
23 | 31 | import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
24 | 32 | import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
|
25 | 33 | import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
26 | 34 | import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
27 | 35 | import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
|
28 | 36 | import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
29 |
| -import java.util.HashSet; |
30 |
| -import java.util.LinkedList; |
31 |
| -import java.util.List; |
32 |
| -import java.util.Set; |
33 |
| -import com.jagrosh.jmusicbot.settings.Settings; |
34 |
| -import com.jagrosh.jmusicbot.utils.FormatUtil; |
35 |
| -import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack; |
36 |
| -import java.nio.ByteBuffer; |
37 |
| -import net.dv8tion.jda.api.EmbedBuilder; |
38 |
| -import net.dv8tion.jda.api.JDA; |
39 |
| -import net.dv8tion.jda.api.MessageBuilder; |
| 37 | + |
40 | 38 | import net.dv8tion.jda.api.audio.AudioSendHandler;
|
41 | 39 | import net.dv8tion.jda.api.entities.Guild;
|
42 |
| -import net.dv8tion.jda.api.entities.Message; |
43 |
| -import net.dv8tion.jda.api.entities.User; |
44 |
| -import org.slf4j.LoggerFactory; |
45 | 40 |
|
46 | 41 | /**
|
47 | 42 | *
|
48 | 43 | * @author John Grosh <[email protected]>
|
49 | 44 | */
|
50 | 45 | public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
|
51 | 46 | {
|
52 |
| - public final static String PLAY_EMOJI = "\u25B6"; // ▶ |
53 |
| - public final static String PAUSE_EMOJI = "\u23F8"; // ⏸ |
54 |
| - public final static String STOP_EMOJI = "\u23F9"; // ⏹ |
55 |
| - |
56 |
| - |
57 | 47 | private final List<AudioTrack> defaultQueue = new LinkedList<>();
|
58 | 48 | private final Set<String> votes = new HashSet<>();
|
59 | 49 |
|
@@ -115,12 +105,7 @@ public void stopAndClear()
|
115 | 105 | audioPlayer.stopTrack();
|
116 | 106 | //current = null;
|
117 | 107 | }
|
118 |
| - |
119 |
| - public boolean isMusicPlaying(JDA jda) |
120 |
| - { |
121 |
| - return guild(jda).getSelfMember().getVoiceState().inVoiceChannel() && audioPlayer.getPlayingTrack()!=null; |
122 |
| - } |
123 |
| - |
| 108 | + |
124 | 109 | public Set<String> getVotes()
|
125 | 110 | {
|
126 | 111 | return votes;
|
@@ -212,75 +197,7 @@ public void onTrackStart(AudioPlayer player, AudioTrack track)
|
212 | 197 | votes.clear();
|
213 | 198 | manager.getBot().getNowplayingHandler().onTrackUpdate(track);
|
214 | 199 | }
|
215 |
| - |
216 | 200 |
|
217 |
| - // Formatting |
218 |
| - public Message getNowPlaying(JDA jda) |
219 |
| - { |
220 |
| - if(isMusicPlaying(jda)) |
221 |
| - { |
222 |
| - Guild guild = guild(jda); |
223 |
| - AudioTrack track = audioPlayer.getPlayingTrack(); |
224 |
| - MessageBuilder mb = new MessageBuilder(); |
225 |
| - mb.append(FormatUtil.filter(manager.getBot().getConfig().getSuccess()+" **Now Playing in "+guild.getSelfMember().getVoiceState().getChannel().getAsMention()+"...**")); |
226 |
| - EmbedBuilder eb = new EmbedBuilder(); |
227 |
| - eb.setColor(guild.getSelfMember().getColor()); |
228 |
| - RequestMetadata rm = getRequestMetadata(); |
229 |
| - if(rm.getOwner() != 0L) |
230 |
| - { |
231 |
| - User u = guild.getJDA().getUserById(rm.user.id); |
232 |
| - if(u==null) |
233 |
| - eb.setAuthor(FormatUtil.formatUsername(rm.user), null, rm.user.avatar); |
234 |
| - else |
235 |
| - eb.setAuthor(FormatUtil.formatUsername(u), null, u.getEffectiveAvatarUrl()); |
236 |
| - } |
237 |
| - |
238 |
| - try |
239 |
| - { |
240 |
| - eb.setTitle(track.getInfo().title, track.getInfo().uri); |
241 |
| - } |
242 |
| - catch(Exception e) |
243 |
| - { |
244 |
| - eb.setTitle(track.getInfo().title); |
245 |
| - } |
246 |
| - |
247 |
| - if(track instanceof YoutubeAudioTrack && manager.getBot().getConfig().useNPImages()) |
248 |
| - { |
249 |
| - eb.setThumbnail("https://img.youtube.com/vi/"+track.getIdentifier()+"/mqdefault.jpg"); |
250 |
| - } |
251 |
| - |
252 |
| - if(track.getInfo().author != null && !track.getInfo().author.isEmpty()) |
253 |
| - eb.setFooter("Source: " + track.getInfo().author, null); |
254 |
| - |
255 |
| - double progress = (double)audioPlayer.getPlayingTrack().getPosition()/track.getDuration(); |
256 |
| - eb.setDescription(getStatusEmoji() |
257 |
| - + " "+FormatUtil.progressBar(progress) |
258 |
| - + " `[" + TimeUtil.formatTime(track.getPosition()) + "/" + TimeUtil.formatTime(track.getDuration()) + "]` " |
259 |
| - + FormatUtil.volumeIcon(audioPlayer.getVolume())); |
260 |
| - |
261 |
| - return mb.setEmbeds(eb.build()).build(); |
262 |
| - } |
263 |
| - else return null; |
264 |
| - } |
265 |
| - |
266 |
| - public Message getNoMusicPlaying(JDA jda) |
267 |
| - { |
268 |
| - Guild guild = guild(jda); |
269 |
| - return new MessageBuilder() |
270 |
| - .setContent(FormatUtil.filter(manager.getBot().getConfig().getSuccess()+" **Now Playing...**")) |
271 |
| - .setEmbeds(new EmbedBuilder() |
272 |
| - .setTitle("No music playing") |
273 |
| - .setDescription(STOP_EMOJI+" "+FormatUtil.progressBar(-1)+" "+FormatUtil.volumeIcon(audioPlayer.getVolume())) |
274 |
| - .setColor(guild.getSelfMember().getColor()) |
275 |
| - .build()).build(); |
276 |
| - } |
277 |
| - |
278 |
| - public String getStatusEmoji() |
279 |
| - { |
280 |
| - return audioPlayer.isPaused() ? PAUSE_EMOJI : PLAY_EMOJI; |
281 |
| - } |
282 |
| - |
283 |
| - // Audio Send Handler methods |
284 | 201 | /*@Override
|
285 | 202 | public boolean canProvide()
|
286 | 203 | {
|
@@ -320,11 +237,4 @@ public boolean isOpus()
|
320 | 237 | {
|
321 | 238 | return true;
|
322 | 239 | }
|
323 |
| - |
324 |
| - |
325 |
| - // Private methods |
326 |
| - private Guild guild(JDA jda) |
327 |
| - { |
328 |
| - return jda.getGuildById(guildId); |
329 |
| - } |
330 | 240 | }
|
0 commit comments