commit
ec11cf7035
10 changed files with 47 additions and 20 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package com.bbn.hadder;
|
package com.bbn.hadder;
|
||||||
|
|
||||||
|
import com.bbn.hadder.audio.AudioManager;
|
||||||
import com.bbn.hadder.commands.general.*;
|
import com.bbn.hadder.commands.general.*;
|
||||||
import com.bbn.hadder.commands.misc.*;
|
import com.bbn.hadder.commands.misc.*;
|
||||||
import com.bbn.hadder.commands.moderation.*;
|
import com.bbn.hadder.commands.moderation.*;
|
||||||
|
|
@ -42,6 +43,8 @@ public class Hadder {
|
||||||
|
|
||||||
HelpCommand helpCommand = new HelpCommand();
|
HelpCommand helpCommand = new HelpCommand();
|
||||||
|
|
||||||
|
AudioManager audioManager = new AudioManager();
|
||||||
|
|
||||||
CommandHandler commandHandler = new CommandHandler(
|
CommandHandler commandHandler = new CommandHandler(
|
||||||
List.of(
|
List.of(
|
||||||
helpCommand,
|
helpCommand,
|
||||||
|
|
@ -100,7 +103,7 @@ public class Hadder {
|
||||||
builder.addEventListeners(
|
builder.addEventListeners(
|
||||||
new MentionListener(rethink),
|
new MentionListener(rethink),
|
||||||
new PrivateMessageListener(rethink),
|
new PrivateMessageListener(rethink),
|
||||||
new CommandListener(rethink, commandHandler),
|
new CommandListener(rethink, commandHandler, audioManager),
|
||||||
new GuildListener(rethink, config),
|
new GuildListener(rethink, config),
|
||||||
new ReadyListener(rethink, config),
|
new ReadyListener(rethink, config),
|
||||||
new InviteLinkListener(rethink),
|
new InviteLinkListener(rethink),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bbn.hadder.commands;
|
package com.bbn.hadder.commands;
|
||||||
|
|
||||||
import com.bbn.hadder.Rethink;
|
import com.bbn.hadder.Rethink;
|
||||||
|
import com.bbn.hadder.audio.AudioManager;
|
||||||
import com.bbn.hadder.commands.general.HelpCommand;
|
import com.bbn.hadder.commands.general.HelpCommand;
|
||||||
import com.bbn.hadder.core.CommandHandler;
|
import com.bbn.hadder.core.CommandHandler;
|
||||||
import com.bbn.hadder.core.Config;
|
import com.bbn.hadder.core.Config;
|
||||||
|
|
@ -8,6 +9,7 @@ import com.bbn.hadder.utils.EventWaiter;
|
||||||
import com.bbn.hadder.utils.MessageEditor;
|
import com.bbn.hadder.utils.MessageEditor;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.events.Event;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -20,8 +22,9 @@ public class CommandEvent extends MessageReceivedEvent {
|
||||||
private HelpCommand helpCommand;
|
private HelpCommand helpCommand;
|
||||||
private MessageEditor messageEditor;
|
private MessageEditor messageEditor;
|
||||||
private EventWaiter eventWaiter;
|
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);
|
super(api, responseNumber, message);
|
||||||
this.rethink = rethink;
|
this.rethink = rethink;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
@ -29,6 +32,18 @@ public class CommandEvent extends MessageReceivedEvent {
|
||||||
this.helpCommand = helpCommand;
|
this.helpCommand = helpCommand;
|
||||||
this.messageEditor = messageEditor;
|
this.messageEditor = messageEditor;
|
||||||
this.eventWaiter = eventWaiter;
|
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() {
|
public Rethink getRethink() {
|
||||||
|
|
@ -54,4 +69,8 @@ public class CommandEvent extends MessageReceivedEvent {
|
||||||
public EventWaiter getEventWaiter() {
|
public EventWaiter getEventWaiter() {
|
||||||
return eventWaiter;
|
return eventWaiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AudioManager getAudioManager() {
|
||||||
|
return audioManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ public class InfoCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executed(String[] args, CommandEvent event) {
|
public void executed(String[] args, CommandEvent event) {
|
||||||
if (new AudioManager().hasPlayer(event.getGuild()) && new AudioManager().getPlayer(event.getGuild()).getPlayingTrack() == null) {
|
if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() == null) {
|
||||||
AudioTrack track = new AudioManager().getPlayer(event.getGuild()).getPlayingTrack();
|
AudioTrack track = event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack();
|
||||||
event.getTextChannel().sendMessage("Track Info" + String.format(QUEUE_DESCRIPTION, CD, new AudioManager().getOrNull(track.getInfo().title),
|
event.getTextChannel().sendMessage("Track Info" + String.format(QUEUE_DESCRIPTION, CD, event.getAudioManager().getOrNull(track.getInfo().title),
|
||||||
"\n\u23F1 **|>** `[ " + new AudioManager().getTimestamp(track.getPosition()) + " / " + new AudioManager().getTimestamp(track.getInfo().length) + " ]`",
|
"\n\u23F1 **|>** `[ " + event.getAudioManager().getTimestamp(track.getPosition()) + " / " + event.getAudioManager().getTimestamp(track.getInfo().length) + " ]`",
|
||||||
"\n" + MIC, new AudioManager().getOrNull(track.getInfo().author),
|
"\n" + MIC, event.getAudioManager().getOrNull(track.getInfo().author),
|
||||||
"\n\uD83C\uDFA7 **|>** " + "")).queue();
|
"\n\uD83C\uDFA7 **|>** " + "")).queue();
|
||||||
} else {
|
} else {
|
||||||
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
|
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,12 @@ public class PlayCommand implements Command {
|
||||||
Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
|
Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
|
||||||
"commands.music.play.load.title", "⭕",
|
"commands.music.play.load.title", "⭕",
|
||||||
"commands.music.play.load.description", "").build()).complete();
|
"commands.music.play.load.description", "").build()).complete();
|
||||||
new AudioManager().loadTrack(input, event, msg);
|
event.getAudioManager().loadTrack(input, event, msg);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
|
Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
|
||||||
"commands.music.play.load.title", "⭕",
|
"commands.music.play.load.title", "⭕",
|
||||||
"commands.music.play.load.description", "").build()).complete();
|
"commands.music.play.load.description", "").build()).complete();
|
||||||
new AudioManager().loadTrack("ytsearch: " + input, event, msg);
|
event.getAudioManager().loadTrack("ytsearch: " + input, event, msg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
|
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@ public class QueueCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executed(String[] args, CommandEvent event) {
|
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,
|
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.WARNING,
|
||||||
"commands.music.queue.error.title",
|
"commands.music.queue.error.title",
|
||||||
"commands.music.queue.error.description"
|
"commands.music.queue.error.description"
|
||||||
).build()).queue();
|
).build()).queue();
|
||||||
} else {
|
} 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,
|
EmbedBuilder b = event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
|
||||||
"commands.music.queue.success.title",
|
"commands.music.queue.success.title",
|
||||||
"commands.music.queue.success.description")
|
"commands.music.queue.success.description")
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ public class SkipCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executed(String[] args, CommandEvent event) {
|
public void executed(String[] args, CommandEvent event) {
|
||||||
|
event.getAudioManager().forceSkipTrack(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ public class StopCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executed(String[] args, CommandEvent event) {
|
public void executed(String[] args, CommandEvent event) {
|
||||||
if (new AudioManager().hasPlayer(event.getGuild())) {
|
if (event.getAudioManager().hasPlayer(event.getGuild())) {
|
||||||
new AudioManager().players.remove(event.getGuild().getId());
|
event.getAudioManager().players.remove(event.getGuild().getId());
|
||||||
new AudioManager().getPlayer(event.getGuild()).destroy();
|
event.getAudioManager().getPlayer(event.getGuild()).destroy();
|
||||||
new AudioManager().getTrackManager(event.getGuild()).purgeQueue();
|
event.getAudioManager().getTrackManager(event.getGuild()).purgeQueue();
|
||||||
event.getGuild().getAudioManager().closeAudioConnection();
|
event.getGuild().getAudioManager().closeAudioConnection();
|
||||||
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
|
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
|
||||||
"commands.music.stop.success.title",
|
"commands.music.stop.success.title",
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ public class EvalCommand implements Command {
|
||||||
engine.put("member", event.getMember());
|
engine.put("member", event.getMember());
|
||||||
engine.put("self", event.getGuild().getSelfMember());
|
engine.put("self", event.getGuild().getSelfMember());
|
||||||
engine.put("audio", new AudioManager());
|
engine.put("audio", new AudioManager());
|
||||||
|
engine.put("out", System.out);
|
||||||
|
|
||||||
ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
|
ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bbn.hadder.core;
|
package com.bbn.hadder.core;
|
||||||
|
|
||||||
import com.bbn.hadder.Rethink;
|
import com.bbn.hadder.Rethink;
|
||||||
|
import com.bbn.hadder.audio.AudioManager;
|
||||||
import com.bbn.hadder.commands.Command;
|
import com.bbn.hadder.commands.Command;
|
||||||
import com.bbn.hadder.commands.CommandEvent;
|
import com.bbn.hadder.commands.CommandEvent;
|
||||||
import com.bbn.hadder.commands.general.HelpCommand;
|
import com.bbn.hadder.commands.general.HelpCommand;
|
||||||
|
|
@ -23,7 +24,7 @@ public class CommandHandler {
|
||||||
this.helpCommand = helpCommand;
|
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];
|
String invoke = event.getMessage().getContentRaw().replaceFirst(prefix, "").split(" ")[0];
|
||||||
for (Command cmd : commandList) {
|
for (Command cmd : commandList) {
|
||||||
for (String label : cmd.labels()) {
|
for (String label : cmd.labels()) {
|
||||||
|
|
@ -35,7 +36,7 @@ public class CommandHandler {
|
||||||
if (args.length > 0 && args[0].equals("")) args = new String[0];
|
if (args.length > 0 && args[0].equals("")) args = new String[0];
|
||||||
|
|
||||||
CommandEvent commandEvent = new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink,
|
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)) {
|
if (cmd.getClass().getAnnotations().length > 0 && !Arrays.asList(cmd.getClass().getAnnotations()).contains(Perms.class)) {
|
||||||
for (Perm perm : cmd.getClass().getAnnotation(Perms.class).value()) {
|
for (Perm perm : cmd.getClass().getAnnotation(Perms.class).value()) {
|
||||||
if (!perm.check(commandEvent)) {
|
if (!perm.check(commandEvent)) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bbn.hadder.listener;
|
package com.bbn.hadder.listener;
|
||||||
|
|
||||||
import com.bbn.hadder.Rethink;
|
import com.bbn.hadder.Rethink;
|
||||||
|
import com.bbn.hadder.audio.AudioManager;
|
||||||
import com.bbn.hadder.core.CommandHandler;
|
import com.bbn.hadder.core.CommandHandler;
|
||||||
import net.dv8tion.jda.api.entities.ChannelType;
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
@ -14,10 +15,12 @@ public class CommandListener extends ListenerAdapter {
|
||||||
|
|
||||||
private Rethink rethink;
|
private Rethink rethink;
|
||||||
private CommandHandler handler;
|
private CommandHandler handler;
|
||||||
|
private AudioManager audioManager;
|
||||||
|
|
||||||
public CommandListener(Rethink rethink, CommandHandler handler) {
|
public CommandListener(Rethink rethink, CommandHandler handler, AudioManager audioManager) {
|
||||||
this.rethink = rethink;
|
this.rethink = rethink;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
this.audioManager = audioManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -31,7 +34,7 @@ public class CommandListener extends ListenerAdapter {
|
||||||
};
|
};
|
||||||
for (String prefix : prefixes) {
|
for (String prefix : prefixes) {
|
||||||
if (event.getMessage().getContentRaw().startsWith(prefix)) {
|
if (event.getMessage().getContentRaw().startsWith(prefix)) {
|
||||||
handler.handle(event, rethink, prefix);
|
handler.handle(event, rethink, prefix, audioManager);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue