diff --git a/pom.xml b/pom.xml
index 24b1adf..c4f89c0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,7 @@
net.dv8tion
JDA
- 4.1.0_86
+ 4.1.0_87
org.json
diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java
index 173d6f2..4169459 100644
--- a/src/main/java/com/bbn/hadder/Hadder.java
+++ b/src/main/java/com/bbn/hadder/Hadder.java
@@ -1,5 +1,6 @@
package com.bbn.hadder;
+import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.general.*;
import com.bbn.hadder.commands.misc.*;
import com.bbn.hadder.commands.moderation.*;
@@ -41,6 +42,7 @@ public class Hadder {
builder.setToken(config.getBotToken());
HelpCommand helpCommand = new HelpCommand();
+ AudioManager audioManager = new AudioManager();
CommandHandler commandHandler = new CommandHandler(
List.of(
@@ -100,12 +102,13 @@ public class Hadder {
builder.addEventListeners(
new MentionListener(rethink),
new PrivateMessageListener(rethink),
- new CommandListener(rethink, commandHandler),
+ new CommandListener(rethink, commandHandler, audioManager),
new GuildListener(rethink, config),
new ReadyListener(rethink, config),
new InviteLinkListener(rethink),
new RulesListener(rethink),
- new StarboardListener(rethink));
+ new StarboardListener(rethink),
+ new VoiceLeaveListener(audioManager));
try {
shardManager = builder.build();
diff --git a/src/main/java/com/bbn/hadder/audio/AudioManager.java b/src/main/java/com/bbn/hadder/audio/AudioManager.java
index 7c0d6dd..07b4f1d 100644
--- a/src/main/java/com/bbn/hadder/audio/AudioManager.java
+++ b/src/main/java/com/bbn/hadder/audio/AudioManager.java
@@ -10,7 +10,9 @@ import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
+import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import net.dv8tion.jda.api.entities.Guild;
+import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import java.util.AbstractMap;
@@ -28,11 +30,47 @@ public class AudioManager {
AudioSourceManagers.registerRemoteSources(myManager);
}
- public final Map> players = new HashMap<>();
- public final AudioPlayerManager myManager = new DefaultAudioPlayerManager();
+ public Map> players = new HashMap<>();
+ private final AudioPlayerManager myManager = new DefaultAudioPlayerManager();
+
+ public boolean hasPlayer(Guild guild) {
+ return players.containsKey(guild.getId());
+ }
+
+ public void removePlayer(Guild g) {
+ System.out.println(players.toString());
+ players.remove(g.getId());
+ System.out.println(players.toString());
+ }
+
+ public Map> getPlayers () {
+ return players;
+ }
+
+ public AudioPlayer getPlayer(Guild guild) {
+ AudioPlayer p;
+ if (hasPlayer(guild)) {
+ p = players.get(guild.getId()).getKey();
+ } else {
+ p = createPlayer(guild);
+ }
+ return p;
+ }
+
+ public TrackManager getTrackManager(Guild guild) {
+ return players.get(guild.getId()).getValue();
+ }
+
+ public AudioPlayer createPlayer(Guild guild) {
+ AudioPlayer nPlayer = myManager.createPlayer();
+ TrackManager manager = new TrackManager(nPlayer);
+ nPlayer.addListener(manager);
+ guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(nPlayer));
+ players.put(guild.getId(), new AbstractMap.SimpleEntry<>(nPlayer, manager));
+ return nPlayer;
+ }
public void loadTrack(String identifier, CommandEvent event, Message msg) {
-
Guild guild = event.getGuild();
getPlayer(guild);
@@ -60,9 +98,15 @@ public class AudioManager {
} else if (playlist.isSearchResult()) {
trackLoaded(playlist.getTracks().get(0));
} else {
- for (int i = 0; i < Math.min(playlist.getTracks().size(), 200); i++) {
+ for (int i = 0; i < Math.min(playlist.getTracks().size(), 69); i++) {
getTrackManager(guild).queue(playlist.getTracks().get(i), event.getMember());
}
+ msg.editMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
+ "commands.music.play.success.loading.title", "⏯",
+ "", "")
+ .addField(event.getMessageEditor().getTerm("commands.music.play.success.title"), playlist.getName(), true)
+ .addField(event.getMessageEditor().getTerm("commands.music.play.success.tracks"), String.valueOf(playlist.getTracks().size()), true)
+ .build()).queue();
}
}
@@ -84,31 +128,25 @@ public class AudioManager {
});
}
- public boolean hasPlayer(Guild guild) {
- return players.containsKey(guild.getId());
+ public boolean isDj(Member member) {
+ return member.getRoles().stream().anyMatch(r -> r.getName().equals("DJ"));
}
- public AudioPlayer getPlayer(Guild guild) {
- AudioPlayer p;
- if (hasPlayer(guild)) {
- p = players.get(guild.getId()).getKey();
- } else {
- p = createPlayer(guild);
- }
- return p;
+ public boolean isCurrentDj(Member member) {
+ return getTrackManager(member.getGuild()).getTrackInfo(getPlayer(member.getGuild()).getPlayingTrack()).getAuthor().equals(member);
}
- public TrackManager getTrackManager(Guild guild) {
- return players.get(guild.getId()).getValue();
+ public void forceSkipTrack(CommandEvent event) {
+ getPlayer(event.getGuild()).stopTrack();
}
- public AudioPlayer createPlayer(Guild guild) {
- AudioPlayer nPlayer = myManager.createPlayer();
- TrackManager manager = new TrackManager(nPlayer);
- nPlayer.addListener(manager);
- guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(nPlayer));
- players.put(guild.getId(), new AbstractMap.SimpleEntry<>(nPlayer, manager));
- return nPlayer;
+ public String getTimestamp(long milis) {
+ long seconds = milis / 1000;
+ long hours = Math.floorDiv(seconds, 3600);
+ seconds = seconds - (hours * 3600);
+ long mins = Math.floorDiv(seconds, 60);
+ seconds = seconds - (mins * 60);
+ return (hours == 0 ? "" : hours + ":") + String.format("%02d", mins) + ":" + String.format("%02d", seconds);
}
public String getOrNull(String s) {
diff --git a/src/main/java/com/bbn/hadder/commands/CommandEvent.java b/src/main/java/com/bbn/hadder/commands/CommandEvent.java
index fb9d643..6e75d45 100644
--- a/src/main/java/com/bbn/hadder/commands/CommandEvent.java
+++ b/src/main/java/com/bbn/hadder/commands/CommandEvent.java
@@ -1,6 +1,7 @@
package com.bbn.hadder.commands;
import com.bbn.hadder.Rethink;
+import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.general.HelpCommand;
import com.bbn.hadder.core.CommandHandler;
import com.bbn.hadder.core.Config;
@@ -8,6 +9,7 @@ import com.bbn.hadder.utils.EventWaiter;
import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Message;
+import net.dv8tion.jda.api.events.Event;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import javax.annotation.Nonnull;
@@ -20,8 +22,9 @@ public class CommandEvent extends MessageReceivedEvent {
private HelpCommand helpCommand;
private MessageEditor messageEditor;
private EventWaiter eventWaiter;
+ private AudioManager audioManager;
- public CommandEvent(@Nonnull JDA api, long responseNumber, @Nonnull Message message, Rethink rethink, Config config, CommandHandler commandHandler, HelpCommand helpCommand, MessageEditor messageEditor, EventWaiter eventWaiter) {
+ public CommandEvent(@Nonnull JDA api, long responseNumber, @Nonnull Message message, Rethink rethink, Config config, CommandHandler commandHandler, HelpCommand helpCommand, MessageEditor messageEditor, EventWaiter eventWaiter, AudioManager audioManager) {
super(api, responseNumber, message);
this.rethink = rethink;
this.config = config;
@@ -29,6 +32,18 @@ public class CommandEvent extends MessageReceivedEvent {
this.helpCommand = helpCommand;
this.messageEditor = messageEditor;
this.eventWaiter = eventWaiter;
+ this.audioManager = audioManager;
+ }
+
+ public CommandEvent(MessageReceivedEvent event, Rethink rethink, Config config, CommandHandler commandHandler, HelpCommand helpCommand, MessageEditor messageEditor, EventWaiter eventWaiter, AudioManager audioManager) {
+ super(event.getJDA(), event.getResponseNumber(), event.getMessage());
+ this.rethink = rethink;
+ this.config = config;
+ this.commandHandler = commandHandler;
+ this.helpCommand = helpCommand;
+ this.messageEditor = messageEditor;
+ this.eventWaiter = eventWaiter;
+ this.audioManager = audioManager;
}
public Rethink getRethink() {
@@ -54,4 +69,8 @@ public class CommandEvent extends MessageReceivedEvent {
public EventWaiter getEventWaiter() {
return eventWaiter;
}
+
+ public AudioManager getAudioManager() {
+ return audioManager;
+ }
}
diff --git a/src/main/java/com/bbn/hadder/commands/moderation/BanCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/BanCommand.java
index 406d699..de948d9 100644
--- a/src/main/java/com/bbn/hadder/commands/moderation/BanCommand.java
+++ b/src/main/java/com/bbn/hadder/commands/moderation/BanCommand.java
@@ -26,7 +26,7 @@ public class BanCommand implements Command {
event.getMessageEditor().getMessage(
MessageEditor.MessageType.INFO,
"commands.moderation.ban.success.title",
- "✅",
+ "",
"commands.moderation.ban.success.description",
victim.getUser().getName() + ".").build()).queue();
} else {
@@ -74,7 +74,7 @@ public class BanCommand implements Command {
}
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.moderation.ban.success.title",
- "✅",
+ "",
"commands.moderation.ban.massban.success.description",
String.valueOf(event.getMessage().getMentionedMembers().size())).build()).queue();
}
diff --git a/src/main/java/com/bbn/hadder/commands/music/InfoCommand.java b/src/main/java/com/bbn/hadder/commands/music/InfoCommand.java
index 3baeb46..cf83fc7 100644
--- a/src/main/java/com/bbn/hadder/commands/music/InfoCommand.java
+++ b/src/main/java/com/bbn/hadder/commands/music/InfoCommand.java
@@ -1,8 +1,8 @@
package com.bbn.hadder.commands.music;
-import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
+import com.bbn.hadder.utils.MessageEditor;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
/**
@@ -11,46 +11,31 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
public class InfoCommand implements Command {
- private static final String CD = "\uD83D\uDCBF";
- private static final String MIC = "\uD83C\uDFA4";
- private static final String QUEUE_DESCRIPTION = "%s **|>** %s\n%s\n%s %s\n%s";
-
@Override
public void executed(String[] args, CommandEvent event) {
- if (new AudioManager().hasPlayer(event.getGuild())) {
- event.getTextChannel().sendMessage("Ja Player is auch wieder da");
- }
- if (new AudioManager().getPlayer(event.getGuild()).getPlayingTrack() == null) {
- event.getTextChannel().sendMessage("Joo playing track net anwesend^^").queue();
- }
- if (!new AudioManager().hasPlayer(event.getGuild()) || new AudioManager().getPlayer(event.getGuild()).getPlayingTrack() == null) {
- event.getTextChannel().sendMessage("Shut up eyyyy du kek").queue();
+ if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) {
+ AudioTrack track = event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack();
+ event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
+ "commands.music.info.success.title", "")
+ .setAuthor(track.getInfo().author)
+ .addField("Title", track.getInfo().title, true)
+ .addField("Progress", "`[ " + event.getAudioManager().getTimestamp(track.getPosition()) + " / " + event.getAudioManager().getTimestamp(track.getInfo().length) + " ]`", false)
+ .build()).queue();
} else {
- AudioTrack track = new AudioManager().getPlayer(event.getGuild()).getPlayingTrack();
- event.getTextChannel().sendMessage("Track Info" + String.format(QUEUE_DESCRIPTION, CD, new AudioManager().getOrNull(track.getInfo().title),
- "\n\u23F1 **|>** `[ " + getTimestamp(track.getPosition()) + " / " + getTimestamp(track.getInfo().length) + " ]`",
- "\n" + MIC, new AudioManager().getOrNull(track.getInfo().author),
- "\n\uD83C\uDFA7 **|>** " + "")).queue();
+ event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
+ "commands.music.info.error.title",
+ "commands.music.info.error.description").build()).queue();
}
}
- private String getTimestamp(long milis) {
- long seconds = milis / 1000;
- long hours = Math.floorDiv(seconds, 3600);
- seconds = seconds - (hours * 3600);
- long mins = Math.floorDiv(seconds, 60);
- seconds = seconds - (mins * 60);
- return (hours == 0 ? "" : hours + ":") + String.format("%02d", mins) + ":" + String.format("%02d", seconds);
- }
-
@Override
public String[] labels() {
- return new String[]{"info"};
+ return new String[]{"info", "songinfo"};
}
@Override
public String description() {
- return "Shows information about the playing song";
+ return "commands.music.info.help.description";
}
@Override
diff --git a/src/main/java/com/bbn/hadder/commands/music/JoinCommand.java b/src/main/java/com/bbn/hadder/commands/music/JoinCommand.java
index 3992f90..d9ab13d 100644
--- a/src/main/java/com/bbn/hadder/commands/music/JoinCommand.java
+++ b/src/main/java/com/bbn/hadder/commands/music/JoinCommand.java
@@ -33,32 +33,30 @@ public class JoinCommand implements Command {
} else {
event.getTextChannel().sendMessage(
event.getMessageEditor().getMessage(
- MessageEditor.MessageType.WARNING,
- "commands.music.join.error.connecting.already.title",
+ MessageEditor.MessageType.WARNING,
+ "commands.music.join.error.connecting.already.title",
"commands.music.join.error.connecting.already.description")
.build()).queue();
}
} else {
event.getGuild().getAudioManager().openAudioConnection(vc);
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
- MessageEditor.MessageType.INFO,
- "commands.music.join.success.title",
- "",
- "commands.music.join.success.description",
- vc.getName())
+ MessageEditor.MessageType.INFO,
+ "commands.music.join.success.title", "",
+ "commands.music.join.success.description", vc.getName())
.build()).queue();
}
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
- MessageEditor.MessageType.WARNING,
- "commands.music.join.error.connecting.trying.title",
+ MessageEditor.MessageType.WARNING,
+ "commands.music.join.error.connecting.trying.title",
"commands.music.join.error.connecting.trying.description")
.build()).queue();
}
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
- MessageEditor.MessageType.WARNING,
- "commands.music.join.error.channel.title",
+ MessageEditor.MessageType.WARNING,
+ "commands.music.join.error.channel.title",
"commands.music.join.error.channel.description")
.build()).queue();
}
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 eb860db..c2a0398 100644
--- a/src/main/java/com/bbn/hadder/commands/music/LeaveCommand.java
+++ b/src/main/java/com/bbn/hadder/commands/music/LeaveCommand.java
@@ -15,14 +15,14 @@ public class LeaveCommand implements Command {
if (event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
event.getGuild().getAudioManager().closeAudioConnection();
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
- MessageEditor.MessageType.INFO,
- "commands.music.leave.success.title",
+ MessageEditor.MessageType.INFO,
+ "commands.music.leave.success.title",
"commands.music.leave.success.description")
.build()).queue();
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
- MessageEditor.MessageType.WARNING,
- "commands.music.leave.error.tile",
+ MessageEditor.MessageType.WARNING,
+ "commands.music.leave.error.tile",
"commands.music.leave.error.description")
.build()).queue();
}
@@ -30,7 +30,7 @@ public class LeaveCommand implements Command {
@Override
public String[] labels() {
- return new String[]{"leave"};
+ return new String[]{"leave", "quit"};
}
@Override
diff --git a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java
index ddb5c92..c0d4cf5 100644
--- a/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java
+++ b/src/main/java/com/bbn/hadder/commands/music/PlayCommand.java
@@ -1,6 +1,5 @@
package com.bbn.hadder.commands.music;
-import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor;
@@ -24,12 +23,12 @@ public class PlayCommand implements Command {
Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.play.load.title", "⭕",
"commands.music.play.load.description", "").build()).complete();
- new AudioManager().loadTrack(input, event, msg);
+ event.getAudioManager().loadTrack(input, event, msg);
} catch (Exception ignore) {
Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.play.load.title", "⭕",
"commands.music.play.load.description", "").build()).complete();
- new AudioManager().loadTrack("ytsearch: " + input, event, msg);
+ event.getAudioManager().loadTrack("ytsearch: " + input, event, msg);
}
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
diff --git a/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java b/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java
index d2178f9..60747f4 100644
--- a/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java
+++ b/src/main/java/com/bbn/hadder/commands/music/QueueCommand.java
@@ -1,11 +1,9 @@
package com.bbn.hadder.commands.music;
import com.bbn.hadder.audio.AudioInfo;
-import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor;
-import net.dv8tion.jda.api.EmbedBuilder;
import java.util.Set;
@@ -17,21 +15,20 @@ public class QueueCommand implements Command {
@Override
public void executed(String[] args, CommandEvent event) {
- if (!new AudioManager().hasPlayer(event.getGuild()) || new AudioManager().getTrackManager(event.getGuild()).getQueuedTracks().isEmpty()) {
+ if (!event.getAudioManager().hasPlayer(event.getGuild()) || event.getAudioManager().getTrackManager(event.getGuild()).getQueuedTracks().isEmpty()) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.WARNING,
"commands.music.queue.error.title",
"commands.music.queue.error.description"
).build()).queue();
} else {
- Set queue = new AudioManager().getTrackManager(event.getGuild()).getQueuedTracks();
- EmbedBuilder b = event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
- "commands.music.queue.success.title",
- "commands.music.queue.success.description")
- .addField("Queued songs", String.valueOf(queue.size()), true);
+ Set queue = event.getAudioManager().getTrackManager(event.getGuild()).getQueuedTracks();
+ StringBuilder builder = new StringBuilder();
for (AudioInfo g : queue) {
- b.addField(g.getTrack().getInfo().author, g.getTrack().getInfo().title, true);
+ builder.append("**").append(g.getTrack().getInfo().author).append("**: `").append(g.getTrack().getInfo().title).append("` \n");
}
- event.getTextChannel().sendMessage(b.build()).queue();
+ event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
+ "commands.music.queue.success.title", "",
+ "commands.music.queue.success.description", builder.toString()).build()).queue();
}
}
@@ -42,7 +39,7 @@ public class QueueCommand implements Command {
@Override
public String description() {
- return "Shows the music queue.";
+ return "commands.music.queue.help.description";
}
@Override
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 ea36991..c0b94c3 100644
--- a/src/main/java/com/bbn/hadder/commands/music/SkipCommand.java
+++ b/src/main/java/com/bbn/hadder/commands/music/SkipCommand.java
@@ -1,9 +1,8 @@
package com.bbn.hadder.commands.music;
-import com.bbn.hadder.audio.AudioInfo;
-import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
+import com.bbn.hadder.utils.MessageEditor;
/**
* @author Skidder / GregTCLTK
@@ -13,7 +12,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();
+ } else {
+ event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
+ "commands.music.info.error.title",
+ "commands.music.info.error.description").build()).queue();
+ }
}
@Override
@@ -23,7 +31,7 @@ public class SkipCommand implements Command {
@Override
public String description() {
- return "Skips the song";
+ return "commands.music.skip.help.description";
}
@Override
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 ab03799..84bc911 100644
--- a/src/main/java/com/bbn/hadder/commands/music/StopCommand.java
+++ b/src/main/java/com/bbn/hadder/commands/music/StopCommand.java
@@ -1,6 +1,5 @@
package com.bbn.hadder.commands.music;
-import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor;
@@ -13,13 +12,19 @@ public class StopCommand implements Command {
@Override
public void executed(String[] args, CommandEvent event) {
- new AudioManager().players.remove(event.getGuild().getId());
- new AudioManager().getPlayer(event.getGuild()).destroy();
- new AudioManager().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.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();
+ } else {
+ event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
+ "commands.music.info.error.title",
+ "commands.music.info.error.description").build()).queue();
+ }
}
@Override
diff --git a/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java b/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java
index ca5fac2..b05c5f1 100644
--- a/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java
+++ b/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java
@@ -5,6 +5,7 @@ package com.bbn.hadder.commands.owner;
*/
import com.bbn.hadder.Hadder;
+import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.core.Perm;
@@ -43,6 +44,8 @@ public class EvalCommand implements Command {
engine.put("author", event.getAuthor());
engine.put("member", event.getMember());
engine.put("self", event.getGuild().getSelfMember());
+ engine.put("audio", event.getAudioManager());
+ engine.put("out", System.out);
ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
@@ -52,12 +55,12 @@ public class EvalCommand implements Command {
Object out;
try {
- String script = "";
+ StringBuilder script = new StringBuilder();
for (int i = 0; i < args.length; i++) {
args[i] = args[i].replace("```java", "").replace("```", "");
- script += i == args.length - 1 ? args[i] : args[i] + " ";
+ script.append(i == args.length - 1 ? args[i] : args[i] + " ");
}
- out = engine.eval(script);
+ out = engine.eval(script.toString());
event.getTextChannel().sendMessage(event.getMessageEditor()
.getMessage(MessageEditor.MessageType.INFO, "commands.owner.eval.success.title", "")
diff --git a/src/main/java/com/bbn/hadder/core/CommandHandler.java b/src/main/java/com/bbn/hadder/core/CommandHandler.java
index 9d7469f..8734539 100644
--- a/src/main/java/com/bbn/hadder/core/CommandHandler.java
+++ b/src/main/java/com/bbn/hadder/core/CommandHandler.java
@@ -1,6 +1,7 @@
package com.bbn.hadder.core;
import com.bbn.hadder.Rethink;
+import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.commands.general.HelpCommand;
@@ -23,7 +24,7 @@ public class CommandHandler {
this.helpCommand = helpCommand;
}
- public void handle(MessageReceivedEvent event, Rethink rethink, String prefix) {
+ public void handle(MessageReceivedEvent event, Rethink rethink, String prefix, AudioManager audioManager) {
String invoke = event.getMessage().getContentRaw().replaceFirst(prefix, "").split(" ")[0];
for (Command cmd : commandList) {
for (String label : cmd.labels()) {
@@ -35,7 +36,7 @@ public class CommandHandler {
if (args.length > 0 && args[0].equals("")) args = new String[0];
CommandEvent commandEvent = new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink,
- config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()), new EventWaiter());
+ config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()), new EventWaiter(), audioManager);
if (cmd.getClass().getAnnotations().length > 0 && !Arrays.asList(cmd.getClass().getAnnotations()).contains(Perms.class)) {
for (Perm perm : cmd.getClass().getAnnotation(Perms.class).value()) {
if (!perm.check(commandEvent)) {
diff --git a/src/main/java/com/bbn/hadder/listener/CommandListener.java b/src/main/java/com/bbn/hadder/listener/CommandListener.java
index 3598e1e..dff1e8b 100644
--- a/src/main/java/com/bbn/hadder/listener/CommandListener.java
+++ b/src/main/java/com/bbn/hadder/listener/CommandListener.java
@@ -1,6 +1,7 @@
package com.bbn.hadder.listener;
import com.bbn.hadder.Rethink;
+import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.core.CommandHandler;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@@ -14,10 +15,12 @@ public class CommandListener extends ListenerAdapter {
private Rethink rethink;
private CommandHandler handler;
+ private AudioManager audioManager;
- public CommandListener(Rethink rethink, CommandHandler handler) {
+ public CommandListener(Rethink rethink, CommandHandler handler, AudioManager audioManager) {
this.rethink = rethink;
this.handler = handler;
+ this.audioManager = audioManager;
}
@Override
@@ -31,7 +34,7 @@ public class CommandListener extends ListenerAdapter {
};
for (String prefix : prefixes) {
if (event.getMessage().getContentRaw().startsWith(prefix)) {
- handler.handle(event, rethink, prefix);
+ handler.handle(event, rethink, prefix, audioManager);
return;
}
}
diff --git a/src/main/java/com/bbn/hadder/listener/VoiceLeaveListener.java b/src/main/java/com/bbn/hadder/listener/VoiceLeaveListener.java
new file mode 100644
index 0000000..643a17a
--- /dev/null
+++ b/src/main/java/com/bbn/hadder/listener/VoiceLeaveListener.java
@@ -0,0 +1,28 @@
+package com.bbn.hadder.listener;
+
+import com.bbn.hadder.audio.AudioManager;
+import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
+import net.dv8tion.jda.api.hooks.ListenerAdapter;
+
+/**
+ * @author Skidder / GregTCLTK
+ */
+
+public class VoiceLeaveListener extends ListenerAdapter {
+
+ private AudioManager audioManager;
+
+ public VoiceLeaveListener(AudioManager audioManager) {
+ this.audioManager = audioManager;
+ }
+
+ @Override
+ public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
+ if (new AudioManager().hasPlayer(event.getGuild()) && event.getChannelLeft().getMembers().equals(event.getGuild().getSelfMember())) {
+ audioManager.players.remove(event.getGuild().getId());
+ audioManager.getPlayer(event.getGuild()).destroy();
+ audioManager.getTrackManager(event.getGuild()).purgeQueue();
+ event.getGuild().getAudioManager().closeAudioConnection();
+ }
+ }
+}
diff --git a/src/main/java/com/bbn/hadder/utils/MessageEditor.java b/src/main/java/com/bbn/hadder/utils/MessageEditor.java
index c7205f1..c5b10fe 100644
--- a/src/main/java/com/bbn/hadder/utils/MessageEditor.java
+++ b/src/main/java/com/bbn/hadder/utils/MessageEditor.java
@@ -24,21 +24,21 @@ public class MessageEditor {
return this.getMessage(type, "", "", "", "", "", "");
}
- public EmbedBuilder getMessage(MessageType type, String title_language_string, String description_language_string) {
- return this.getMessage(type, title_language_string, "", "", description_language_string, "", "");
+ public EmbedBuilder getMessage(MessageType type, String title, String description) {
+ return this.getMessage(type, title, "", "", description, "", "");
}
- public EmbedBuilder getMessage(MessageType type, String title_language_string, String title_extra,
- String description_language_string, String description_extra) {
- return this.getMessage(type, title_language_string, title_extra, "", description_language_string, description_extra, "");
+ public EmbedBuilder getMessage(MessageType type, String title, String title_extra,
+ String description, String description_extra) {
+ return this.getMessage(type, title, title_extra, "", description, description_extra, "");
}
- public EmbedBuilder getMessage(MessageType type, String title_language_string, String title_extra, String title_extra_two,
- String description_language_string, String description_extra, String description_extra_two) {
+ public EmbedBuilder getMessage(MessageType type, String title, String title_extra, String title_extra_two,
+ String description, String description_extra, String description_extra_two) {
String language = (this.user!=null) ? rethink.getLanguage(this.user.getId()) : null;
EmbedBuilder eb = this.getDefaultSettings(type);
- if (!title_language_string.equals("")) eb.setTitle(this.handle(language, title_language_string, title_extra, title_extra_two));
- if (!description_language_string.equals("")) eb.setDescription(this.handle(language, description_language_string, description_extra, description_extra_two));
+ if (!title.equals("")) eb.setTitle(this.handle(language, title, title_extra, title_extra_two));
+ if (!description.equals("")) eb.setDescription(this.handle(language, description, description_extra, description_extra_two));
return eb;
}
@@ -122,7 +122,7 @@ public class MessageEditor {
Locale locale = new Locale(language_code);
ResourceBundle resourceBundle = ResourceBundle.getBundle("Translations/Translations", locale);
if (resourceBundle.containsKey(string))
- return resourceBundle.getString(string).replaceAll("%prefix%", "h.").replaceAll("%extra%", extra).replaceAll("%extra_two%", extra_two);
- else return "This key doesn't exist. Please report this to the Bot Developers. Key: "+string+" Language_code: "+language_code;
+ return resourceBundle.getString(string).replaceAll("%extra%", extra).replaceAll("%extra_two%", extra_two);
+ else return "This key doesn't exist. Please report this to the Bot Developers. Key: " + string + " Language_code: " + language_code;
}
}
diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties
index 6ff6c80..d9f7d84 100644
--- a/src/main/resources/Translations/Translations_en.properties
+++ b/src/main/resources/Translations/Translations_en.properties
@@ -84,7 +84,7 @@ commands.misc.screenshare.channel.existing.error = Hol' up
commands.misc.screenshare.channel.existing.description = There is no Voice Channel named like this. \n\nNote\: Make sure the Voice Channel is in this Guild.
commands.misc.screenshare.help.description = Shows you the link to share your screen.
-commands.moderation.ban.success.title = %extra% Successfully banned %extra%
+commands.moderation.ban.success.title = Successfully banned
commands.moderation.ban.success.description = I successfully baned %extra%
commands.moderation.ban.error.title = Not possible
commands.moderation.ban.myself.error.description = I can not ban myself\!
@@ -179,9 +179,9 @@ commands.moderation.editrules.help.description = Edits the rules message.
commands.music.join.success.title = Successfully connected
commands.music.join.success.description = I successfully connected to %extra%.
commands.music.join.error.connecting.already.title = Already connected
-commands.music.join.error.connecting.already.description = I am already connected to your voice channel.
+commands.music.join.error.connecting.already.description = I am already connected to your voice channel
commands.music.join.error.connecting.trying.title = Already trying to connect
-commands.music.join.error.connecting.trying.description = Hadder is already trying to connect. Please wait a moment.
+commands.music.join.error.connecting.trying.description = Hadder is already trying to connect. Please wait a moment
commands.music.join.error.channel.title = No Voice Channel
commands.music.join.error.channel.description = You aren't in a Voice Channel.
commands.music.join.help.description = Joins your voice channel
@@ -193,39 +193,48 @@ commands.music.leave.help.description = Leaves a voice channel
commands.music.play.load.title = %extra% Now loading %extra%
commands.music.play.load.description = Trying to load the song...
commands.music.play.success.loading.title = %extra% Now playing %extra%
-commands.music.play.error.load.title = %extra% Load failed %extra%
-commands.music.play.error.load.description = Unfortunately I can not load the given song.
-commands.music.play.error.match.title = %extra% No matches %extra%
-commands.music.play.error.match.description = I can not find a song named this on YouTube.
commands.music.play.success.title = Title
commands.music.play.success.author = Author
commands.music.play.success.length = Length
+commands.music.play.success.tracks = Tracks
+commands.music.play.error.load.title = %extra% Load failed %extra%
+commands.music.play.error.load.description = Unfortunately I can not load the given song
+commands.music.play.error.match.title = %extra% No matches %extra%
+commands.music.play.error.match.description = I can not find a song named this on YouTube
commands.music.play.help.description = Plays a song
commands.music.stop.success.title = Successfully stopped
commands.music.stop.success.description = I successfully stopped the song.
+commands.music.info.success.title = Track info
+commands.music.info.error.title = No playing track
+commands.music.info.error.description = I am not playing anything at the moment
+commands.music.info.help.description = Shows information about the playing song
commands.music.stop.help.description = Stops the song
commands.music.queue.error.title = No queue
commands.music.queue.error.description = There are no queued songs at the moment
commands.music.queue.success.title = Queue
-commands.music.queue.success.description = This is the queue\: %extra%
+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.help.description = Skips the currently playing song
commands.nsfw.gif.error.title = GIF not showing? Click here
commands.nsfw.img.error.title = Image not showing? Click here
-commands.nsfw.anal.help.description = Shows a random anal gif.
-commands.nsfw.bdsm.help.description = Shows a random BDSM picture.
-commands.nsfw.blowjob.help.description = Shows a random Blowjob picture.
-commands.nsfw.boobs.help.description = Shows a random boob gif.
-commands.nsfw.cum.help.description = Shows a random cum gif.
-commands.nsfw.erotic.help.description = Shows a random erotic picture.
-commands.nsfw.feet.help.description = Shows a random feet gif.
-commands.nsfw.fingering.help.description = Shows a random fingering gif.
-commands.nsfw.linking.help.description = Shows a random licking gif.
-commands.nsfw.porn.help.description = Shows a random porn gif.
-commands.nsfw.pussy.help.description = Shows a random pussy gif.
-commands.nsfw.randomporn.help.description = Shows a completely random porn gif.
-commands.nsfw.solo.help.description = Shows a random solo gif.
-commands.nsfw.spank.help.description = Shows a random spank gif.
-commands.nsfw.trans.help.description = Shows a random trans picture.
+commands.nsfw.anal.help.description = Shows a random anal gif
+commands.nsfw.bdsm.help.description = Shows a random BDSM picture
+commands.nsfw.blowjob.help.description = Shows a random Blowjob picture
+commands.nsfw.boobs.help.description = Shows a random boob gif
+commands.nsfw.cum.help.description = Shows a random cum gif
+commands.nsfw.erotic.help.description = Shows a random erotic picture
+commands.nsfw.feet.help.description = Shows a random feet gif
+commands.nsfw.fingering.help.description = Shows a random fingering gif
+commands.nsfw.linking.help.description = Shows a random licking gif
+commands.nsfw.porn.help.description = Shows a random porn gif
+commands.nsfw.pussy.help.description = Shows a random pussy gif
+commands.nsfw.randomporn.help.description = Shows a completely random porn gif
+commands.nsfw.solo.help.description = Shows a random solo gif
+commands.nsfw.spank.help.description = Shows a random spank gif
+commands.nsfw.trans.help.description = Shows a random trans picture
commands.owner.eval.success.title = Eval Command
commands.owner.eval.success.input = Input