diff --git a/Dockerfile b/Dockerfile index a443484..bad7422 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,2 @@ -FROM debian:latest +FROM debian:buster WORKDIR /home/Hadder diff --git a/pom.xml b/pom.xml index 712e13f..6926c73 100644 --- a/pom.xml +++ b/pom.xml @@ -19,18 +19,18 @@ net.dv8tion JDA - 4.1.0_93 + 4.1.0_95 org.json json 20190722 - - com.rethinkdb - rethinkdb-driver - 2.3.3 - + + com.rethinkdb + rethinkdb-driver + 2.3.3 + org.slf4j slf4j-simple @@ -39,7 +39,7 @@ club.minnced discord-webhooks - 0.1.8 + 0.2.0 org.kohsuke @@ -49,7 +49,7 @@ com.sedmelluq lavaplayer - 1.3.32 + 1.3.33 diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index f257042..b4a6cbb 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -102,7 +102,8 @@ public class Hadder { new VolumeCommand(), new StopCommand(), new BlacklistCommand(), - new PauseCommand()), config, helpCommand); + new PauseCommand(), + new LoopCommand()), config, helpCommand); builder.addEventListeners( new MentionListener(rethink), diff --git a/src/main/java/com/bbn/hadder/Rethink.java b/src/main/java/com/bbn/hadder/Rethink.java index 6ef9d10..5ff7c94 100644 --- a/src/main/java/com/bbn/hadder/Rethink.java +++ b/src/main/java/com/bbn/hadder/Rethink.java @@ -70,6 +70,22 @@ public class Rethink { } } + public void update(String table, String value, String what, int whatvalue) { + try { + r.table(table).get(value).update(r.hashMap(what, whatvalue)).run(conn); + } catch (ClassCastException e) { + e.printStackTrace(); + } + } + + public void update(String table, String value, String what, boolean whatvalue) { + try { + r.table(table).get(value).update(r.hashMap(what, whatvalue)).run(conn); + } catch (ClassCastException e) { + e.printStackTrace(); + } + } + public void insert(String table, Object object) { try { r.table(table).insert(object).run(conn); @@ -122,7 +138,8 @@ public class Rethink { } public void insertGuild(String id) { - this.insert("server", r.hashMap("id", id) + this.insert("server", r + .hashMap("id", id) .with("prefix", "h.") .with("message_id", "") .with("role_id", "") @@ -133,7 +150,11 @@ public class Rethink { } public void insertUser(String id) { - this.insert("user", r.hashMap("id", id).with("prefix", "h.").with("language", "en").with("blacklisted", "none")); + this.insert("user", r + .hashMap("id", id) + .with("prefix", "h.") + .with("language", "en") + .with("blacklisted", "none")); } public void setBlackListed(String id, String commands) { @@ -204,11 +225,7 @@ public class Rethink { } public void setInviteDetection(String guild_id, boolean b) { - try { - r.table("server").get(guild_id).update(r.hashMap("invite_detect", b)).run(conn); - } catch (ClassCastException e) { - e.printStackTrace(); - } + this.update("server", guild_id, "invite_detect", b); } public Boolean getInviteDetection(String guild_id) { diff --git a/src/main/java/com/bbn/hadder/audio/TrackManager.java b/src/main/java/com/bbn/hadder/audio/TrackManager.java index b4c1e9a..489c12f 100644 --- a/src/main/java/com/bbn/hadder/audio/TrackManager.java +++ b/src/main/java/com/bbn/hadder/audio/TrackManager.java @@ -19,6 +19,7 @@ public class TrackManager extends AudioEventAdapter { private final AudioPlayer player; private final Queue queue; + private boolean loop = false; public TrackManager(AudioPlayer player) { this.player = player; @@ -47,8 +48,10 @@ public class TrackManager extends AudioEventAdapter { @Override public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { - Guild g = queue.poll().getAuthor().getGuild(); - if (queue.isEmpty()) { + Guild g = queue.element().getAuthor().getGuild(); + if (loop) { + player.playTrack(track.makeClone()); + } else if (queue.isEmpty()) { g.getAudioManager().closeAudioConnection(); } else { player.playTrack(queue.element().getTrack()); @@ -67,6 +70,16 @@ public class TrackManager extends AudioEventAdapter { queue.remove(entry); } + public boolean isLoop() + { + return loop; + } + + public void setLoop(boolean repeating) + { + this.loop = repeating; + } + public AudioInfo getTrackInfo(AudioTrack track) { return queue.stream().filter(audioInfo -> audioInfo.getTrack().equals(track)).findFirst().orElse(null); } diff --git a/src/main/java/com/bbn/hadder/commands/music/LoopCommand.java b/src/main/java/com/bbn/hadder/commands/music/LoopCommand.java new file mode 100644 index 0000000..5003134 --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/music/LoopCommand.java @@ -0,0 +1,56 @@ +package com.bbn.hadder.commands.music; + +import com.bbn.hadder.commands.Command; +import com.bbn.hadder.commands.CommandEvent; +import com.bbn.hadder.utils.MessageEditor; + +/** + * @author Skidder / GregTCLTK + */ + +public class LoopCommand implements Command { + + @Override + public void executed(String[] args, CommandEvent event) { + if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) { + if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) { + if (event.getAudioManager().getTrackManager(event.getGuild()).isLoop()) { + event.getAudioManager().getTrackManager(event.getGuild()).setLoop(false); + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, "commands.music.loop.success.unloop.title", "commands.music.loop.success.unloop.description").build()).queue(); + } else { + event.getAudioManager().getTrackManager(event.getGuild()).setLoop(true); + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, "commands.music.loop.success.loop.title", "commands.music.loop.success.loop.description").build()).queue(); + } + } else { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, + "commands.music.loop.error.connected.title", + "commands.music.loop.error.connected.description") + .build()).queue(); + } + } else { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, + "commands.music.info.error.title", + "commands.music.info.error.description").build()).queue(); + } + } + + @Override + public String[] labels() { + return new String[]{"loop", "repeat"}; + } + + @Override + public String description() { + return "commands.music.loop.help.description"; + } + + @Override + public String usage() { + return null; + } + + @Override + public String example() { + return null; + } +} diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index f5dd88b..a3a2891 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -237,6 +237,13 @@ commands.music.pause.error.paused.description = The song is already paused. commands.music.pause.error.connected.title = No channel commands.music.pause.error.connected.description = You have to be in the same voice channel as the bot to pause the song. commands.music.pause.help.description = Pause the playing song. +commands.music.loop.success.loop.title = Successfully activated +commands.music.loop.success.loop.description = I will now repeat the currently played song. +commands.music.loop.success.unloop.title = Successfully deactivated +commands.music.loop.success.unloop.description = I will no longer repeat the currently played song. +commands.music.loop.error.connected.title = No channel +commands.music.loop.error.connected.description = You have to be in the same voice channel as the bot to set the repeat status. +commands.music.loop.help.description = Repeats a song/queue. commands.nsfw.gif.error.title = GIF not showing? Click here commands.nsfw.img.error.title = Image not showing? Click here