From dddf4c8e3816e972c00f36932f92bd8f59a320dd Mon Sep 17 00:00:00 2001 From: John Grosh Date: Fri, 18 Aug 2017 15:43:20 -0400 Subject: [PATCH] added altprefix, songinstatus, and setstatus features slight change to internals to reduce some bugs --- pom.xml | 8 +- src/main/java/com/jagrosh/jmusicbot/Bot.java | 9 + .../java/com/jagrosh/jmusicbot/Config.java | 18 ++ .../java/com/jagrosh/jmusicbot/JMusicBot.java | 8 +- .../jagrosh/jmusicbot/audio/AudioHandler.java | 54 ++--- .../jagrosh/jmusicbot/audio/QueuedTrack.java | 104 ++++---- .../jmusicbot/commands/ForceskipCmd.java | 9 +- .../jmusicbot/commands/NowplayingCmd.java | 20 +- .../jagrosh/jmusicbot/commands/PauseCmd.java | 2 +- .../jagrosh/jmusicbot/commands/PlayCmd.java | 4 +- .../jagrosh/jmusicbot/commands/QueueCmd.java | 6 +- .../jagrosh/jmusicbot/commands/RemoveCmd.java | 5 +- .../jmusicbot/commands/SetstatusCmd.java | 56 +++++ .../jmusicbot/commands/ShuffleCmd.java | 108 ++++----- .../jagrosh/jmusicbot/commands/SkipCmd.java | 16 +- .../jagrosh/jmusicbot/gui/GuildsPanel.java | 222 +++++++++--------- .../jagrosh/jmusicbot/queue/FairQueue.java | 12 +- .../jagrosh/jmusicbot/queue/Queueable.java | 50 ++-- .../jagrosh/jmusicbot/utils/FormatUtil.java | 10 +- 19 files changed, 394 insertions(+), 327 deletions(-) create mode 100644 src/main/java/com/jagrosh/jmusicbot/commands/SetstatusCmd.java diff --git a/pom.xml b/pom.xml index 867fe15af..1efc204a6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.jagrosh JMusicBot - 0.0.7 + 0.0.8 jar @@ -23,17 +23,17 @@ net.dv8tion JDA - 3.1.1_219 + 3.2.0_242 com.sedmelluq lavaplayer - 1.2.42 + 1.2.43 com.jagrosh JDA-Utilities - 1.2 + 1.5 org.json diff --git a/src/main/java/com/jagrosh/jmusicbot/Bot.java b/src/main/java/com/jagrosh/jmusicbot/Bot.java index 8be93f5c2..ce22c5861 100644 --- a/src/main/java/com/jagrosh/jmusicbot/Bot.java +++ b/src/main/java/com/jagrosh/jmusicbot/Bot.java @@ -35,6 +35,7 @@ import com.jagrosh.jmusicbot.utils.FormatUtil; import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.core.Permission; +import net.dv8tion.jda.core.entities.Game; import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.Role; import net.dv8tion.jda.core.entities.TextChannel; @@ -149,6 +150,14 @@ public AudioHandler setUpHandler(Guild guild) return handler; } + public void resetGame() + { + if(config.getGame()==null || config.getGame().equalsIgnoreCase("none")) + jda.getPresence().setGame(null); + else + jda.getPresence().setGame(Game.of(config.getGame())); + } + private void updateTopic(Guild guild, AudioHandler handler) { TextChannel tchan = guild.getTextChannelById(getSettings(guild).getTextId()); diff --git a/src/main/java/com/jagrosh/jmusicbot/Config.java b/src/main/java/com/jagrosh/jmusicbot/Config.java index ad6e8f03c..a31b37230 100644 --- a/src/main/java/com/jagrosh/jmusicbot/Config.java +++ b/src/main/java/com/jagrosh/jmusicbot/Config.java @@ -31,6 +31,7 @@ public class Config { private boolean nogui; private String prefix; + private String altprefix; private String token; private String owner; private String success; @@ -40,6 +41,7 @@ public class Config { private String help; private boolean stay; private boolean dbots; + private boolean songingame; public Config(boolean nogui) { @@ -61,6 +63,9 @@ public Config(boolean nogui) case "prefix": prefix = value; break; + case "altprefix": + altprefix = value; + break; case "owner": owner = value; break; @@ -82,6 +87,9 @@ public Config(boolean nogui) case "noprogressintopic": FormatUtil.NO_PROGRESS_BAR_IN_TOPIC = "true".equalsIgnoreCase(value); break; + case "songinstatus": + songingame = "true".equalsIgnoreCase(value); + break; case "stayinchannel": stay = "true".equalsIgnoreCase(value); break; @@ -148,6 +156,11 @@ public String getPrefix() return prefix; } + public String getAltPrefix() + { + return altprefix; + } + public String getToken() { return token; @@ -193,6 +206,11 @@ public boolean getStay() return stay; } + public boolean getSongInStatus() + { + return songingame; + } + public boolean getDBots() { return dbots; diff --git a/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java b/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java index d2990ed0d..82c702449 100644 --- a/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java +++ b/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java @@ -59,18 +59,21 @@ public static void main(String[] args){ Bot bot = new Bot(waiter, config); AboutCommand.IS_AUTHOR = false; + AboutCommand.REPLACEMENT_ICON = "\uD83C\uDFB6"; AudioHandler.STAY_IN_CHANNEL = config.getStay(); + AudioHandler.SONG_IN_STATUS = config.getSongInStatus(); // set up the command client CommandClientBuilder cb = new CommandClientBuilder() .setPrefix(config.getPrefix()) + .setAlternativePrefix(config.getAltPrefix()) .setOwnerId(config.getOwnerId()) .setEmojis(config.getSuccess(), config.getWarning(), config.getError()) .setHelpWord(config.getHelp()) .addCommands( new AboutCommand(Color.BLUE.brighter(), - "a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v0.0.7)", + "a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v0.0.8)", new String[]{"High-quality music playback", "FairQueueâ„¢ Technology", "Easy to host yourself"}, RECOMMENDED_PERMS), new PingCommand(), @@ -101,10 +104,13 @@ public static void main(String[] args){ new SetavatarCmd(bot), new SetgameCmd(bot), new SetnameCmd(bot), + new SetstatusCmd(bot), new ShutdownCmd(bot) ); if(config.getGame()==null) cb.useDefaultGame(); + else if(config.getGame().equalsIgnoreCase("none")) + cb.setGame(null); else cb.setGame(Game.of(config.getGame())); CommandClient client = cb.build(); diff --git a/src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java b/src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java index 30375f922..330a1a648 100644 --- a/src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java +++ b/src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java @@ -28,6 +28,7 @@ import com.jagrosh.jmusicbot.playlist.Playlist; import com.jagrosh.jmusicbot.queue.FairQueue; import net.dv8tion.jda.core.audio.AudioSendHandler; +import net.dv8tion.jda.core.entities.Game; import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.User; @@ -43,8 +44,9 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler private final List defaultQueue; private final Bot bot; private AudioFrame lastFrame; - private QueuedTrack current; + private long requester; public static boolean STAY_IN_CHANNEL; + public static boolean SONG_IN_STATUS; public AudioHandler(AudioPlayer audioPlayer, Guild guild, Bot bot) { this.audioPlayer = audioPlayer; @@ -57,22 +59,14 @@ public AudioHandler(AudioPlayer audioPlayer, Guild guild, Bot bot) { public int addTrack(AudioTrack track, User user) { - QueuedTrack qt = new QueuedTrack(track, user.getId()); - if(current==null) + if(requester==0) { - current = qt; + requester = user.getIdLong(); audioPlayer.playTrack(track); return -1; } else - { - return queue.add(qt); - } - } - - public QueuedTrack getCurrentTrack() - { - return current; + return queue.add(new QueuedTrack(track, user.getIdLong())); } public FairQueue getQueue() @@ -90,7 +84,7 @@ public void stopAndClear() public boolean isMusicPlaying() { - return guild.getSelfMember().getVoiceState().inVoiceChannel() && current!=null; + return guild.getSelfMember().getVoiceState().inVoiceChannel() && audioPlayer.getPlayingTrack()!=null; } public Set getVotes() @@ -103,12 +97,16 @@ public AudioPlayer getPlayer() return audioPlayer; } + public long getRequester() + { + return requester; + } + public boolean playFromDefault() { if(!defaultQueue.isEmpty()) { - current = new QueuedTrack(defaultQueue.remove(0), null); - audioPlayer.playTrack(current.getTrack()); + audioPlayer.playTrack(defaultQueue.remove(0)); return true; } if(bot.getSettings(guild)==null || bot.getSettings(guild).getDefaultPlaylist()==null) @@ -117,46 +115,44 @@ public boolean playFromDefault() if(pl==null || pl.getItems().isEmpty()) return false; pl.loadTracks(bot.getAudioManager(), (at) -> { - if(current==null) - { - current = new QueuedTrack(at, null); + if(audioPlayer.getPlayingTrack()==null) audioPlayer.playTrack(at); - } else defaultQueue.add(at); }, () -> { - if(pl.getTracks().isEmpty()) - { - current = null; - if(!STAY_IN_CHANNEL) - guild.getAudioManager().closeAudioConnection(); - } + if(pl.getTracks().isEmpty() && !STAY_IN_CHANNEL) + guild.getAudioManager().closeAudioConnection(); }); return true; } @Override public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { + requester = 0; if(queue.isEmpty()) { - current = null; if(!playFromDefault()) { - current = null; + bot.resetGame(); if(!STAY_IN_CHANNEL) guild.getAudioManager().closeAudioConnection(); } } else { - current = queue.pull(); - player.playTrack(current.getTrack()); + QueuedTrack qt = queue.pull(); + requester = qt.getIdentifier(); + player.playTrack(qt.getTrack()); } } @Override public void onTrackStart(AudioPlayer player, AudioTrack track) { votes.clear(); + if(SONG_IN_STATUS && guild.getJDA().getGuilds().size()==1) + { + guild.getJDA().getPresence().setGame(Game.of(track.getInfo().title)); + } } @Override diff --git a/src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java b/src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java index 38c593645..45548e54b 100644 --- a/src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java +++ b/src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java @@ -1,52 +1,52 @@ -/* - * Copyright 2016 John Grosh . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.jmusicbot.audio; - -import com.sedmelluq.discord.lavaplayer.track.AudioTrack; -import com.jagrosh.jmusicbot.queue.Queueable; -import com.jagrosh.jmusicbot.utils.FormatUtil; - -/** - * - * @author John Grosh - */ -public class QueuedTrack implements Queueable { - - private final AudioTrack track; - private final String owner; - - public QueuedTrack(AudioTrack track, String owner) - { - this.track = track; - this.owner = owner; - } - - @Override - public String getIdentifier() { - return owner; - } - - public AudioTrack getTrack() - { - return track; - } - - @Override - public String toString() { - return "`["+FormatUtil.formatTime(track.getDuration())+"]` **" + track.getInfo().title +"** - <@"+owner+">"; - } - -} +/* + * Copyright 2016 John Grosh . + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jmusicbot.audio; + +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import com.jagrosh.jmusicbot.queue.Queueable; +import com.jagrosh.jmusicbot.utils.FormatUtil; + +/** + * + * @author John Grosh + */ +public class QueuedTrack implements Queueable { + + private final AudioTrack track; + private final long owner; + + public QueuedTrack(AudioTrack track, long owner) + { + this.track = track; + this.owner = owner; + } + + @Override + public long getIdentifier() { + return owner; + } + + public AudioTrack getTrack() + { + return track; + } + + @Override + public String toString() { + return "`["+FormatUtil.formatTime(track.getDuration())+"]` **" + track.getInfo().title +"** - <@"+owner+">"; + } + +} diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/ForceskipCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/ForceskipCmd.java index 295b19d17..6bbab5995 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/ForceskipCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/ForceskipCmd.java @@ -39,13 +39,8 @@ public ForceskipCmd(Bot bot) @Override public void doCommand(CommandEvent event) { AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); - User u; - try { - u = event.getJDA().getUserById(handler.getCurrentTrack().getIdentifier()); - } catch(Exception e) { - u = null; - } - event.reply(event.getClient().getSuccess()+" Skipped **"+handler.getCurrentTrack().getTrack().getInfo().title + User u = event.getJDA().getUserById(handler.getRequester()); + event.reply(event.getClient().getSuccess()+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title +"** (requested by "+(u==null ? "someone" : "**"+u.getName()+"**")+")"); handler.getPlayer().stopTrack(); } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/NowplayingCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/NowplayingCmd.java index d217a3f94..ebe401b59 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/NowplayingCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/NowplayingCmd.java @@ -19,7 +19,6 @@ import com.jagrosh.jmusicbot.Bot; import com.jagrosh.jmusicbot.audio.AudioHandler; import com.jagrosh.jmusicbot.utils.FormatUtil; -import com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioTrack; import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack; import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.core.Permission; @@ -54,28 +53,23 @@ public void doCommand(CommandEvent event) { return; } - if(ah.getCurrentTrack().getIdentifier()!=null) + if(ah.getRequester()!=0) { - User u; - try { - u = event.getJDA().getUserById(ah.getCurrentTrack().getIdentifier()); - } catch(Exception e) { - u = null; - } + User u = event.getJDA().getUserById(ah.getRequester()); if(u==null) - eb.setAuthor("Unknown (ID:"+ah.getCurrentTrack().getIdentifier()+")", null, null); + eb.setAuthor("Unknown (ID:"+ah.getRequester()+")", null, null); else eb.setAuthor(u.getName()+"#"+u.getDiscriminator(), null, u.getEffectiveAvatarUrl()); } try { - eb.setTitle(ah.getCurrentTrack().getTrack().getInfo().title, ah.getCurrentTrack().getTrack().getInfo().uri); + eb.setTitle(ah.getPlayer().getPlayingTrack().getInfo().title, ah.getPlayer().getPlayingTrack().getInfo().uri); } catch(Exception e) { - eb.setTitle(ah.getCurrentTrack().getTrack().getInfo().title); + eb.setTitle(ah.getPlayer().getPlayingTrack().getInfo().title); } - if(ah.getCurrentTrack().getTrack() instanceof YoutubeAudioTrack) - eb.setThumbnail("https://img.youtube.com/vi/"+ah.getCurrentTrack().getTrack().getIdentifier()+"/maxresdefault.jpg"); + if(ah.getPlayer().getPlayingTrack() instanceof YoutubeAudioTrack) + eb.setThumbnail("https://img.youtube.com/vi/"+ah.getPlayer().getPlayingTrack().getIdentifier()+"/maxresdefault.jpg"); eb.setDescription(FormatUtil.embedformattedAudio(ah)); diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/PauseCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/PauseCmd.java index deff9b0a6..e78065505 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/PauseCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/PauseCmd.java @@ -44,7 +44,7 @@ public void doCommand(CommandEvent event) { return; } handler.getPlayer().setPaused(true); - event.replySuccess("Paused **"+handler.getCurrentTrack().getTrack().getInfo().title+"**. Type `"+event.getClient().getPrefix()+"play` to unpause!"); + event.replySuccess("Paused **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**. Type `"+event.getClient().getPrefix()+"play` to unpause!"); } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/PlayCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/PlayCmd.java index d5329e9c1..9e14a3dd5 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/PlayCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/PlayCmd.java @@ -51,7 +51,7 @@ public void doCommand(CommandEvent event) { if(event.getArgs().isEmpty()) { AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); - if(handler!=null && handler.getCurrentTrack()!=null && handler.getPlayer().isPaused()) + if(handler!=null && handler.getPlayer().getPlayingTrack()!=null && handler.getPlayer().isPaused()) { boolean isDJ = event.getMember().hasPermission(Permission.MANAGE_SERVER); if(!isDJ) @@ -61,7 +61,7 @@ public void doCommand(CommandEvent event) { else { handler.getPlayer().setPaused(false); - event.replySuccess("Resumed **"+handler.getCurrentTrack().getTrack().getInfo().title+"**."); + event.replySuccess("Resumed **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**."); } return; } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/QueueCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/QueueCmd.java index 2dd301f26..6dd54fb35 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/QueueCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/QueueCmd.java @@ -65,7 +65,7 @@ public void doCommand(CommandEvent event) { if(list.isEmpty()) { event.replyWarning("There is no music in the queue!" - +(!ah.isMusicPlaying() ? "" : " Now playing:\n\n**"+ah.getCurrentTrack().getTrack().getInfo().title+"**\n"+FormatUtil.embedformattedAudio(ah))); + +(!ah.isMusicPlaying() ? "" : " Now playing:\n\n**"+ah.getPlayer().getPlayingTrack().getInfo().title+"**\n"+FormatUtil.embedformattedAudio(ah))); return; } String[] songs = new String[list.size()]; @@ -87,8 +87,8 @@ public void doCommand(CommandEvent event) { private String getQueueTitle(AudioHandler ah, String success, int songslength, long total) { StringBuilder sb = new StringBuilder(); - if(ah.getCurrentTrack()!=null) - sb.append("**").append(ah.getCurrentTrack().getTrack().getInfo().title).append("**\n").append(FormatUtil.embedformattedAudio(ah)).append("\n\n"); + if(ah.getPlayer().getPlayingTrack()!=null) + sb.append("**").append(ah.getPlayer().getPlayingTrack().getInfo().title).append("**\n").append(FormatUtil.embedformattedAudio(ah)).append("\n\n"); return sb.append(success).append(" Current Queue | ").append(songslength).append(" entries | `").append(FormatUtil.formatTime(total)).append("` ").toString(); } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/RemoveCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/RemoveCmd.java index d73926487..eabe7f127 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/RemoveCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/RemoveCmd.java @@ -21,7 +21,6 @@ import com.jagrosh.jmusicbot.audio.QueuedTrack; import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.entities.User; -import net.dv8tion.jda.core.utils.PermissionUtil; /** * @@ -50,7 +49,7 @@ public void doCommand(CommandEvent event) { } if(event.getArgs().equalsIgnoreCase("all")) { - int count = handler.getQueue().removeAll(event.getAuthor().getId()); + int count = handler.getQueue().removeAll(event.getAuthor().getIdLong()); if(count==0) event.reply(event.getClient().getWarning()+" You don't have any songs in the queue!"); else @@ -72,7 +71,7 @@ public void doCommand(CommandEvent event) { if(!isDJ) isDJ = event.getMember().getRoles().contains(event.getGuild().getRoleById(bot.getSettings(event.getGuild()).getRoleId())); QueuedTrack qt = handler.getQueue().get(pos-1); - if(qt.getIdentifier().equals(event.getAuthor().getId())) + if(qt.getIdentifier()==event.getAuthor().getIdLong()) { handler.getQueue().remove(pos-1); event.reply(event.getClient().getSuccess()+" Removed **"+qt.getTrack().getInfo().title+"** from the queue"); diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/SetstatusCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/SetstatusCmd.java new file mode 100644 index 000000000..ed72d00e6 --- /dev/null +++ b/src/main/java/com/jagrosh/jmusicbot/commands/SetstatusCmd.java @@ -0,0 +1,56 @@ +/* + * Copyright 2017 John Grosh . + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jmusicbot.commands; + +import com.jagrosh.jdautilities.commandclient.Command; +import com.jagrosh.jdautilities.commandclient.CommandEvent; +import com.jagrosh.jmusicbot.Bot; +import net.dv8tion.jda.core.OnlineStatus; + +/** + * + * @author John Grosh + */ +public class SetstatusCmd extends Command { + + public SetstatusCmd(Bot bot) + { + this.name = "setstatus"; + this.help = "sets the status the bot displays"; + this.arguments = "[game]"; + this.ownerCommand = true; + this.category = bot.OWNER; + } + + @Override + protected void execute(CommandEvent event) { + try { + OnlineStatus status = OnlineStatus.fromKey(event.getArgs()); + if(status==OnlineStatus.UNKNOWN) + { + event.replyError("Please include one of the following statuses: `ONLINE`, `IDLE`, `DND`, `INVISIBLE`"); + } + else + { + event.getJDA().getPresence().setStatus(status); + event.replySuccess("Set the status to `"+status.getKey().toUpperCase()+"`"); + } + } catch(Exception e) { + event.reply(event.getClient().getError()+" The status could not be set!"); + } + } + +} diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/ShuffleCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/ShuffleCmd.java index 0c7ecb6a8..f00ea98dc 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/ShuffleCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/ShuffleCmd.java @@ -1,54 +1,54 @@ -/* - * Copyright 2016 John Grosh . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.jmusicbot.commands; - -import com.jagrosh.jdautilities.commandclient.CommandEvent; -import com.jagrosh.jmusicbot.Bot; -import com.jagrosh.jmusicbot.audio.AudioHandler; - -/** - * - * @author John Grosh - */ -public class ShuffleCmd extends MusicCommand { - - public ShuffleCmd(Bot bot) - { - super(bot); - this.name = "shuffle"; - this.help = "shuffles songs you have added"; - this.beListening = true; - this.bePlaying = true; - } - - @Override - public void doCommand(CommandEvent event) { - AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); - int s = handler.getQueue().shuffle(event.getAuthor().getId()); - switch (s) { - case 0: - event.reply(event.getClient().getError()+" You don't have any music in the queue to shuffle!"); - break; - case 1: - event.reply(event.getClient().getWarning()+" You only have one song in the queue!"); - break; - default: - event.reply(event.getClient().getSuccess()+" You successfully shuffled your "+s+" entries."); - break; - } - } - -} +/* + * Copyright 2016 John Grosh . + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jmusicbot.commands; + +import com.jagrosh.jdautilities.commandclient.CommandEvent; +import com.jagrosh.jmusicbot.Bot; +import com.jagrosh.jmusicbot.audio.AudioHandler; + +/** + * + * @author John Grosh + */ +public class ShuffleCmd extends MusicCommand { + + public ShuffleCmd(Bot bot) + { + super(bot); + this.name = "shuffle"; + this.help = "shuffles songs you have added"; + this.beListening = true; + this.bePlaying = true; + } + + @Override + public void doCommand(CommandEvent event) { + AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); + int s = handler.getQueue().shuffle(event.getAuthor().getIdLong()); + switch (s) { + case 0: + event.reply(event.getClient().getError()+" You don't have any music in the queue to shuffle!"); + break; + case 1: + event.reply(event.getClient().getWarning()+" You only have one song in the queue!"); + break; + default: + event.reply(event.getClient().getSuccess()+" You successfully shuffled your "+s+" entries."); + break; + } + } + +} diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/SkipCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/SkipCmd.java index 934f4e5f2..2032f5c6f 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/SkipCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/SkipCmd.java @@ -39,10 +39,9 @@ public SkipCmd(Bot bot) @Override public void doCommand(CommandEvent event) { AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); - if(event.getAuthor().getId().equals(handler.getCurrentTrack().getIdentifier())) + if(event.getAuthor().getIdLong()==handler.getRequester()) { - event.reply(event.getClient().getSuccess()+" Skipped **"+handler.getCurrentTrack().getTrack().getInfo().title - +"**"); + event.reply(event.getClient().getSuccess()+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**"); handler.getPlayer().stopTrack(); } else @@ -63,14 +62,9 @@ public void doCommand(CommandEvent event) { msg+= skippers+" votes, "+required+"/"+listeners+" needed]`"; if(skippers>=required) { - User u; - try { - u = event.getJDA().getUserById(handler.getCurrentTrack().getIdentifier()); - } catch(Exception e) { - u = null; - } - msg+="\n"+event.getClient().getSuccess()+" Skipped **"+handler.getCurrentTrack().getTrack().getInfo().title - +"**"+(handler.getCurrentTrack().getIdentifier()==null ? "" : " (requested by "+(u==null ? "someone" : "**"+u.getName()+"**")+")"); + User u = event.getJDA().getUserById(handler.getRequester()); + msg+="\n"+event.getClient().getSuccess()+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title + +"**"+(handler.getRequester()==0 ? "" : " (requested by "+(u==null ? "someone" : "**"+u.getName()+"**")+")"); handler.getPlayer().stopTrack(); } event.reply(msg); diff --git a/src/main/java/com/jagrosh/jmusicbot/gui/GuildsPanel.java b/src/main/java/com/jagrosh/jmusicbot/gui/GuildsPanel.java index 907881c07..df3b0789d 100644 --- a/src/main/java/com/jagrosh/jmusicbot/gui/GuildsPanel.java +++ b/src/main/java/com/jagrosh/jmusicbot/gui/GuildsPanel.java @@ -1,111 +1,111 @@ -/* - * Copyright 2017 John Grosh . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.jmusicbot.gui; - -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.util.List; -import javax.swing.DefaultListModel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import com.jagrosh.jmusicbot.Bot; -import com.jagrosh.jmusicbot.audio.AudioHandler; -import com.jagrosh.jmusicbot.utils.FormatUtil; -import net.dv8tion.jda.core.entities.Guild; - -/** - * - * @author John Grosh - */ -public class GuildsPanel extends JPanel { - - private final Bot bot; - private final JList guildList; - private final JTextArea guildQueue; - private int index = -1; - - public GuildsPanel(Bot bot) - { - super(); - super.setLayout(new GridBagLayout()); - this.bot = bot; - - guildList = new JList(); - guildQueue = new JTextArea(); - guildList.setModel(new DefaultListModel()); - guildList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - guildList.setFixedCellHeight(20); - guildList.setPreferredSize(new Dimension(100,300)); - guildQueue.setPreferredSize(new Dimension(300,300)); - guildQueue.setEditable(false); - JScrollPane pane = new JScrollPane(); - JScrollPane pane2 = new JScrollPane(); - pane.setViewportView(guildList); - pane2.setViewportView(guildQueue); - GridBagConstraints c = new GridBagConstraints(); - c.fill = GridBagConstraints.BOTH; - c.anchor = GridBagConstraints.LINE_START; - c.gridx = 0; - c.gridwidth = 1; - super.add(pane, c); - c.gridx = 1; - c.gridwidth = 3; - super.add(pane2, c); - //bot.registerPanel(this); - guildList.addListSelectionListener((ListSelectionEvent e) -> { - index = guildList.getSelectedIndex(); - //bot.updatePanel(); - }); - } - - public void updateList(List guilds) - { - String[] strs = new String[guilds.size()]; - for(int i=0; i. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jmusicbot.gui; + +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.List; +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import com.jagrosh.jmusicbot.Bot; +import com.jagrosh.jmusicbot.audio.AudioHandler; +import com.jagrosh.jmusicbot.utils.FormatUtil; +import net.dv8tion.jda.core.entities.Guild; + +/** + * + * @author John Grosh + */ +public class GuildsPanel extends JPanel { + + private final Bot bot; + private final JList guildList; + private final JTextArea guildQueue; + private int index = -1; + + public GuildsPanel(Bot bot) + { + super(); + super.setLayout(new GridBagLayout()); + this.bot = bot; + + guildList = new JList(); + guildQueue = new JTextArea(); + guildList.setModel(new DefaultListModel()); + guildList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + guildList.setFixedCellHeight(20); + guildList.setPreferredSize(new Dimension(100,300)); + guildQueue.setPreferredSize(new Dimension(300,300)); + guildQueue.setEditable(false); + JScrollPane pane = new JScrollPane(); + JScrollPane pane2 = new JScrollPane(); + pane.setViewportView(guildList); + pane2.setViewportView(guildQueue); + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.LINE_START; + c.gridx = 0; + c.gridwidth = 1; + super.add(pane, c); + c.gridx = 1; + c.gridwidth = 3; + super.add(pane2, c); + //bot.registerPanel(this); + guildList.addListSelectionListener((ListSelectionEvent e) -> { + index = guildList.getSelectedIndex(); + //bot.updatePanel(); + }); + } + + public void updateList(List guilds) + { + String[] strs = new String[guilds.size()]; + for(int i=0; i { private final List list = new ArrayList<>(); - private final Set set = new HashSet<>(); + private final Set set = new HashSet<>(); public int add(T item) { int lastIndex; for(lastIndex=list.size()-1; lastIndex>-1; lastIndex--) - if(list.get(lastIndex).getIdentifier().equals(item.getIdentifier())) + if(list.get(lastIndex).getIdentifier()==item.getIdentifier()) break; lastIndex++; set.clear(); @@ -77,12 +77,12 @@ public T remove(int index) return list.remove(index); } - public int removeAll(String identifier) + public int removeAll(long identifier) { int count = 0; for(int i=list.size()-1; i>=0; i--) { - if(list.get(i).getIdentifier().equals(identifier)) + if(list.get(i).getIdentifier()==identifier) { list.remove(i); count++; @@ -96,12 +96,12 @@ public void clear() list.clear(); } - public int shuffle(String identifier) + public int shuffle(long identifier) { List iset = new ArrayList<>(); for(int i=0; i. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.jmusicbot.queue; - -/** - * - * @author John Grosh - */ -public interface Queueable { - - public String getIdentifier(); -} +/* + * Copyright 2016 John Grosh . + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jmusicbot.queue; + +/** + * + * @author John Grosh + */ +public interface Queueable { + + public long getIdentifier(); +} diff --git a/src/main/java/com/jagrosh/jmusicbot/utils/FormatUtil.java b/src/main/java/com/jagrosh/jmusicbot/utils/FormatUtil.java index 6fe3b647a..4047b7c4c 100644 --- a/src/main/java/com/jagrosh/jmusicbot/utils/FormatUtil.java +++ b/src/main/java/com/jagrosh/jmusicbot/utils/FormatUtil.java @@ -52,13 +52,13 @@ else if (!handler.isMusicPlaying()) return "No music playing\n\u23F9 "+progressBar(-1)+" "+volumeIcon(handler.getPlayer().getVolume()); else { - String userid = handler.getCurrentTrack().getIdentifier(); - AudioTrack track = handler.getCurrentTrack().getTrack(); + long userid = handler.getRequester(); + AudioTrack track = handler.getPlayer().getPlayingTrack(); String title = track.getInfo().title; if(!NO_PROGRESS_BAR_IN_TOPIC && title.length()>30) title = title.substring(0,27)+"..."; double progress = (double)track.getPosition()/track.getDuration(); - String str = "**"+title+"** ["+(userid==null ? "autoplay" : "<@"+userid+">")+"]"; + String str = "**"+title+"** ["+(userid==0 ? "autoplay" : "<@"+userid+">")+"]"; String str2 = "\n"+(handler.getPlayer().isPaused()?"\u23F8":"\u25B6")+" " +(NO_PROGRESS_BAR_IN_TOPIC ? "["+formatTime(track.getDuration())+"] " : progressBar(progress)+" ["+formatTime(track.getPosition()) + "/" + formatTime(track.getDuration())+"] ") @@ -69,8 +69,8 @@ else if (!handler.isMusicPlaying()) public static String embedformattedAudio(AudioHandler ah) { - return (ah.getPlayer().isPaused()?"\u23F8":"\u25B6")+" "+progressBar((double)ah.getCurrentTrack().getTrack().getPosition()/ah.getCurrentTrack().getTrack().getDuration()) - +" `["+formatTime(ah.getCurrentTrack().getTrack().getPosition()) + "/" + formatTime(ah.getCurrentTrack().getTrack().getDuration()) +"]` " + return (ah.getPlayer().isPaused()?"\u23F8":"\u25B6")+" "+progressBar((double)ah.getPlayer().getPlayingTrack().getPosition()/ah.getPlayer().getPlayingTrack().getDuration()) + +" `["+formatTime(ah.getPlayer().getPlayingTrack().getPosition()) + "/" + formatTime(ah.getPlayer().getPlayingTrack().getDuration()) +"]` " +volumeIcon(ah.getPlayer().getVolume()); }