This commit is contained in:
Hax 2019-12-28 13:24:39 +01:00
parent 1c75ed6255
commit c3aaa9a238
10 changed files with 46 additions and 23 deletions

View file

@ -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.*;
@ -42,6 +43,8 @@ public class Hadder {
HelpCommand helpCommand = new HelpCommand();
AudioManager audioManager = new AudioManager();
CommandHandler commandHandler = new CommandHandler(
List.of(
helpCommand,
@ -100,7 +103,7 @@ 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),

View file

@ -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;
}
}

View file

@ -18,11 +18,11 @@ public class InfoCommand implements Command {
@Override
public void executed(String[] args, CommandEvent event) {
if (new AudioManager().hasPlayer(event.getGuild()) && new AudioManager().getPlayer(event.getGuild()).getPlayingTrack() == null) {
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 **|>** `[ " + new AudioManager().getTimestamp(track.getPosition()) + " / " + new AudioManager().getTimestamp(track.getInfo().length) + " ]`",
"\n" + MIC, new AudioManager().getOrNull(track.getInfo().author),
if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() == null) {
AudioTrack track = event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack();
event.getTextChannel().sendMessage("Track Info" + String.format(QUEUE_DESCRIPTION, CD, event.getAudioManager().getOrNull(track.getInfo().title),
"\n\u23F1 **|>** `[ " + event.getAudioManager().getTimestamp(track.getPosition()) + " / " + event.getAudioManager().getTimestamp(track.getInfo().length) + " ]`",
"\n" + MIC, event.getAudioManager().getOrNull(track.getInfo().author),
"\n\uD83C\uDFA7 **|>** " + "")).queue();
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,

View file

@ -24,12 +24,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(

View file

@ -17,13 +17,13 @@ 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<AudioInfo> queue = new AudioManager().getTrackManager(event.getGuild()).getQueuedTracks();
Set<AudioInfo> queue = event.getAudioManager().getTrackManager(event.getGuild()).getQueuedTracks();
EmbedBuilder b = event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.queue.success.title",
"commands.music.queue.success.description")

View file

@ -13,7 +13,7 @@ public class SkipCommand implements Command {
@Override
public void executed(String[] args, CommandEvent event) {
event.getAudioManager().forceSkipTrack(event);
}
@Override

View file

@ -13,10 +13,10 @@ public class StopCommand implements Command {
@Override
public void executed(String[] args, CommandEvent event) {
if (new AudioManager().hasPlayer(event.getGuild())) {
new AudioManager().players.remove(event.getGuild().getId());
new AudioManager().getPlayer(event.getGuild()).destroy();
new AudioManager().getTrackManager(event.getGuild()).purgeQueue();
if (event.getAudioManager().hasPlayer(event.getGuild())) {
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",

View file

@ -29,11 +29,8 @@ public class GuildLeaveCommand implements Command {
} catch (Exception e) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.WARNING, "commands.owner.guildleave.error.title", "", "commands.owner.guildleave.help.description", guild.getName()).build()).queue();
}
<<<<<<< Updated upstream
} else {
event.getHelpCommand().sendHelp(this, event);
=======
>>>>>>> Stashed changes
}
}

View file

@ -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)) {

View file

@ -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;
}
}