diff --git a/README.md b/README.md index 14d28c1b9..f3b83af1c 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ ## Extra Features - Play command works on spotify track, album or playlist links (Right click -> Share -> Copy link to playlist) +- Server-specific emojis used by the bot, configured by the setemoji command ## Setup - Get the latest release at https://github.com/cmorley191/MusicBot/releases diff --git a/src/main/java/com/jagrosh/jmusicbot/Bot.java b/src/main/java/com/jagrosh/jmusicbot/Bot.java index 395445e52..ab1372cf2 100644 --- a/src/main/java/com/jagrosh/jmusicbot/Bot.java +++ b/src/main/java/com/jagrosh/jmusicbot/Bot.java @@ -17,6 +17,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; + +import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.commons.waiter.EventWaiter; import com.jagrosh.jmusicbot.audio.AloneInVoiceHandler; import com.jagrosh.jmusicbot.audio.AudioHandler; @@ -25,6 +27,7 @@ import com.jagrosh.jmusicbot.gui.GUI; import com.jagrosh.jmusicbot.playlist.PlaylistLoader; import com.jagrosh.jmusicbot.playlist.SpotifyAPI; +import com.jagrosh.jmusicbot.settings.Settings; import com.jagrosh.jmusicbot.settings.SettingsManager; import java.util.Objects; import net.dv8tion.jda.api.JDA; @@ -173,4 +176,45 @@ public void setGUI(GUI gui) { this.gui = gui; } + + private Settings getSettings(CommandEvent event) { + try { return getSettingsManager().getSettings(event.getGuild()); } + catch (IllegalStateException ignore) {} + return getSettingsManager().getSettings(null); + } + + public String getSuccess(CommandEvent event) + { + String guildSetting = getSettings(event).getSuccess(); + if (guildSetting != null) return guildSetting; + return getConfig().getSuccess(); + } + + public String getWarning(CommandEvent event) + { + String guildSetting = getSettings(event).getWarning(); + if (guildSetting != null) return guildSetting; + return getConfig().getWarning(); + } + + public String getError(CommandEvent event) + { + String guildSetting = getSettings(event).getError(); + if (guildSetting != null) return guildSetting; + return getConfig().getError(); + } + + public String getLoading(CommandEvent event) + { + String guildSetting = getSettings(event).getLoading(); + if (guildSetting != null) return guildSetting; + return getConfig().getLoading(); + } + + public String getSearching(CommandEvent event) + { + String guildSetting = getSettings(event).getSearching(); + if (guildSetting != null) return guildSetting; + return getConfig().getSearching(); + } } diff --git a/src/main/java/com/jagrosh/jmusicbot/BotConfig.java b/src/main/java/com/jagrosh/jmusicbot/BotConfig.java index e45357576..ee5be1328 100644 --- a/src/main/java/com/jagrosh/jmusicbot/BotConfig.java +++ b/src/main/java/com/jagrosh/jmusicbot/BotConfig.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Collections; import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.entities.Activity; diff --git a/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java b/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java index dea43b131..5dcf81788 100644 --- a/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java +++ b/src/main/java/com/jagrosh/jmusicbot/JMusicBot.java @@ -125,6 +125,7 @@ public static void main(String[] args) new SkipratioCmd(bot), new SettcCmd(bot), new SetvcCmd(bot), + new SetemojiCmd(bot), new AutoplaylistCmd(bot), new DebugCmd(bot), diff --git a/src/main/java/com/jagrosh/jmusicbot/audio/PlayerManager.java b/src/main/java/com/jagrosh/jmusicbot/audio/PlayerManager.java index 0309fa8ee..ec4721950 100644 --- a/src/main/java/com/jagrosh/jmusicbot/audio/PlayerManager.java +++ b/src/main/java/com/jagrosh/jmusicbot/audio/PlayerManager.java @@ -20,7 +20,6 @@ import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager; -import com.typesafe.config.Config; import net.dv8tion.jda.api.entities.Guild; /** diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/MusicCommand.java b/src/main/java/com/jagrosh/jmusicbot/commands/MusicCommand.java index 9740a7af7..f6d717f77 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/MusicCommand.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/MusicCommand.java @@ -53,13 +53,13 @@ protected void execute(CommandEvent event) { event.getMessage().delete().queue(); } catch(PermissionException ignore){} - event.replyInDm(event.getClient().getError()+" You can only use that command in "+tchannel.getAsMention()+"!"); + event.replyInDm(bot.getError(event)+" You can only use that command in "+tchannel.getAsMention()+"!"); return; } bot.getPlayerManager().setUpHandler(event.getGuild()); // no point constantly checking for this later if(bePlaying && !((AudioHandler)event.getGuild().getAudioManager().getSendingHandler()).isMusicPlaying(event.getJDA())) { - event.reply(event.getClient().getError()+" There must be music playing to use that!"); + event.reply(bot.getError(event)+" There must be music playing to use that!"); return; } if(beListening) @@ -70,14 +70,14 @@ protected void execute(CommandEvent event) GuildVoiceState userState = event.getMember().getVoiceState(); if(!userState.inVoiceChannel() || userState.isDeafened() || (current!=null && !userState.getChannel().equals(current))) { - event.replyError("You must be listening in "+(current==null ? "a voice channel" : current.getAsMention())+" to use that!"); + event.reply(bot.getError(event)+"You must be listening in "+(current==null ? "a voice channel" : current.getAsMention())+" to use that!"); return; } VoiceChannel afkChannel = userState.getGuild().getAfkChannel(); if(afkChannel != null && afkChannel.equals(userState.getChannel())) { - event.replyError("You cannot use that command in an AFK channel!"); + event.reply(bot.getError(event)+"You cannot use that command in an AFK channel!"); return; } @@ -89,7 +89,7 @@ protected void execute(CommandEvent event) } catch(PermissionException ex) { - event.reply(event.getClient().getError()+" I am unable to connect to "+userState.getChannel().getAsMention()+"!"); + event.reply(bot.getError(event)+" I am unable to connect to "+userState.getChannel().getAsMention()+"!"); return; } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/admin/PrefixCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/admin/PrefixCmd.java index 1eaea786c..9835542a6 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/admin/PrefixCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/admin/PrefixCmd.java @@ -26,8 +26,11 @@ */ public class PrefixCmd extends AdminCommand { + private final Bot bot; + public PrefixCmd(Bot bot) { + this.bot = bot; this.name = "prefix"; this.help = "sets a server-specific prefix"; this.arguments = ""; @@ -39,7 +42,7 @@ protected void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { - event.replyError("Please include a prefix or NONE"); + event.reply(bot.getError(event)+"Please include a prefix or NONE"); return; } @@ -47,12 +50,12 @@ protected void execute(CommandEvent event) if(event.getArgs().equalsIgnoreCase("none")) { s.setPrefix(null); - event.replySuccess("Prefix cleared."); + event.reply(bot.getSuccess(event)+"Prefix cleared."); } else { s.setPrefix(event.getArgs()); - event.replySuccess("Custom prefix set to `" + event.getArgs() + "` on *" + event.getGuild().getName() + "*"); + event.reply(bot.getSuccess(event)+"Custom prefix set to `" + event.getArgs() + "` on *" + event.getGuild().getName() + "*"); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/admin/SetdjCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/admin/SetdjCmd.java index 05038cfaa..9607f9bec 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/admin/SetdjCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/admin/SetdjCmd.java @@ -30,8 +30,11 @@ */ public class SetdjCmd extends AdminCommand { + private final Bot bot; + public SetdjCmd(Bot bot) { + this.bot = bot; this.name = "setdj"; this.help = "sets the DJ role for certain music commands"; this.arguments = ""; @@ -43,26 +46,26 @@ protected void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { - event.reply(event.getClient().getError()+" Please include a role name or NONE"); + event.reply(bot.getError(event)+" Please include a role name or NONE"); return; } Settings s = event.getClient().getSettingsFor(event.getGuild()); if(event.getArgs().equalsIgnoreCase("none")) { s.setDJRole(null); - event.reply(event.getClient().getSuccess()+" DJ role cleared; Only Admins can use the DJ commands."); + event.reply(bot.getSuccess(event)+" DJ role cleared; Only Admins can use the DJ commands."); } else { List list = FinderUtil.findRoles(event.getArgs(), event.getGuild()); if(list.isEmpty()) - event.reply(event.getClient().getWarning()+" No Roles found matching \""+event.getArgs()+"\""); + event.reply(bot.getWarning(event)+" No Roles found matching \""+event.getArgs()+"\""); else if (list.size()>1) - event.reply(event.getClient().getWarning()+FormatUtil.listOfRoles(list, event.getArgs())); + event.reply(bot.getWarning(event)+FormatUtil.listOfRoles(list, event.getArgs())); else { s.setDJRole(list.get(0)); - event.reply(event.getClient().getSuccess()+" DJ commands can now be used by users with the **"+list.get(0).getName()+"** role."); + event.reply(bot.getSuccess(event)+" DJ commands can now be used by users with the **"+list.get(0).getName()+"** role."); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/admin/SettcCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/admin/SettcCmd.java index 568085d1f..b58cd92c8 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/admin/SettcCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/admin/SettcCmd.java @@ -30,8 +30,11 @@ */ public class SettcCmd extends AdminCommand { + private final Bot bot; + public SettcCmd(Bot bot) { + this.bot = bot; this.name = "settc"; this.help = "sets the text channel for music commands"; this.arguments = ""; @@ -43,26 +46,26 @@ protected void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { - event.reply(event.getClient().getError()+" Please include a text channel or NONE"); + event.reply(bot.getError(event)+" Please include a text channel or NONE"); return; } Settings s = event.getClient().getSettingsFor(event.getGuild()); if(event.getArgs().equalsIgnoreCase("none")) { s.setTextChannel(null); - event.reply(event.getClient().getSuccess()+" Music commands can now be used in any channel"); + event.reply(bot.getSuccess(event)+" Music commands can now be used in any channel"); } else { List list = FinderUtil.findTextChannels(event.getArgs(), event.getGuild()); if(list.isEmpty()) - event.reply(event.getClient().getWarning()+" No Text Channels found matching \""+event.getArgs()+"\""); + event.reply(bot.getWarning(event)+" No Text Channels found matching \""+event.getArgs()+"\""); else if (list.size()>1) - event.reply(event.getClient().getWarning()+FormatUtil.listOfTChannels(list, event.getArgs())); + event.reply(bot.getWarning(event)+FormatUtil.listOfTChannels(list, event.getArgs())); else { s.setTextChannel(list.get(0)); - event.reply(event.getClient().getSuccess()+" Music commands can now only be used in <#"+list.get(0).getId()+">"); + event.reply(bot.getSuccess(event)+" Music commands can now only be used in <#"+list.get(0).getId()+">"); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/admin/SetvcCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/admin/SetvcCmd.java index e8f66639e..180d538b2 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/admin/SetvcCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/admin/SetvcCmd.java @@ -30,8 +30,11 @@ */ public class SetvcCmd extends AdminCommand { + private final Bot bot; + public SetvcCmd(Bot bot) { + this.bot = bot; this.name = "setvc"; this.help = "sets the voice channel for playing music"; this.arguments = ""; @@ -43,26 +46,26 @@ protected void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { - event.reply(event.getClient().getError()+" Please include a voice channel or NONE"); + event.reply(bot.getError(event)+" Please include a voice channel or NONE"); return; } Settings s = event.getClient().getSettingsFor(event.getGuild()); if(event.getArgs().equalsIgnoreCase("none")) { s.setVoiceChannel(null); - event.reply(event.getClient().getSuccess()+" Music can now be played in any channel"); + event.reply(bot.getSuccess(event)+" Music can now be played in any channel"); } else { List list = FinderUtil.findVoiceChannels(event.getArgs(), event.getGuild()); if(list.isEmpty()) - event.reply(event.getClient().getWarning()+" No Voice Channels found matching \""+event.getArgs()+"\""); + event.reply(bot.getWarning(event)+" No Voice Channels found matching \""+event.getArgs()+"\""); else if (list.size()>1) - event.reply(event.getClient().getWarning()+FormatUtil.listOfVChannels(list, event.getArgs())); + event.reply(bot.getWarning(event)+FormatUtil.listOfVChannels(list, event.getArgs())); else { s.setVoiceChannel(list.get(0)); - event.reply(event.getClient().getSuccess()+" Music can now only be played in "+list.get(0).getAsMention()); + event.reply(bot.getSuccess(event)+" Music can now only be played in "+list.get(0).getAsMention()); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/admin/SkipratioCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/admin/SkipratioCmd.java index f2a06d7b6..057a97c42 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/admin/SkipratioCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/admin/SkipratioCmd.java @@ -26,8 +26,11 @@ */ public class SkipratioCmd extends AdminCommand { + private final Bot bot; + public SkipratioCmd(Bot bot) { + this.bot = bot; this.name = "setskip"; this.help = "sets a server-specific skip percentage"; this.arguments = "<0 - 100>"; @@ -42,16 +45,16 @@ protected void execute(CommandEvent event) int val = Integer.parseInt(event.getArgs().endsWith("%") ? event.getArgs().substring(0,event.getArgs().length()-1) : event.getArgs()); if( val < 0 || val > 100) { - event.replyError("The provided value must be between 0 and 100!"); + event.reply(bot.getError(event)+"The provided value must be between 0 and 100!"); return; } Settings s = event.getClient().getSettingsFor(event.getGuild()); s.setSkipRatio(val / 100.0); - event.replySuccess("Skip percentage has been set to `" + val + "%` of listeners on *" + event.getGuild().getName() + "*"); + event.reply(bot.getSuccess(event)+"Skip percentage has been set to `" + val + "%` of listeners on *" + event.getGuild().getName() + "*"); } catch(NumberFormatException ex) { - event.replyError("Please include an integer between 0 and 100 (default is 55). This number is the percentage of listening users that must vote to skip a song."); + event.reply(bot.getError(event)+"Please include an integer between 0 and 100 (default is 55). This number is the percentage of listening users that must vote to skip a song."); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceRemoveCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceRemoveCmd.java index 53594cda0..0d25f73af 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceRemoveCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceRemoveCmd.java @@ -51,14 +51,14 @@ public void doCommand(CommandEvent event) { if (event.getArgs().isEmpty()) { - event.replyError("You need to mention a user!"); + event.reply(bot.getError(event)+"You need to mention a user!"); return; } AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler(); if (handler.getQueue().isEmpty()) { - event.replyError("There is nothing in the queue!"); + event.reply(bot.getError(event)+"There is nothing in the queue!"); return; } @@ -68,7 +68,7 @@ public void doCommand(CommandEvent event) if(found.isEmpty()) { - event.replyError("Unable to find the user!"); + event.reply(bot.getError(event)+"Unable to find the user!"); return; } else if(found.size()>1) @@ -109,11 +109,11 @@ private void removeAllEntries(User target, CommandEvent event) int count = ((AudioHandler) event.getGuild().getAudioManager().getSendingHandler()).getQueue().removeAll(target.getIdLong()); if (count == 0) { - event.replyWarning("**"+target.getName()+"** doesn't have any songs in the queue!"); + event.reply(bot.getWarning(event)+"**"+target.getName()+"** doesn't have any songs in the queue!"); } else { - event.replySuccess("Successfully removed `"+count+"` entries from **"+target.getName()+"**#"+target.getDiscriminator()+"."); + event.reply(bot.getSuccess(event)+"Successfully removed `"+count+"` entries from **"+target.getName()+"**#"+target.getDiscriminator()+"."); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceskipCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceskipCmd.java index 9d852fc76..a902d8ea0 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceskipCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceskipCmd.java @@ -20,7 +20,6 @@ import com.jagrosh.jmusicbot.audio.AudioHandler; import com.jagrosh.jmusicbot.audio.RequestMetadata; import com.jagrosh.jmusicbot.commands.DJCommand; -import net.dv8tion.jda.api.entities.User; /** * @@ -42,7 +41,7 @@ public void doCommand(CommandEvent event) { AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); RequestMetadata rm = handler.getRequestMetadata(); - event.reply(event.getClient().getSuccess()+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title + event.reply(bot.getSuccess(event)+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title +"** "+(rm.getOwner() == 0L ? "(autoplay)" : "(requested by **" + rm.user.username + "**)")); handler.getPlayer().stopTrack(); } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/MoveTrackCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/MoveTrackCmd.java index 7c652f903..816f65461 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/MoveTrackCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/MoveTrackCmd.java @@ -33,7 +33,7 @@ public void doCommand(CommandEvent event) String[] parts = event.getArgs().split("\\s+", 2); if(parts.length < 2) { - event.replyError("Please include two valid indexes."); + event.reply(bot.getError(event)+"Please include two valid indexes."); return; } @@ -45,13 +45,13 @@ public void doCommand(CommandEvent event) } catch (NumberFormatException e) { - event.replyError("Please provide two valid indexes."); + event.reply(bot.getError(event)+"Please provide two valid indexes."); return; } if (from == to) { - event.replyError("Can't move a track to the same position."); + event.reply(bot.getError(event)+"Can't move a track to the same position."); return; } @@ -61,13 +61,13 @@ public void doCommand(CommandEvent event) if (isUnavailablePosition(queue, from)) { String reply = String.format("`%d` is not a valid position in the queue!", from); - event.replyError(reply); + event.reply(bot.getError(event)+reply); return; } if (isUnavailablePosition(queue, to)) { String reply = String.format("`%d` is not a valid position in the queue!", to); - event.replyError(reply); + event.reply(bot.getError(event)+reply); return; } @@ -75,7 +75,7 @@ public void doCommand(CommandEvent event) QueuedTrack track = queue.moveItem(from - 1, to - 1); String trackTitle = track.getTrack().getInfo().title; String reply = String.format("Moved **%s** from position `%d` to `%d`.", trackTitle, from, to); - event.replySuccess(reply); + event.reply(bot.getSuccess(event)+reply); } private static boolean isUnavailablePosition(FairQueue queue, int position) diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/PauseCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/PauseCmd.java index 9a923f02c..201369f78 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/PauseCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/PauseCmd.java @@ -41,10 +41,10 @@ public void doCommand(CommandEvent event) AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); if(handler.getPlayer().isPaused()) { - event.replyWarning("The player is already paused! Use `"+event.getClient().getPrefix()+"play` to unpause!"); + event.reply(bot.getWarning(event)+"The player is already paused! Use `"+event.getClient().getPrefix()+"play` to unpause!"); return; } handler.getPlayer().setPaused(true); - event.replySuccess("Paused **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**. Type `"+event.getClient().getPrefix()+"play` to unpause!"); + event.reply(bot.getSuccess(event)+"Paused **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**. Type `"+event.getClient().getPrefix()+"play` to unpause!"); } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/PlaynextCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/PlaynextCmd.java index 91d79be14..f906f9b89 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/PlaynextCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/PlaynextCmd.java @@ -33,12 +33,10 @@ */ public class PlaynextCmd extends DJCommand { - private final String loadingEmoji; public PlaynextCmd(Bot bot) { super(bot); - this.loadingEmoji = bot.getConfig().getLoading(); this.name = "playnext"; this.arguments = ""; this.help = "plays a single song next"; @@ -52,13 +50,13 @@ public void doCommand(CommandEvent event) { if(event.getArgs().isEmpty() && event.getMessage().getAttachments().isEmpty()) { - event.replyWarning("Please include a song title or URL!"); + event.reply(bot.getWarning(event)+"Please include a song title or URL!"); return; } String args = event.getArgs().startsWith("<") && event.getArgs().endsWith(">") ? event.getArgs().substring(1,event.getArgs().length()-1) : event.getArgs().isEmpty() ? event.getMessage().getAttachments().get(0).getUrl() : event.getArgs(); - event.reply(loadingEmoji+" Loading... `["+args+"]`", m -> bot.getPlayerManager().loadItemOrdered(event.getGuild(), args, new ResultHandler(m,event,false))); + event.reply(bot.getLoading(event)+" Loading... `["+args+"]`", m -> bot.getPlayerManager().loadItemOrdered(event.getGuild(), args, new ResultHandler(m,event,false))); } private class ResultHandler implements AudioLoadResultHandler @@ -78,13 +76,13 @@ private void loadSingle(AudioTrack track) { if(bot.getConfig().isTooLong(track)) { - m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" + m.editMessage(FormatUtil.filter(bot.getWarning(event)+" This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" +FormatUtil.formatTime(track.getDuration())+"` > `"+FormatUtil.formatTime(bot.getConfig().getMaxSeconds()*1000)+"`")).queue(); return; } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); int pos = handler.addTrackToFront(new QueuedTrack(track, event.getAuthor()))+1; - String addMsg = FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title + String addMsg = FormatUtil.filter(bot.getSuccess(event)+" Added **"+track.getInfo().title +"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0?"to begin playing":" to the queue at position "+pos)); m.editMessage(addMsg).queue(); } @@ -112,7 +110,7 @@ else if (playlist.getSelectedTrack()!=null) public void noMatches() { if(ytsearch) - m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" No results found for `"+event.getArgs()+"`.")).queue(); + m.editMessage(FormatUtil.filter(bot.getWarning(event)+" No results found for `"+event.getArgs()+"`.")).queue(); else bot.getPlayerManager().loadItemOrdered(event.getGuild(), "ytsearch:"+event.getArgs(), new ResultHandler(m,event,true)); } @@ -121,9 +119,9 @@ public void noMatches() public void loadFailed(FriendlyException throwable) { if(throwable.severity==FriendlyException.Severity.COMMON) - m.editMessage(event.getClient().getError()+" Error loading: "+throwable.getMessage()).queue(); + m.editMessage(bot.getError(event)+" Error loading: "+throwable.getMessage()).queue(); else - m.editMessage(event.getClient().getError()+" Error loading track.").queue(); + m.editMessage(bot.getError(event)+" Error loading track.").queue(); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/RepeatCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/RepeatCmd.java index e355b28a0..a21d8605f 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/RepeatCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/RepeatCmd.java @@ -65,11 +65,11 @@ else if(args.equalsIgnoreCase("one") || args.equalsIgnoreCase("single")) } else { - event.replyError("Valid options are `off`, `all` or `single` (or leave empty to toggle between `off` and `all`)"); + event.reply(bot.getError(event)+"Valid options are `off`, `all` or `single` (or leave empty to toggle between `off` and `all`)"); return; } settings.setRepeatMode(value); - event.replySuccess("Repeat mode is now `"+value.getUserFriendlyName()+"`"); + event.reply(bot.getSuccess(event)+"Repeat mode is now `"+value.getUserFriendlyName()+"`"); } @Override diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/SkiptoCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/SkiptoCmd.java index e7fffb531..fe196c4cb 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/SkiptoCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/SkiptoCmd.java @@ -46,17 +46,17 @@ public void doCommand(CommandEvent event) } catch(NumberFormatException e) { - event.reply(event.getClient().getError()+" `"+event.getArgs()+"` is not a valid integer!"); + event.reply(bot.getError(event)+" `"+event.getArgs()+"` is not a valid integer!"); return; } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); if(index<1 || index>handler.getQueue().size()) { - event.reply(event.getClient().getError()+" Position must be a valid integer between 1 and "+handler.getQueue().size()+"!"); + event.reply(bot.getError(event)+" Position must be a valid integer between 1 and "+handler.getQueue().size()+"!"); return; } handler.getQueue().skip(index-1); - event.reply(event.getClient().getSuccess()+" Skipped to **"+handler.getQueue().get(0).getTrack().getInfo().title+"**"); + event.reply(bot.getSuccess(event)+" Skipped to **"+handler.getQueue().get(0).getTrack().getInfo().title+"**"); handler.getPlayer().stopTrack(); } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/StopCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/StopCmd.java index 8caa67c8d..a8d968c27 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/StopCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/StopCmd.java @@ -41,6 +41,6 @@ public void doCommand(CommandEvent event) AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); handler.stopAndClear(); event.getGuild().getAudioManager().closeAudioConnection(); - event.reply(event.getClient().getSuccess()+" The player has stopped and the queue has been cleared."); + event.reply(bot.getSuccess(event)+" The player has stopped and the queue has been cleared."); } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/dj/VolumeCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/dj/VolumeCmd.java index 0b50c648f..5958ec347 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/dj/VolumeCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/dj/VolumeCmd.java @@ -56,7 +56,7 @@ public void doCommand(CommandEvent event) nvolume = -1; } if(nvolume<0 || nvolume>150) - event.reply(event.getClient().getError()+" Volume must be a valid integer between 0 and 150!"); + event.reply(bot.getError(event)+" Volume must be a valid integer between 0 and 150!"); else { handler.getPlayer().setVolume(nvolume); diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/LyricsCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/LyricsCmd.java index 3deec5ba3..4b7589bde 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/LyricsCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/LyricsCmd.java @@ -52,7 +52,7 @@ public void doCommand(CommandEvent event) title = sendingHandler.getPlayer().getPlayingTrack().getInfo().title; else { - event.replyError("There must be music playing to use that!"); + event.reply(bot.getError(event)+"There must be music playing to use that!"); return; } } @@ -63,7 +63,7 @@ public void doCommand(CommandEvent event) { if(lyrics == null) { - event.replyError("Lyrics for `" + title + "` could not be found!" + (event.getArgs().isEmpty() ? " Try entering the song name manually (`lyrics [song name]`)" : "")); + event.reply(bot.getError(event)+"Lyrics for `" + title + "` could not be found!" + (event.getArgs().isEmpty() ? " Try entering the song name manually (`lyrics [song name]`)" : "")); return; } @@ -73,7 +73,7 @@ public void doCommand(CommandEvent event) .setTitle(lyrics.getTitle(), lyrics.getURL()); if(lyrics.getContent().length()>15000) { - event.replyWarning("Lyrics for `" + title + "` found but likely not correct: " + lyrics.getURL()); + event.reply(bot.getWarning(event)+"Lyrics for `" + title + "` found but likely not correct: " + lyrics.getURL()); } else if(lyrics.getContent().length()>2000) { diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java index e70f4e110..1cdaffdd4 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java @@ -49,13 +49,13 @@ public class PlayCmd extends MusicCommand { private final static String LOAD = "\uD83D\uDCE5"; // 📥 private final static String CANCEL = "\uD83D\uDEAB"; // 🚫 - - private final String loadingEmoji; - + + private final Bot bot; + public PlayCmd(Bot bot) { super(bot); - this.loadingEmoji = bot.getConfig().getLoading(); + this.bot = bot; this.name = "play"; this.arguments = ""; this.help = "plays the provided song"; @@ -76,13 +76,13 @@ public void doCommand(CommandEvent event) if(DJCommand.checkDJPermission(event)) { handler.getPlayer().setPaused(false); - event.replySuccess("Resumed **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**."); + event.reply(bot.getSuccess(event)+"Resumed **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**."); } else - event.replyError("Only DJs can unpause the player!"); + event.reply(bot.getError(event)+"Only DJs can unpause the player!"); return; } - StringBuilder builder = new StringBuilder(event.getClient().getWarning()+" Play Commands:\n"); + StringBuilder builder = new StringBuilder(bot.getWarning(event)+" Play Commands:\n"); builder.append("\n`").append(event.getClient().getPrefix()).append(name).append(" ` - plays the first result from Youtube"); builder.append("\n`").append(event.getClient().getPrefix()).append(name).append(" ` - plays the provided song, playlist, or stream"); for(Command cmd: children) @@ -101,11 +101,11 @@ public void doCommand(CommandEvent event) if (spotifyUrl.type == SpotifyUrlData.Type.TRACK) { try { SpotifyTrack track = bot.getSpotifyAPI().getTrack(spotifyUrl.id); - event.reply(bot.getConfig().getLoading() +" Loading... `["+track.name+"]`", + event.reply(bot.getLoading(event) +" Loading... `["+track.name+"]`", m -> bot.getPlayerManager().loadItemOrdered(event.getGuild(), "ytsearch:"+getYoutubeQueryOfTrack(track), new SpotifyResultHandler(m, event, track))); } catch (Exception e) { LoggerFactory.getLogger("MusicBot").error("Failed to load spotify track from: " + args, e); - event.reply(event.getClient().getError()+" Failed to load spotify track... `["+spotifyUrl.id+"]`"); + event.reply(bot.getError(event)+" Failed to load spotify track... `["+spotifyUrl.id+"]`"); } } else { String noun = (spotifyUrl.type == SpotifyUrlData.Type.PLAYLIST) ? "playlist" : "album"; @@ -116,18 +116,18 @@ public void doCommand(CommandEvent event) : bot.getSpotifyAPI().getAlbum(spotifyUrl.id); if (playlist.tracks.length == 0) { - event.reply(event.getClient().getError() +" Spotify "+noun+" does not have any tracks... `["+playlist.name+"]`"); + event.reply(bot.getError(event) +" Spotify "+noun+" does not have any tracks... `["+playlist.name+"]`"); } else { - event.reply(bot.getConfig().getLoading() +" Loading... `["+String.format("%s (%d track%s)", playlist.name, playlist.tracks.length, playlist.tracks.length == 1 ? "" : "s")+"]`", + event.reply(bot.getLoading(event) +" Loading... `["+String.format("%s (%d track%s)", playlist.name, playlist.tracks.length, playlist.tracks.length == 1 ? "" : "s")+"]`", m -> bot.getPlayerManager().loadItemOrdered(event.getGuild(), "ytsearch:"+getYoutubeQueryOfTrack(playlist.tracks[0]), new SpotifyResultHandler(m, event, playlist))); } } catch (Exception e) { LoggerFactory.getLogger("MusicBot").error("Failed to load spotify "+noun+" from: " + args, e); - event.reply(event.getClient().getError()+" Failed to load spotify "+noun+"... `["+spotifyUrl.id+"]`"); + event.reply(bot.getError(event)+" Failed to load spotify "+noun+"... `["+spotifyUrl.id+"]`"); } } } else { - event.reply(loadingEmoji+" Loading... `["+args+"]`", m -> bot.getPlayerManager().loadItemOrdered(event.getGuild(), args, new ResultHandler(m,event,false))); + event.reply(bot.getLoading(event)+" Loading... `["+args+"]`", m -> bot.getPlayerManager().loadItemOrdered(event.getGuild(), args, new ResultHandler(m,event,false))); } } @@ -148,27 +148,27 @@ protected void loadSingle(AudioTrack track, AudioPlaylist playlist) { if(bot.getConfig().isTooLong(track)) { - m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" + m.editMessage(FormatUtil.filter(bot.getWarning(event)+" This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" +FormatUtil.formatTime(track.getDuration())+"` > `"+FormatUtil.formatTime(bot.getConfig().getMaxSeconds()*1000)+"`")).queue(); return; } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+1; - String addMsg = FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title + String addMsg = FormatUtil.filter(bot.getSuccess(event)+" Added **"+track.getInfo().title +"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0?"to begin playing":" to the queue at position "+pos)); if(playlist==null || !event.getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_ADD_REACTION)) m.editMessage(addMsg).queue(); else { new ButtonMenu.Builder() - .setText(addMsg+"\n"+event.getClient().getWarning()+" This track has a playlist of **"+playlist.getTracks().size()+"** tracks attached. Select "+LOAD+" to load playlist.") + .setText(addMsg+"\n"+bot.getWarning(event)+" This track has a playlist of **"+playlist.getTracks().size()+"** tracks attached. Select "+LOAD+" to load playlist.") .setChoices(LOAD, CANCEL) .setEventWaiter(bot.getWaiter()) .setTimeout(30, TimeUnit.SECONDS) .setAction(re -> { if(re.getName().equals(LOAD)) - m.editMessage(addMsg+"\n"+event.getClient().getSuccess()+" Loaded **"+loadPlaylist(playlist, track)+"** additional tracks!").queue(); + m.editMessage(addMsg+"\n"+bot.getSuccess(event)+" Loaded **"+loadPlaylist(playlist, track)+"** additional tracks!").queue(); else m.editMessage(addMsg).queue(); }).setFinalAction(m -> @@ -216,15 +216,15 @@ else if (playlist.getSelectedTrack()!=null) int count = loadPlaylist(playlist, null); if(count==0) { - m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" All entries in this playlist "+(playlist.getName()==null ? "" : "(**"+playlist.getName() + m.editMessage(FormatUtil.filter(bot.getWarning(event)+" All entries in this playlist "+(playlist.getName()==null ? "" : "(**"+playlist.getName() +"**) ")+"were longer than the allowed maximum (`"+bot.getConfig().getMaxTime()+"`)")).queue(); } else { - m.editMessage(FormatUtil.filter(event.getClient().getSuccess()+" Found " + m.editMessage(FormatUtil.filter(bot.getSuccess(event)+" Found " +(playlist.getName()==null?"a playlist":"playlist **"+playlist.getName()+"**")+" with `" + playlist.getTracks().size()+"` entries; added to the queue!" - + (count `"+FormatUtil.formatTime(bot.getConfig().getMaxSeconds()*1000)+"`")).queue(); return; } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+1; - String addMsg = FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title + String addMsg = FormatUtil.filter(bot.getSuccess(event)+" Added **"+track.getInfo().title +"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0?"to begin playing":" to the queue at position "+pos)); if(playlist.tracks.length == 1 || !event.getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_ADD_REACTION)) m.editMessage(addMsg).queue(); else { new ButtonMenu.Builder() - .setText(addMsg+"\n"+event.getClient().getWarning()+" [**"+playlist.name+"**] has **"+playlist.tracks.length+"** tracks attached. Select "+LOAD+" to add the rest to the queue.") + .setText(addMsg+"\n"+bot.getWarning(event)+" [**"+playlist.name+"**] has **"+playlist.tracks.length+"** tracks attached. Select "+LOAD+" to add the rest to the queue.") .setChoices(LOAD, CANCEL) .setEventWaiter(bot.getWaiter()) .setTimeout(30, TimeUnit.SECONDS) .setAction(re -> { if(re.getName().equals(LOAD)) { - String newMessageText = addMsg+"\n"+event.getClient().getSuccess()+" Loading **1/"+(playlist.tracks.length - 1)+"** additional tracks..."; + String newMessageText = addMsg+"\n"+bot.getSuccess(event)+" Loading **1/"+(playlist.tracks.length - 1)+"** additional tracks..."; m.editMessage(newMessageText).queue(); bot.getPlayerManager().loadItemOrdered(event.getGuild(), "ytsearch:"+getYoutubeQueryOfTrack(playlist.tracks[1]), new SpotifyResultHandler(m,event,playlist,1,newMessageText,prevErrors)); } @@ -324,13 +324,13 @@ protected void loadSingle(AudioTrack track, AudioPlaylist UNUSED) int newErrors = prevErrors; if (track == null) { - newMessageText = prevMessageText+"\n"+FormatUtil.filter(event.getClient().getError()+" Couldn't find youtube link for track " + (iTrack + 1) + " of " + playlist.tracks.length + ": "+playlist.tracks[iTrack].name); + newMessageText = prevMessageText+"\n"+FormatUtil.filter(bot.getError(event)+" Couldn't find youtube link for track " + (iTrack + 1) + " of " + playlist.tracks.length + ": "+playlist.tracks[iTrack].name); newErrors++; m.editMessage(newMessageText).queue(); } else if(bot.getConfig().isTooLong(track)) { - newMessageText = prevMessageText+"\n"+FormatUtil.filter(event.getClient().getWarning()+" This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" + newMessageText = prevMessageText+"\n"+FormatUtil.filter(bot.getWarning(event)+" This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" +FormatUtil.formatTime(track.getDuration())+"` > `"+FormatUtil.formatTime(bot.getConfig().getMaxSeconds()*1000)+"`"); newErrors++; m.editMessage(newMessageText).queue(); @@ -348,7 +348,7 @@ else if(bot.getConfig().isTooLong(track)) } if (iTrack < playlist.tracks.length - 1) { // update second line ("loading tracks...") - newMessageText = firstLine+"\n"+(event.getClient().getSuccess()+" Loading **" + (iTrack + 1) + "/"+(playlist.tracks.length - 1)+"** additional tracks...")+(remainingParts.length == 0 ? "" : "\n"+String.join("\n", remainingParts)); + newMessageText = firstLine+"\n"+(bot.getSuccess(event)+" Loading **" + (iTrack + 1) + "/"+(playlist.tracks.length - 1)+"** additional tracks...")+(remainingParts.length == 0 ? "" : "\n"+String.join("\n", remainingParts)); m.editMessage(newMessageText).queue(); bot.getPlayerManager().loadItemOrdered(event.getGuild(), "ytsearch:"+getYoutubeQueryOfTrack(playlist.tracks[iTrack + 1]), new SpotifyResultHandler(m,event,playlist,iTrack + 1,newMessageText,newErrors)); } else { @@ -356,7 +356,7 @@ else if(bot.getConfig().isTooLong(track)) // remove the second line ("loading tracks...") but keep everything else newMessageText = String.format("%s\n%s", firstLine + (remainingParts.length == 0 ? "" : "\n"+String.join("\n", remainingParts)), - event.getClient().getSuccess()+" Loaded **"+(playlist.tracks.length - newErrors - 1)+"** additional tracks!" + bot.getSuccess(event)+" Loaded **"+(playlist.tracks.length - newErrors - 1)+"** additional tracks!" ); m.editMessage(newMessageText).queue(); } @@ -421,22 +421,22 @@ public void doCommand(CommandEvent event) { if(event.getArgs().isEmpty()) { - event.reply(event.getClient().getError()+" Please include a playlist name."); + event.reply(bot.getError(event)+" Please include a playlist name."); return; } Playlist playlist = bot.getPlaylistLoader().getPlaylist(event.getArgs()); if(playlist==null) { - event.replyError("I could not find `"+event.getArgs()+".txt` in the Playlists folder."); + event.reply(bot.getError(event)+"I could not find `"+event.getArgs()+".txt` in the Playlists folder."); return; } - event.getChannel().sendMessage(loadingEmoji+" Loading playlist **"+event.getArgs()+"**... ("+playlist.getItems().size()+" items)").queue(m -> + event.getChannel().sendMessage(bot.getLoading(event)+" Loading playlist **"+event.getArgs()+"**... ("+playlist.getItems().size()+" items)").queue(m -> { AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); playlist.loadTracks(bot.getPlayerManager(), (at)->handler.addTrack(new QueuedTrack(at, event.getAuthor())), () -> { StringBuilder builder = new StringBuilder(playlist.getTracks().isEmpty() - ? event.getClient().getWarning()+" No tracks were loaded!" - : event.getClient().getSuccess()+" Loaded **"+playlist.getTracks().size()+"** tracks!"); + ? bot.getWarning(event)+" No tracks were loaded!" + : bot.getSuccess(event)+" Loaded **"+playlist.getTracks().size()+"** tracks!"); if(!playlist.getErrors().isEmpty()) builder.append("\nThe following tracks failed to load:"); playlist.getErrors().forEach(err -> builder.append("\n`[").append(err.getIndex()+1).append("]` **").append(err.getItem()).append("**: ").append(err.getReason())); diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/PlaylistsCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/PlaylistsCmd.java index 858a7641a..a72780ccd 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/PlaylistsCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/PlaylistsCmd.java @@ -44,17 +44,17 @@ public void doCommand(CommandEvent event) bot.getPlaylistLoader().createFolder(); if(!bot.getPlaylistLoader().folderExists()) { - event.reply(event.getClient().getWarning()+" Playlists folder does not exist and could not be created!"); + event.reply(bot.getWarning(event)+" Playlists folder does not exist and could not be created!"); return; } List list = bot.getPlaylistLoader().getPlaylistNames(); if(list==null) - event.reply(event.getClient().getError()+" Failed to load available playlists!"); + event.reply(bot.getError(event)+" Failed to load available playlists!"); else if(list.isEmpty()) - event.reply(event.getClient().getWarning()+" There are no playlists in the Playlists folder!"); + event.reply(bot.getWarning(event)+" There are no playlists in the Playlists folder!"); else { - StringBuilder builder = new StringBuilder(event.getClient().getSuccess()+" Available playlists:\n"); + StringBuilder builder = new StringBuilder(bot.getSuccess(event)+" Available playlists:\n"); list.forEach(str -> builder.append("`").append(str).append("` ")); builder.append("\nType `").append(event.getClient().getTextualPrefix()).append("play playlist ` to play a playlist"); event.reply(builder.toString()); diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/QueueCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/QueueCmd.java index 51139729f..137d62900 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/QueueCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/QueueCmd.java @@ -77,7 +77,7 @@ public void doCommand(CommandEvent event) Message nowp = ah.getNowPlaying(event.getJDA()); Message nonowp = ah.getNoMusicPlaying(event.getJDA()); Message built = new MessageBuilder() - .setContent(event.getClient().getWarning() + " There is no music in the queue!") + .setContent(bot.getWarning(event) + " There is no music in the queue!") .setEmbed((nowp==null ? nonowp : nowp).getEmbeds().get(0)).build(); event.reply(built, m -> { @@ -95,7 +95,7 @@ public void doCommand(CommandEvent event) } Settings settings = event.getClient().getSettingsFor(event.getGuild()); long fintotal = total; - builder.setText((i1,i2) -> getQueueTitle(ah, event.getClient().getSuccess(), songs.length, fintotal, settings.getRepeatMode())) + builder.setText((i1,i2) -> getQueueTitle(ah, bot.getSuccess(event), songs.length, fintotal, settings.getRepeatMode())) .setItems(songs) .setUsers(event.getAuthor()) .setColor(event.getSelfMember().getColor()) diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/RemoveCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/RemoveCmd.java index 37382e293..a5f96a931 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/RemoveCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/RemoveCmd.java @@ -47,16 +47,16 @@ public void doCommand(CommandEvent event) AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); if(handler.getQueue().isEmpty()) { - event.replyError("There is nothing in the queue!"); + event.reply(bot.getError(event)+"There is nothing in the queue!"); return; } if(event.getArgs().equalsIgnoreCase("all")) { int count = handler.getQueue().removeAll(event.getAuthor().getIdLong()); if(count==0) - event.replyWarning("You don't have any songs in the queue!"); + event.reply(bot.getWarning(event)+"You don't have any songs in the queue!"); else - event.replySuccess("Successfully removed your "+count+" entries."); + event.reply(bot.getSuccess(event)+"Successfully removed your "+count+" entries."); return; } int pos; @@ -67,7 +67,7 @@ public void doCommand(CommandEvent event) } if(pos<1 || pos>handler.getQueue().size()) { - event.replyError("Position must be a valid integer between 1 and "+handler.getQueue().size()+"!"); + event.reply(bot.getError(event)+"Position must be a valid integer between 1 and "+handler.getQueue().size()+"!"); return; } Settings settings = event.getClient().getSettingsFor(event.getGuild()); @@ -78,7 +78,7 @@ public void doCommand(CommandEvent event) if(qt.getIdentifier()==event.getAuthor().getIdLong()) { handler.getQueue().remove(pos-1); - event.replySuccess("Removed **"+qt.getTrack().getInfo().title+"** from the queue"); + event.reply(bot.getSuccess(event)+"Removed **"+qt.getTrack().getInfo().title+"** from the queue"); } else if(isDJ) { @@ -89,12 +89,12 @@ else if(isDJ) } catch(Exception e) { u = null; } - event.replySuccess("Removed **"+qt.getTrack().getInfo().title + event.reply(bot.getSuccess(event)+"Removed **"+qt.getTrack().getInfo().title +"** from the queue (requested by "+(u==null ? "someone" : "**"+u.getName()+"**")+")"); } else { - event.replyError("You cannot remove **"+qt.getTrack().getInfo().title+"** because you didn't add it!"); + event.reply(bot.getError(event)+"You cannot remove **"+qt.getTrack().getInfo().title+"** because you didn't add it!"); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/SearchCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/SearchCmd.java index 9358698aa..d6fe0b328 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/SearchCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/SearchCmd.java @@ -39,12 +39,10 @@ public class SearchCmd extends MusicCommand { protected String searchPrefix = "ytsearch:"; private final OrderedMenu.Builder builder; - private final String searchingEmoji; public SearchCmd(Bot bot) { super(bot); - this.searchingEmoji = bot.getConfig().getSearching(); this.name = "search"; this.aliases = bot.getConfig().getAliases(this.name); this.arguments = ""; @@ -64,10 +62,10 @@ public void doCommand(CommandEvent event) { if(event.getArgs().isEmpty()) { - event.replyError("Please include a query."); + event.reply(bot.getError(event)+"Please include a query."); return; } - event.reply(searchingEmoji+" Searching... `["+event.getArgs()+"]`", + event.reply(bot.getSearching(event)+" Searching... `["+event.getArgs()+"]`", m -> bot.getPlayerManager().loadItemOrdered(event.getGuild(), searchPrefix + event.getArgs(), new ResultHandler(m,event))); } @@ -87,13 +85,13 @@ public void trackLoaded(AudioTrack track) { if(bot.getConfig().isTooLong(track)) { - m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" + m.editMessage(FormatUtil.filter(bot.getWarning(event)+" This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" +FormatUtil.formatTime(track.getDuration())+"` > `"+bot.getConfig().getMaxTime()+"`")).queue(); return; } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+1; - m.editMessage(FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title + m.editMessage(FormatUtil.filter(bot.getSuccess(event)+" Added **"+track.getInfo().title +"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0 ? "to begin playing" : " to the queue at position "+pos))).queue(); } @@ -102,20 +100,20 @@ public void trackLoaded(AudioTrack track) public void playlistLoaded(AudioPlaylist playlist) { builder.setColor(event.getSelfMember().getColor()) - .setText(FormatUtil.filter(event.getClient().getSuccess()+" Search results for `"+event.getArgs()+"`:")) + .setText(FormatUtil.filter(bot.getSuccess(event)+" Search results for `"+event.getArgs()+"`:")) .setChoices(new String[0]) .setSelection((msg,i) -> { AudioTrack track = playlist.getTracks().get(i-1); if(bot.getConfig().isTooLong(track)) { - event.replyWarning("This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" + event.reply(bot.getWarning(event)+"This track (**"+track.getInfo().title+"**) is longer than the allowed maximum: `" +FormatUtil.formatTime(track.getDuration())+"` > `"+bot.getConfig().getMaxTime()+"`"); return; } AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler(); int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+1; - event.replySuccess("Added **" + FormatUtil.filter(track.getInfo().title) + event.reply(bot.getSuccess(event)+"Added **" + FormatUtil.filter(track.getInfo().title) + "** (`" + FormatUtil.formatTime(track.getDuration()) + "`) " + (pos==0 ? "to begin playing" : " to the queue at position "+pos)); }) @@ -133,16 +131,16 @@ public void playlistLoaded(AudioPlaylist playlist) @Override public void noMatches() { - m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" No results found for `"+event.getArgs()+"`.")).queue(); + m.editMessage(FormatUtil.filter(bot.getWarning(event)+" No results found for `"+event.getArgs()+"`.")).queue(); } @Override public void loadFailed(FriendlyException throwable) { if(throwable.severity==Severity.COMMON) - m.editMessage(event.getClient().getError()+" Error loading: "+throwable.getMessage()).queue(); + m.editMessage(bot.getError(event)+" Error loading: "+throwable.getMessage()).queue(); else - m.editMessage(event.getClient().getError()+" Error loading track.").queue(); + m.editMessage(bot.getError(event)+" Error loading track.").queue(); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/ShuffleCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/ShuffleCmd.java index c151f4d83..3c2dc8c42 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/ShuffleCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/ShuffleCmd.java @@ -44,13 +44,13 @@ public void doCommand(CommandEvent event) switch (s) { case 0: - event.replyError("You don't have any music in the queue to shuffle!"); + event.reply(bot.getError(event)+"You don't have any music in the queue to shuffle!"); break; case 1: - event.replyWarning("You only have one song in the queue!"); + event.reply(bot.getWarning(event)+"You only have one song in the queue!"); break; default: - event.replySuccess("You successfully shuffled your "+s+" entries."); + event.reply(bot.getSuccess(event)+"You successfully shuffled your "+s+" entries."); break; } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/music/SkipCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/music/SkipCmd.java index da4dcb336..2eea44e87 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/music/SkipCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/music/SkipCmd.java @@ -20,7 +20,6 @@ import com.jagrosh.jmusicbot.audio.AudioHandler; import com.jagrosh.jmusicbot.audio.RequestMetadata; import com.jagrosh.jmusicbot.commands.MusicCommand; -import net.dv8tion.jda.api.entities.User; /** * @@ -45,7 +44,7 @@ public void doCommand(CommandEvent event) RequestMetadata rm = handler.getRequestMetadata(); if(event.getAuthor().getIdLong() == rm.getOwner()) { - event.reply(event.getClient().getSuccess()+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**"); + event.reply(bot.getSuccess(event)+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**"); handler.getPlayer().stopTrack(); } else @@ -54,10 +53,10 @@ public void doCommand(CommandEvent event) .filter(m -> !m.getUser().isBot() && !m.getVoiceState().isDeafened()).count(); String msg; if(handler.getVotes().contains(event.getAuthor().getId())) - msg = event.getClient().getWarning()+" You already voted to skip this song `["; + msg = bot.getWarning(event)+" You already voted to skip this song `["; else { - msg = event.getClient().getSuccess()+" You voted to skip the song `["; + msg = bot.getSuccess(event)+" You voted to skip the song `["; handler.getVotes().add(event.getAuthor().getId()); } int skippers = (int)event.getSelfMember().getVoiceState().getChannel().getMembers().stream() @@ -66,7 +65,7 @@ public void doCommand(CommandEvent event) msg += skippers + " votes, " + required + "/" + listeners + " needed]`"; if(skippers>=required) { - msg += "\n" + event.getClient().getSuccess() + " Skipped **" + handler.getPlayer().getPlayingTrack().getInfo().title + msg += "\n" + bot.getSuccess(event) + " Skipped **" + handler.getPlayer().getPlayingTrack().getInfo().title + "** " + (rm.getOwner() == 0L ? "(autoplay)" : "(requested by **" + rm.user.username + "**)"); handler.getPlayer().stopTrack(); } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/owner/AutoplaylistCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/owner/AutoplaylistCmd.java index 107340de7..580a1cc21 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/owner/AutoplaylistCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/owner/AutoplaylistCmd.java @@ -43,26 +43,26 @@ public void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { - event.reply(event.getClient().getError()+" Please include a playlist name or NONE"); + event.reply(bot.getError(event)+" Please include a playlist name or NONE"); return; } if(event.getArgs().equalsIgnoreCase("none")) { Settings settings = event.getClient().getSettingsFor(event.getGuild()); settings.setDefaultPlaylist(null); - event.reply(event.getClient().getSuccess()+" Cleared the default playlist for **"+event.getGuild().getName()+"**"); + event.reply(bot.getSuccess(event)+" Cleared the default playlist for **"+event.getGuild().getName()+"**"); return; } String pname = event.getArgs().replaceAll("\\s+", "_"); if(bot.getPlaylistLoader().getPlaylist(pname)==null) { - event.reply(event.getClient().getError()+" Could not find `"+pname+".txt`!"); + event.reply(bot.getError(event)+" Could not find `"+pname+".txt`!"); } else { Settings settings = event.getClient().getSettingsFor(event.getGuild()); settings.setDefaultPlaylist(pname); - event.reply(event.getClient().getSuccess()+" The default playlist for **"+event.getGuild().getName()+"** is now `"+pname+"`"); + event.reply(bot.getSuccess(event)+" The default playlist for **"+event.getGuild().getName()+"** is now `"+pname+"`"); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/owner/EvalCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/owner/EvalCmd.java index 4c50d7d34..5f19554be 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/owner/EvalCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/owner/EvalCmd.java @@ -49,11 +49,11 @@ protected void execute(CommandEvent event) se.put("channel", event.getChannel()); try { - event.reply(event.getClient().getSuccess()+" Evaluated Successfully:\n```\n"+se.eval(event.getArgs())+" ```"); + event.reply(bot.getSuccess(event)+" Evaluated Successfully:\n```\n"+se.eval(event.getArgs())+" ```"); } catch(Exception e) { - event.reply(event.getClient().getError()+" An exception was thrown:\n```\n"+e+" ```"); + event.reply(bot.getError(event)+" An exception was thrown:\n```\n"+e+" ```"); } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/owner/PlaylistCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/owner/PlaylistCmd.java index 0caf39756..4ac948d1a 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/owner/PlaylistCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/owner/PlaylistCmd.java @@ -50,7 +50,7 @@ public PlaylistCmd(Bot bot) @Override public void execute(CommandEvent event) { - StringBuilder builder = new StringBuilder(event.getClient().getWarning()+" Playlist Management Commands:\n"); + StringBuilder builder = new StringBuilder(bot.getWarning(event)+" Playlist Management Commands:\n"); for(Command cmd: this.children) builder.append("\n`").append(event.getClient().getPrefix()).append(name).append(" ").append(cmd.getName()) .append(" ").append(cmd.getArguments()==null ? "" : cmd.getArguments()).append("` - ").append(cmd.getHelp()); @@ -77,15 +77,15 @@ protected void execute(CommandEvent event) try { bot.getPlaylistLoader().createPlaylist(pname); - event.reply(event.getClient().getSuccess()+" Successfully created playlist `"+pname+"`!"); + event.reply(bot.getSuccess(event)+" Successfully created playlist `"+pname+"`!"); } catch(IOException e) { - event.reply(event.getClient().getError()+" I was unable to create the playlist: "+e.getLocalizedMessage()); + event.reply(bot.getError(event)+" I was unable to create the playlist: "+e.getLocalizedMessage()); } } else - event.reply(event.getClient().getError()+" Playlist `"+pname+"` already exists!"); + event.reply(bot.getError(event)+" Playlist `"+pname+"` already exists!"); } } @@ -105,17 +105,17 @@ protected void execute(CommandEvent event) { String pname = event.getArgs().replaceAll("\\s+", "_"); if(bot.getPlaylistLoader().getPlaylist(pname)==null) - event.reply(event.getClient().getError()+" Playlist `"+pname+"` doesn't exist!"); + event.reply(bot.getError(event)+" Playlist `"+pname+"` doesn't exist!"); else { try { bot.getPlaylistLoader().deletePlaylist(pname); - event.reply(event.getClient().getSuccess()+" Successfully deleted playlist `"+pname+"`!"); + event.reply(bot.getSuccess(event)+" Successfully deleted playlist `"+pname+"`!"); } catch(IOException e) { - event.reply(event.getClient().getError()+" I was unable to delete the playlist: "+e.getLocalizedMessage()); + event.reply(bot.getError(event)+" I was unable to delete the playlist: "+e.getLocalizedMessage()); } } } @@ -138,13 +138,13 @@ protected void execute(CommandEvent event) String[] parts = event.getArgs().split("\\s+", 2); if(parts.length<2) { - event.reply(event.getClient().getError()+" Please include a playlist name and URLs to add!"); + event.reply(bot.getError(event)+" Please include a playlist name and URLs to add!"); return; } String pname = parts[0]; Playlist playlist = bot.getPlaylistLoader().getPlaylist(pname); if(playlist==null) - event.reply(event.getClient().getError()+" Playlist `"+pname+"` doesn't exist!"); + event.reply(bot.getError(event)+" Playlist `"+pname+"` doesn't exist!"); else { StringBuilder builder = new StringBuilder(); @@ -160,11 +160,11 @@ protected void execute(CommandEvent event) try { bot.getPlaylistLoader().writePlaylist(pname, builder.toString()); - event.reply(event.getClient().getSuccess()+" Successfully added "+urls.length+" items to playlist `"+pname+"`!"); + event.reply(bot.getSuccess(event)+" Successfully added "+urls.length+" items to playlist `"+pname+"`!"); } catch(IOException e) { - event.reply(event.getClient().getError()+" I was unable to append to the playlist: "+e.getLocalizedMessage()); + event.reply(bot.getError(event)+" I was unable to append to the playlist: "+e.getLocalizedMessage()); } } } @@ -199,17 +199,17 @@ protected void execute(CommandEvent event) bot.getPlaylistLoader().createFolder(); if(!bot.getPlaylistLoader().folderExists()) { - event.reply(event.getClient().getWarning()+" Playlists folder does not exist and could not be created!"); + event.reply(bot.getWarning(event)+" Playlists folder does not exist and could not be created!"); return; } List list = bot.getPlaylistLoader().getPlaylistNames(); if(list==null) - event.reply(event.getClient().getError()+" Failed to load available playlists!"); + event.reply(bot.getError(event)+" Failed to load available playlists!"); else if(list.isEmpty()) - event.reply(event.getClient().getWarning()+" There are no playlists in the Playlists folder!"); + event.reply(bot.getWarning(event)+" There are no playlists in the Playlists folder!"); else { - StringBuilder builder = new StringBuilder(event.getClient().getSuccess()+" Available playlists:\n"); + StringBuilder builder = new StringBuilder(bot.getSuccess(event)+" Available playlists:\n"); list.forEach(str -> builder.append("`").append(str).append("` ")); event.reply(builder.toString()); } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetavatarCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetavatarCmd.java index a5b2fffec..fd07fe918 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetavatarCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetavatarCmd.java @@ -29,8 +29,11 @@ */ public class SetavatarCmd extends OwnerCommand { + private final Bot bot; + public SetavatarCmd(Bot bot) { + this.bot = bot; this.name = "setavatar"; this.help = "sets the avatar of the bot"; this.arguments = ""; @@ -52,16 +55,16 @@ protected void execute(CommandEvent event) InputStream s = OtherUtil.imageFromUrl(url); if(s==null) { - event.reply(event.getClient().getError()+" Invalid or missing URL"); + event.reply(bot.getError(event)+" Invalid or missing URL"); } else { try { event.getSelfUser().getManager().setAvatar(Icon.from(s)).queue( - v -> event.reply(event.getClient().getSuccess()+" Successfully changed avatar."), - t -> event.reply(event.getClient().getError()+" Failed to set avatar.")); + v -> event.reply(bot.getSuccess(event)+" Successfully changed avatar."), + t -> event.reply(bot.getError(event)+" Failed to set avatar.")); } catch(IOException e) { - event.reply(event.getClient().getError()+" Could not load from provided URL."); + event.reply(bot.getError(event)+" Could not load from provided URL."); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetemojiCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetemojiCmd.java new file mode 100644 index 000000000..07add11ee --- /dev/null +++ b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetemojiCmd.java @@ -0,0 +1,171 @@ +package com.jagrosh.jmusicbot.commands.owner; + +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; + +import com.jagrosh.jdautilities.command.CommandEvent; +import com.jagrosh.jdautilities.menu.OrderedMenu; +import com.jagrosh.jmusicbot.Bot; +import com.jagrosh.jmusicbot.commands.OwnerCommand; +import com.jagrosh.jmusicbot.settings.Settings; + +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; +import net.dv8tion.jda.api.exceptions.PermissionException; + +public class SetemojiCmd extends OwnerCommand +{ + + private final Bot bot; + + public SetemojiCmd(Bot bot) + { + this.bot = bot; + this.name = "setemoji"; + this.help = "sets an emoji that the bot uses"; + this.arguments = "[guild: ||all] [emojitype: success|warning|error|loading|searching]"; + this.aliases = bot.getConfig().getAliases(this.name); + this.guildOnly = true; + + messageTypeSetters = new ArrayList>(); + messageTypeSetters.add((set, val) -> set.setSuccess(val)); + messageTypeSetters.add((set, val) -> set.setWarning(val)); + messageTypeSetters.add((set, val) -> set.setError(val)); + messageTypeSetters.add((set, val) -> set.setLoading(val)); + messageTypeSetters.add((set, val) -> set.setSearching(val)); + } + + private final static String[] messageTypes = new String[] { "success", "warning", "error", "loading", "searching" }; + private final ArrayList> messageTypeSetters; + + @Override + protected void execute(CommandEvent event) + { + String guildName = null; + int iMessageType = -1; + String args = event.getArgs().trim().toLowerCase(); + if(!args.isEmpty()) { + for (int i = 0; i < messageTypes.length; i++) { + if (args.toLowerCase().endsWith(messageTypes[i])) { + iMessageType = i; + args = args.substring(0, args.length() - messageTypes[i].length()).trim(); + break; + } + } + if (!args.isEmpty()) { + guildName = args; + } + } + + boolean allGuilds = false; + ArrayList guildOptions = new ArrayList(); + if (guildName != null) { + if (guildName.equals("all")) { + allGuilds = true; + } else { + for (Guild g : bot.getJDA().getGuilds()) { + if (g.getName().toLowerCase().contains(guildName.toLowerCase()) || g.getId().toLowerCase().equals(guildName.toLowerCase())) { + guildOptions.add(g); + } + } + } + } + final boolean fAllGuilds = allGuilds; + final int fIMessageType = iMessageType; + final String fGuildName = guildName; + + if (fAllGuilds) { + continueWithGuildSelection(event, null, fIMessageType); + } else { + String message = null; + if (fGuildName != null && guildOptions.size() == 0) { + message = bot.getWarning(event)+" Couldn't find any guilds matching \""+fGuildName+"\"."; + } else if (guildOptions.size() > 1) { + message = bot.getWarning(event)+" Multiple guilds match \""+fGuildName+"\"."; + } + + if (guildOptions.size() == 1) { + continueWithGuildSelection(event, guildOptions.get(0), fIMessageType); + } else { + if (guildOptions.size() == 0) { + for (Guild g : bot.getJDA().getGuilds()) guildOptions.add(g); + } + + String[] guildNameChoices = new String[guildOptions.size() + 1]; + int i = 0; + for (Guild g : guildOptions) guildNameChoices[i++] = g.getName(); + guildNameChoices[guildNameChoices.length - 1] = "all guilds"; + + if (message == null) message = ""; + else message += "\n"; + message += bot.getLoading(event)+" Select the target guild of this change:"; + + new OrderedMenu.Builder() + .setText(message) + .setChoices(guildNameChoices) + .setEventWaiter(bot.getWaiter()) + .setTimeout(30, TimeUnit.SECONDS) + .setSelection((m2, iGuild) -> { + Guild g; + if (iGuild == guildNameChoices.length) g = null; + else g = guildOptions.get(iGuild - 1); + continueWithGuildSelection(event, g, fIMessageType); + }) + .useCancelButton(true) + .build().display(event.getChannel()); + } + } + } + + private void continueWithGuildSelection(CommandEvent event, Guild guild, int iMessageType) { + if (iMessageType != -1) { + continueWithAllSelections(event, guild, iMessageType); + } else { + new OrderedMenu.Builder() + .setText(bot.getLoading(event)+" Select the emoji type to change on " + (guild == null ? "all guilds" : guild.getName()) + ":") + .setChoices(messageTypes) + .setEventWaiter(bot.getWaiter()) + .setTimeout(30, TimeUnit.SECONDS) + .setSelection((m2, selectedIMessageType) -> { + try { m2.clearReactions().queue(); } catch (PermissionException ignore) {} + continueWithAllSelections(event, guild, selectedIMessageType - 1); + }) + .useCancelButton(true) + .build().display(event.getChannel()); + } + } + + private void continueWithAllSelections(CommandEvent event, Guild guild, int iMessageType) + { + event.reply(bot.getLoading(event)+" React to this message with the \""+messageTypes[iMessageType]+"\" emoji you wish to use in "+(guild == null ? "all guilds" : guild.getName())+"...", m -> { + bot.getWaiter().waitForEvent(MessageReactionAddEvent.class, + reactEvent -> reactEvent.getMessageId().equals(m.getId()) && reactEvent.getUserId().equals(event.getAuthor().getId()), + reactEvent -> { + // What happens next is after a valid event + // is fired and processed above. + + String re; + if (reactEvent.getReaction().getReactionEmote().isEmoji()) { + re = reactEvent.getReaction().getReactionEmote().getEmoji(); + } else { + re = "<:"+reactEvent.getReaction().getReactionEmote().getAsReactionCode()+">"; + } + + // Preform the specified action with the ReactionEmote + if (guild == null) { + for (Guild g : bot.getJDA().getGuilds()) { + messageTypeSetters.get(iMessageType).accept(bot.getSettingsManager().getSettings(g), re); + } + } else { + messageTypeSetters.get(iMessageType).accept(bot.getSettingsManager().getSettings(guild), re); + } + + m.editMessage(bot.getSuccess(event)+" Set the \""+messageTypes[iMessageType]+"\" emoji in "+(guild == null ? "all guilds" : guild.getName())+" to: "+re).queue(); + }, + 30, TimeUnit.SECONDS, () -> { + m.delete().queue(); + }); + }); + } +} diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetgameCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetgameCmd.java index 7950d5429..285c42119 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetgameCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetgameCmd.java @@ -26,8 +26,11 @@ */ public class SetgameCmd extends OwnerCommand { + private final Bot bot; + public SetgameCmd(Bot bot) { + this.bot = bot; this.name = "setgame"; this.help = "sets the game the bot is playing"; this.arguments = "[action] [game]"; @@ -47,12 +50,12 @@ protected void execute(CommandEvent event) try { event.getJDA().getPresence().setActivity(title.isEmpty() ? null : Activity.playing(title)); - event.reply(event.getClient().getSuccess()+" **"+event.getSelfUser().getName() + event.reply(bot.getSuccess(event)+" **"+event.getSelfUser().getName() +"** is "+(title.isEmpty() ? "no longer playing anything." : "now playing `"+title+"`")); } catch(Exception e) { - event.reply(event.getClient().getError()+" The game could not be set!"); + event.reply(bot.getError(event)+" The game could not be set!"); } } @@ -73,18 +76,18 @@ protected void execute(CommandEvent event) String[] parts = event.getArgs().split("\\s+", 2); if(parts.length<2) { - event.replyError("Please include a twitch username and the name of the game to 'stream'"); + event.reply(bot.getError(event)+"Please include a twitch username and the name of the game to 'stream'"); return; } try { event.getJDA().getPresence().setActivity(Activity.streaming(parts[1], "https://twitch.tv/"+parts[0])); - event.replySuccess("**"+event.getSelfUser().getName() + event.reply(bot.getSuccess(event)+"**"+event.getSelfUser().getName() +"** is now streaming `"+parts[1]+"`"); } catch(Exception e) { - event.reply(event.getClient().getError()+" The game could not be set!"); + event.reply(bot.getError(event)+" The game could not be set!"); } } } @@ -105,16 +108,16 @@ protected void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { - event.replyError("Please include a title to listen to!"); + event.reply(bot.getError(event)+"Please include a title to listen to!"); return; } String title = event.getArgs().toLowerCase().startsWith("to") ? event.getArgs().substring(2).trim() : event.getArgs(); try { event.getJDA().getPresence().setActivity(Activity.listening(title)); - event.replySuccess("**"+event.getSelfUser().getName()+"** is now listening to `"+title+"`"); + event.reply(bot.getSuccess(event)+"**"+event.getSelfUser().getName()+"** is now listening to `"+title+"`"); } catch(Exception e) { - event.reply(event.getClient().getError()+" The game could not be set!"); + event.reply(bot.getError(event)+" The game could not be set!"); } } } @@ -135,16 +138,16 @@ protected void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { - event.replyError("Please include a title to watch!"); + event.reply(bot.getError(event)+"Please include a title to watch!"); return; } String title = event.getArgs(); try { event.getJDA().getPresence().setActivity(Activity.watching(title)); - event.replySuccess("**"+event.getSelfUser().getName()+"** is now watching `"+title+"`"); + event.reply(bot.getSuccess(event)+"**"+event.getSelfUser().getName()+"** is now watching `"+title+"`"); } catch(Exception e) { - event.reply(event.getClient().getError()+" The game could not be set!"); + event.reply(bot.getError(event)+" The game could not be set!"); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetnameCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetnameCmd.java index 94844d471..8721a7871 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetnameCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetnameCmd.java @@ -26,8 +26,11 @@ */ public class SetnameCmd extends OwnerCommand { + private final Bot bot; + public SetnameCmd(Bot bot) { + this.bot = bot; this.name = "setname"; this.help = "sets the name of the bot"; this.arguments = ""; @@ -42,15 +45,15 @@ protected void execute(CommandEvent event) { String oldname = event.getSelfUser().getName(); event.getSelfUser().getManager().setName(event.getArgs()).complete(false); - event.reply(event.getClient().getSuccess()+" Name changed from `"+oldname+"` to `"+event.getArgs()+"`"); + event.reply(bot.getSuccess(event)+" Name changed from `"+oldname+"` to `"+event.getArgs()+"`"); } catch(RateLimitedException e) { - event.reply(event.getClient().getError()+" Name can only be changed twice per hour!"); + event.reply(bot.getError(event)+" Name can only be changed twice per hour!"); } catch(Exception e) { - event.reply(event.getClient().getError()+" That name is not valid!"); + event.reply(bot.getError(event)+" That name is not valid!"); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetstatusCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetstatusCmd.java index 06b769832..8dcb60ff9 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetstatusCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/owner/SetstatusCmd.java @@ -26,8 +26,11 @@ */ public class SetstatusCmd extends OwnerCommand { + private final Bot bot; + public SetstatusCmd(Bot bot) { + this.bot = bot; this.name = "setstatus"; this.help = "sets the status the bot displays"; this.arguments = ""; @@ -42,15 +45,15 @@ protected void execute(CommandEvent event) OnlineStatus status = OnlineStatus.fromKey(event.getArgs()); if(status==OnlineStatus.UNKNOWN) { - event.replyError("Please include one of the following statuses: `ONLINE`, `IDLE`, `DND`, `INVISIBLE`"); + event.reply(bot.getError(event)+"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()+"`"); + event.reply(bot.getSuccess(event)+"Set the status to `"+status.getKey().toUpperCase()+"`"); } } catch(Exception e) { - event.reply(event.getClient().getError()+" The status could not be set!"); + event.reply(bot.getError(event)+" The status could not be set!"); } } } diff --git a/src/main/java/com/jagrosh/jmusicbot/commands/owner/ShutdownCmd.java b/src/main/java/com/jagrosh/jmusicbot/commands/owner/ShutdownCmd.java index 2a59cecf8..6b3731532 100644 --- a/src/main/java/com/jagrosh/jmusicbot/commands/owner/ShutdownCmd.java +++ b/src/main/java/com/jagrosh/jmusicbot/commands/owner/ShutdownCmd.java @@ -39,7 +39,7 @@ public ShutdownCmd(Bot bot) @Override protected void execute(CommandEvent event) { - event.replyWarning("Shutting down..."); + event.reply(bot.getWarning(event)+"Shutting down..."); bot.shutdown(); } } diff --git a/src/main/java/com/jagrosh/jmusicbot/playlist/SpotifyAPI.java b/src/main/java/com/jagrosh/jmusicbot/playlist/SpotifyAPI.java index a90c64539..5f36e7837 100644 --- a/src/main/java/com/jagrosh/jmusicbot/playlist/SpotifyAPI.java +++ b/src/main/java/com/jagrosh/jmusicbot/playlist/SpotifyAPI.java @@ -5,24 +5,17 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.URL; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; -import java.util.Dictionary; import java.util.HashMap; import java.util.Map; -import java.util.Optional; -import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor; import com.jagrosh.jmusicbot.BotConfig; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; -import org.slf4j.LoggerFactory; public class SpotifyAPI { private final BotConfig config; @@ -163,7 +156,6 @@ public SpotifyUrlData tryParseUrl(String maybeSpotifyUrl) { .orElseGet(null); } catch (Exception e) { - LoggerFactory.getLogger("MusicBot").error("Errored parsing spotify url: " + maybeSpotifyUrl, e); return null; } } diff --git a/src/main/java/com/jagrosh/jmusicbot/settings/Settings.java b/src/main/java/com/jagrosh/jmusicbot/settings/Settings.java index 37062e39f..36066fee7 100644 --- a/src/main/java/com/jagrosh/jmusicbot/settings/Settings.java +++ b/src/main/java/com/jagrosh/jmusicbot/settings/Settings.java @@ -38,8 +38,9 @@ public class Settings implements GuildSettingsProvider private RepeatMode repeatMode; private String prefix; private double skipRatio; + private String successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji; - public Settings(SettingsManager manager, String textId, String voiceId, String roleId, int volume, String defaultPlaylist, RepeatMode repeatMode, String prefix, double skipRatio) + public Settings(SettingsManager manager, String textId, String voiceId, String roleId, int volume, String defaultPlaylist, RepeatMode repeatMode, String prefix, double skipRatio, String successEmoji, String warningEmoji, String errorEmoji, String loadingEmoji, String searchingEmoji) { this.manager = manager; try @@ -71,9 +72,14 @@ public Settings(SettingsManager manager, String textId, String voiceId, String r this.repeatMode = repeatMode; this.prefix = prefix; this.skipRatio = skipRatio; + this.successEmoji = successEmoji; + this.warningEmoji = warningEmoji; + this.errorEmoji = errorEmoji; + this.loadingEmoji = loadingEmoji; + this.searchingEmoji = searchingEmoji; } - public Settings(SettingsManager manager, long textId, long voiceId, long roleId, int volume, String defaultPlaylist, RepeatMode repeatMode, String prefix, double skipRatio) + public Settings(SettingsManager manager, long textId, long voiceId, long roleId, int volume, String defaultPlaylist, RepeatMode repeatMode, String prefix, double skipRatio, String successEmoji, String warningEmoji, String errorEmoji, String loadingEmoji, String searchingEmoji) { this.manager = manager; this.textId = textId; @@ -84,6 +90,11 @@ public Settings(SettingsManager manager, long textId, long voiceId, long roleId, this.repeatMode = repeatMode; this.prefix = prefix; this.skipRatio = skipRatio; + this.successEmoji = successEmoji; + this.warningEmoji = warningEmoji; + this.errorEmoji = errorEmoji; + this.loadingEmoji = loadingEmoji; + this.searchingEmoji = searchingEmoji; } // Getters @@ -127,6 +138,31 @@ public double getSkipRatio() return skipRatio; } + public String getSuccess() + { + return successEmoji; + } + + public String getWarning() + { + return warningEmoji; + } + + public String getError() + { + return errorEmoji; + } + + public String getLoading() + { + return loadingEmoji; + } + + public String getSearching() + { + return searchingEmoji; + } + @Override public Collection getPrefixes() { @@ -181,4 +217,34 @@ public void setSkipRatio(double skipRatio) this.skipRatio = skipRatio; this.manager.writeSettings(); } + + public void setSuccess(String success) + { + this.successEmoji = success; + this.manager.writeSettings(); + } + + public void setWarning(String warning) + { + this.warningEmoji = warning; + this.manager.writeSettings(); + } + + public void setError(String error) + { + this.errorEmoji = error; + this.manager.writeSettings(); + } + + public void setLoading(String loading) + { + this.loadingEmoji = loading; + this.manager.writeSettings(); + } + + public void setSearching(String searching) + { + this.searchingEmoji = searching; + this.manager.writeSettings(); + } } diff --git a/src/main/java/com/jagrosh/jmusicbot/settings/SettingsManager.java b/src/main/java/com/jagrosh/jmusicbot/settings/SettingsManager.java index 72b081e69..d11ac811a 100644 --- a/src/main/java/com/jagrosh/jmusicbot/settings/SettingsManager.java +++ b/src/main/java/com/jagrosh/jmusicbot/settings/SettingsManager.java @@ -29,7 +29,7 @@ * * @author John Grosh (john.a.grosh@gmail.com) */ -public class SettingsManager implements GuildSettingsManager +public class SettingsManager implements GuildSettingsManager { private final static double SKIP_RATIO = .55; private final HashMap settings; @@ -38,7 +38,7 @@ public SettingsManager() { this.settings = new HashMap<>(); try { - JSONObject loadedSettings = new JSONObject(new String(Files.readAllBytes(OtherUtil.getPath("serversettings.json")))); + JSONObject loadedSettings = new JSONObject(new String(Files.readAllBytes(OtherUtil.getPath("serversettings.json")), "utf-16")); loadedSettings.keySet().forEach((id) -> { JSONObject o = loadedSettings.getJSONObject(id); @@ -55,7 +55,12 @@ public SettingsManager() o.has("default_playlist")? o.getString("default_playlist") : null, o.has("repeat_mode") ? o.getEnum(RepeatMode.class, "repeat_mode"): RepeatMode.OFF, o.has("prefix") ? o.getString("prefix") : null, - o.has("skip_ratio") ? o.getDouble("skip_ratio") : SKIP_RATIO)); + o.has("skip_ratio") ? o.getDouble("skip_ratio") : SKIP_RATIO, + o.has("success") ? o.getString("success") : null, + o.has("warning") ? o.getString("warning") : null, + o.has("error") ? o.getString("error") : null, + o.has("loading") ? o.getString("loading") : null, + o.has("searching") ? o.getString("searching") : null)); }); } catch(IOException | JSONException e) { LoggerFactory.getLogger("Settings").warn("Failed to load server settings (this is normal if no settings have been set yet): "+e); @@ -71,6 +76,7 @@ public SettingsManager() @Override public Settings getSettings(Guild guild) { + if (guild == null) return createDefaultSettings(); return getSettings(guild.getIdLong()); } @@ -81,7 +87,7 @@ public Settings getSettings(long guildId) private Settings createDefaultSettings() { - return new Settings(this, 0, 0, 0, 100, null, RepeatMode.OFF, null, SKIP_RATIO); + return new Settings(this, 0, 0, 0, 100, null, RepeatMode.OFF, null, SKIP_RATIO, null, null, null, null, null); } protected void writeSettings() @@ -106,10 +112,20 @@ protected void writeSettings() o.put("prefix", s.getPrefix()); if(s.getSkipRatio() != SKIP_RATIO) o.put("skip_ratio", s.getSkipRatio()); + if (s.getSuccess() != null) + o.put("success", s.getSuccess()); + if (s.getWarning() != null) + o.put("warning", s.getWarning()); + if (s.getError() != null) + o.put("error", s.getError()); + if (s.getLoading() != null) + o.put("loading", s.getLoading()); + if (s.getSearching() != null) + o.put("searching", s.getSearching()); obj.put(Long.toString(key), o); }); try { - Files.write(OtherUtil.getPath("serversettings.json"), obj.toString(4).getBytes()); + Files.write(OtherUtil.getPath("serversettings.json"), obj.toString(4).getBytes("utf-16")); } catch(IOException ex){ LoggerFactory.getLogger("Settings").warn("Failed to write to file: "+ex); }