From 7a09a2b1bc43d1b79a2fd080d1a9a29b36bfa751 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 4 Jan 2020 14:39:02 +0100 Subject: [PATCH] More error messages --- .../hadder/commands/music/LeaveCommand.java | 23 ++++++++---- .../hadder/commands/music/SkipCommand.java | 14 +++++-- .../hadder/commands/music/StopCommand.java | 21 +++++++---- .../hadder/commands/music/VolumeCommand.java | 37 +++++++++++-------- .../Translations/Translations_en.properties | 12 +++++- 5 files changed, 71 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/bbn/hadder/commands/music/LeaveCommand.java b/src/main/java/com/bbn/hadder/commands/music/LeaveCommand.java index ec9043c..8636984 100644 --- a/src/main/java/com/bbn/hadder/commands/music/LeaveCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/LeaveCommand.java @@ -13,17 +13,24 @@ public class LeaveCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { if (event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) { - event.getGuild().getAudioManager().closeAudioConnection(); - event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( - MessageEditor.MessageType.INFO, - "commands.music.leave.success.title", - "commands.music.leave.success.description") - .build()).queue(); + if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) { + event.getGuild().getAudioManager().closeAudioConnection(); + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( + MessageEditor.MessageType.INFO, + "commands.music.leave.success.title", + "commands.music.leave.success.description") + .build()).queue(); + } else { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, + "commands.music.leave.error.channel.title", + "commands.music.leave.error.channel.description") + .build()).queue(); + } } else { event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( MessageEditor.MessageType.ERROR, - "commands.music.leave.error.tile", - "commands.music.leave.error.description") + "commands.music.leave.error.connected.tile", + "commands.music.leave.error.connected.description") .build()).queue(); } } diff --git a/src/main/java/com/bbn/hadder/commands/music/SkipCommand.java b/src/main/java/com/bbn/hadder/commands/music/SkipCommand.java index c2265bd..40f366f 100644 --- a/src/main/java/com/bbn/hadder/commands/music/SkipCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/SkipCommand.java @@ -13,10 +13,16 @@ public class SkipCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { if (event.getAudioManager().hasPlayer(event.getGuild()) && !event.getAudioManager().getTrackManager(event.getGuild()).getQueuedTracks().isEmpty()) { - event.getAudioManager().forceSkipTrack(event); - event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, - "commands.music.skip.success.title", - "commands.music.skip.success.description").build()).queue(); + if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) { + event.getAudioManager().forceSkipTrack(event); + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.skip.success.title", + "commands.music.skip.success.description").build()).queue(); + } else { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, + "commands.music.skip.error.connected.title", + "commands.music.skip.error.connected.description ").build()).queue(); + } } else { event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, "commands.music.info.error.title", diff --git a/src/main/java/com/bbn/hadder/commands/music/StopCommand.java b/src/main/java/com/bbn/hadder/commands/music/StopCommand.java index b9336bc..56cd891 100644 --- a/src/main/java/com/bbn/hadder/commands/music/StopCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/StopCommand.java @@ -13,13 +13,20 @@ public class StopCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) { - event.getAudioManager().players.remove(event.getGuild().getId()); - event.getAudioManager().getPlayer(event.getGuild()).destroy(); - event.getAudioManager().getTrackManager(event.getGuild()).purgeQueue(); - event.getGuild().getAudioManager().closeAudioConnection(); - event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, - "commands.music.stop.success.title", - "commands.music.stop.success.description").build()).queue(); + if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) { + event.getAudioManager().players.remove(event.getGuild().getId()); + event.getAudioManager().getPlayer(event.getGuild()).destroy(); + event.getAudioManager().getTrackManager(event.getGuild()).purgeQueue(); + event.getGuild().getAudioManager().closeAudioConnection(); + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.stop.success.title", + "commands.music.stop.success.description").build()).queue(); + } else { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, + "commands.music.stop.error.connected.title", + "commands.music.stop.error.connected.description") + .build()).queue(); + } } else { event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, "commands.music.info.error.title", diff --git a/src/main/java/com/bbn/hadder/commands/music/VolumeCommand.java b/src/main/java/com/bbn/hadder/commands/music/VolumeCommand.java index d0d058b..a7d3546 100644 --- a/src/main/java/com/bbn/hadder/commands/music/VolumeCommand.java +++ b/src/main/java/com/bbn/hadder/commands/music/VolumeCommand.java @@ -14,22 +14,29 @@ public class VolumeCommand implements Command { public void executed(String[] args, CommandEvent event) { if (args.length > 0) { if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) { - try { - int volume = Integer.parseInt(args[0]); - if (volume < 201 && volume > 0 || event.getConfig().getOwners().contains(event.getAuthor().getIdLong())) { - event.getAudioManager().getPlayer(event.getGuild()).setVolume(volume); - event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, - "commands.music.volume.success.title", "", - "commands.music.volume.success.description", String.valueOf(volume)).build()).queue(); - } else { - event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, - "commands.music.volume.error.int.title", - "commands.music.volume.error.int.description").build()).queue(); + if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) { + try { + int volume = Integer.parseInt(args[0]); + if (volume < 201 && volume > 0 || event.getConfig().getOwners().contains(event.getAuthor().getIdLong())) { + event.getAudioManager().getPlayer(event.getGuild()).setVolume(volume); + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.music.volume.success.title", "", + "commands.music.volume.success.description", String.valueOf(volume)).build()).queue(); + } else { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, + "commands.music.volume.error.int.title", + "commands.music.volume.error.int.description").build()).queue(); + } + } catch (NumberFormatException e) { + event.getHelpCommand().sendHelp(this, event); + } catch (Exception e) { + e.printStackTrace(); } - } catch (NumberFormatException e) { - event.getHelpCommand().sendHelp(this, event); - } catch (Exception e) { - e.printStackTrace(); + } else { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, + "commands.music.volume.error.connected.title", + "commands.volume.stop.error.connected.description") + .build()).queue(); } } else { event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index c054233..50da52a 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -183,8 +183,10 @@ commands.music.join.error.permission.description = I am not allowed to join your commands.music.join.help.description = Joins your voice channel. commands.music.leave.success.title = Successfully disconnected commands.music.leave.success.description = I successfully disconnected from the Voice Channel -commands.music.leave.error.tile = Not connected -commands.music.leave.error.description = I'm currently in no Voice Channel on this Guild +commands.music.leave.error.channel.title = No channel +commands.music.leave.error.channel.description = You have to be in the same voice channel as the bot. +commands.music.leave.error.connected.tile = Not connected +commands.music.leave.error.connected.description = I'm currently in no Voice Channel on this Guild commands.music.leave.help.description = Leaves your voice channel. commands.music.play.load.title = %extra% Now loading %extra% commands.music.play.load.description = Trying to load the song... @@ -200,6 +202,8 @@ commands.music.play.error.match.description = I can not find a song named this o commands.music.play.help.description = Plays the specified song. commands.music.stop.success.title = Successfully stopped commands.music.stop.success.description = I successfully stopped the song. +commands.music.stop.error.connected.title = No channel +commands.music.stop.error.connected.description = You have to be in the same voice channel as the bot to stop the song. commands.music.stop.help.description = Stops the song. commands.music.info.success.title = Track info commands.music.info.error.title = No playing track @@ -212,11 +216,15 @@ commands.music.queue.success.description = This is the queue\: \n %extra% commands.music.queue.help.description = Shows the music queue. commands.music.skip.success.title = Successfully skipped commands.music.skip.success.description = I successfully skipped to the next song +commands.music.skip.error.connected.title = No channel +commands.music.skip.error.connected.description = You have to be in the same voice channel as the bot to skip the song. commands.music.skip.help.description = Skips the currently playing song. commands.music.volume.success.title = Successfully set commands.music.volume.success.description = I successfully set the new volume to %extra% commands.music.volume.error.int.title = Invalid number commands.music.volume.error.int.description = The volume have to be between 1 and 200 +commands.music.volume.error.connected.title = No channel +commands.music.volume.error.connected.description = You have to be in the same voice channel as the bot to change the volume. commands.music.volume.help.description = Change the volume of the music. commands.nsfw.gif.error.title = GIF not showing? Click here