v0.1.3 - Reorganized command layout
This commit is contained in:
@@ -1,20 +1,12 @@
|
||||
package com.bensherriff.siren;
|
||||
|
||||
import com.bensherriff.siren.audio.AudioHandler;
|
||||
import com.bensherriff.siren.audio.PlayerManager;
|
||||
import com.bensherriff.siren.listener.Listener;
|
||||
import com.bensherriff.siren.listener.TextListener;
|
||||
import com.bensherriff.siren.settings.Settings;
|
||||
import com.bensherriff.siren.settings.SettingsManager;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||
@@ -24,26 +16,20 @@ import org.apache.logging.log4j.Logger;
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MusicBot extends ListenerAdapter {
|
||||
public class MusicBot {
|
||||
private static final Logger LOGGER = LogManager.getLogger(MusicBot.class);
|
||||
private final static GatewayIntent[] INTENTS = {
|
||||
GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS,
|
||||
GatewayIntent.GUILD_VOICE_STATES
|
||||
GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.MESSAGE_CONTENT
|
||||
};
|
||||
private final static CacheFlag[] ENABLED_FLAGS = {
|
||||
CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE
|
||||
};
|
||||
private final static CacheFlag[] DISABLED_FLAGS = {
|
||||
CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE, CacheFlag.ONLINE_STATUS
|
||||
CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.ONLINE_STATUS, CacheFlag.EMOJI, CacheFlag.STICKER, CacheFlag.SCHEDULED_EVENTS
|
||||
};
|
||||
private final PlayerManager playerManager;
|
||||
private final Map<Long, AudioHandler> musicManagers;
|
||||
private final Settings settings;
|
||||
|
||||
private JDA jda;
|
||||
public static Listener listener;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
start();
|
||||
@@ -52,162 +38,14 @@ public class MusicBot extends ListenerAdapter {
|
||||
private static void start() throws IOException, LoginException {
|
||||
SettingsManager settingsManager = new SettingsManager();
|
||||
Settings settings = settingsManager.load();
|
||||
MusicBot musicBot = new MusicBot(settings);
|
||||
listener = new TextListener(settings);
|
||||
|
||||
JDA jda = JDABuilder.create(settings.getToken(), Arrays.asList(INTENTS))
|
||||
.enableCache(Arrays.asList(ENABLED_FLAGS))
|
||||
.disableCache(Arrays.asList(DISABLED_FLAGS))
|
||||
.addEventListeners(musicBot)
|
||||
.addEventListeners(listener)
|
||||
.setBulkDeleteSplittingEnabled(true)
|
||||
.build();
|
||||
musicBot.setJDA(jda);
|
||||
}
|
||||
|
||||
private MusicBot(Settings settings) {
|
||||
this.musicManagers = new HashMap<>();
|
||||
this.settings = settings;
|
||||
|
||||
this.playerManager = new PlayerManager(this);
|
||||
this.playerManager.initialize();
|
||||
}
|
||||
|
||||
public void setJDA(JDA jda) {
|
||||
this.jda = jda;
|
||||
}
|
||||
|
||||
public JDA getJDA() {
|
||||
return jda;
|
||||
}
|
||||
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void closeAudioConnection(long guildID) {
|
||||
Guild guild = jda.getGuildById(guildID);
|
||||
if (guild != null) {
|
||||
guild.getAudioManager().closeAudioConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
|
||||
if (event.getAuthor().isBot()) return;
|
||||
|
||||
String[] command = event.getMessage().getContentRaw().split(" ", 2);
|
||||
TextChannel channel = event.getChannel();
|
||||
|
||||
if ("!play".equals(command[0]) && command.length == 2) {
|
||||
loadAndPlay(channel, command[1]);
|
||||
} else if ("!skip".equals(command[0])) {
|
||||
skipTrack(channel);
|
||||
} else if ("!stop".equals(command[0])) {
|
||||
stopTrack(channel);
|
||||
} else if ("!volume".equals(command[0])) {
|
||||
changeVolume(channel, command[1]);
|
||||
} else if ("!pause".equals(command[0])) {
|
||||
pauseTrack(channel);
|
||||
} else if ("!resume".equals(command[0])) {
|
||||
resumeTrack(channel);
|
||||
}
|
||||
|
||||
super.onGuildMessageReceived(event);
|
||||
}
|
||||
|
||||
private synchronized AudioHandler getGuildAudioPlayer(Guild guild) {
|
||||
long guildId = Long.parseLong(guild.getId());
|
||||
AudioHandler audioHandler = musicManagers.get(guildId);
|
||||
|
||||
if (audioHandler == null) {
|
||||
LOGGER.info("Creating Audio Handler for guild " + guildId);
|
||||
audioHandler = new AudioHandler(playerManager, guildId);
|
||||
musicManagers.put(guildId, audioHandler);
|
||||
}
|
||||
|
||||
guild.getAudioManager().setSendingHandler(audioHandler);
|
||||
|
||||
return audioHandler;
|
||||
}
|
||||
|
||||
private void loadAndPlay(final TextChannel channel, final String trackUrl) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
|
||||
playerManager.loadItemOrdered(audioHandler, trackUrl, new AudioLoadResultHandler() {
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track) {
|
||||
channel.sendMessage("Adding **" + track.getInfo().title + "** to queue").queue();
|
||||
playTrack(channel.getGuild(), audioHandler, track);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
AudioTrack firstTrack = playlist.getSelectedTrack();
|
||||
|
||||
if (firstTrack == null) {
|
||||
firstTrack = playlist.getTracks().get(0);
|
||||
}
|
||||
|
||||
channel.sendMessage("Adding **" + firstTrack.getInfo().title + "** to queue (first track of playlist " + playlist.getName() + ")").queue();
|
||||
playTrack(channel.getGuild(), audioHandler, firstTrack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noMatches() {
|
||||
channel.sendMessage("Nothing found by " + trackUrl).queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFailed(FriendlyException exception) {
|
||||
channel.sendMessage("Could not play: " + exception.getMessage()).queue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void playTrack(Guild guild, AudioHandler audioHandler, AudioTrack track) {
|
||||
connectToFirstVoiceChannel(guild.getAudioManager());
|
||||
audioHandler.addTrack(track);
|
||||
}
|
||||
|
||||
private void stopTrack(TextChannel channel) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
audioHandler.stopTrack();
|
||||
channel.getGuild().getAudioManager().closeAudioConnection();
|
||||
channel.sendMessage("Stopping music").queue();
|
||||
}
|
||||
|
||||
private void skipTrack(TextChannel channel) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
audioHandler.stopTrack();
|
||||
channel.sendMessage("Skipped to next track").queue();
|
||||
}
|
||||
|
||||
private void pauseTrack(TextChannel channel) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
audioHandler.setPaused(true);
|
||||
channel.sendMessage("Paused track").queue();
|
||||
}
|
||||
|
||||
private void resumeTrack(TextChannel channel) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
audioHandler.setPaused(false);
|
||||
channel.sendMessage("Resumed track").queue();
|
||||
}
|
||||
|
||||
private void changeVolume(TextChannel channel, String vol) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
int volume = Integer.parseInt(vol);
|
||||
settings.setVolume(volume);
|
||||
audioHandler.setVolume(volume);
|
||||
channel.sendMessage("Set volume to " + volume).queue();
|
||||
}
|
||||
|
||||
//TODO connect to user's channel instead of first voice channel
|
||||
private static void connectToFirstVoiceChannel(AudioManager audioManager) {
|
||||
if (!audioManager.isConnected()) {
|
||||
for (VoiceChannel voiceChannel : audioManager.getGuild().getVoiceChannels()) {
|
||||
audioManager.openAudioConnection(voiceChannel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
listener.setJDA(jda);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
|
||||
public AudioHandler(PlayerManager manager, long guildID) {
|
||||
this.manager = manager;
|
||||
player = manager.createPlayer();
|
||||
player.setVolume(manager.getBot().getSettings().getVolume());
|
||||
player.setVolume(manager.getListener().getSettings().getVolume());
|
||||
player.addListener(this);
|
||||
this.queue = new LinkedBlockingQueue<>();
|
||||
this.buffer = ByteBuffer.allocate(1024);
|
||||
@@ -75,7 +75,7 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
|
||||
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
|
||||
// LOGGER.debug("Track ended: " + endReason.name() + "; starting next: " + endReason.mayStartNext);
|
||||
if (queue.isEmpty()) {
|
||||
manager.getBot().closeAudioConnection(guildID);
|
||||
manager.getListener().closeAudioConnection(guildID);
|
||||
} else {
|
||||
player.playTrack(queue.poll());
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.bensherriff.siren.audio;
|
||||
|
||||
import com.bensherriff.siren.MusicBot;
|
||||
import com.bensherriff.siren.listener.Listener;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||
|
||||
public class PlayerManager extends DefaultAudioPlayerManager {
|
||||
|
||||
private final MusicBot bot;
|
||||
private final Listener listener;
|
||||
|
||||
public PlayerManager(MusicBot bot) {
|
||||
this.bot = bot;
|
||||
public PlayerManager(Listener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public MusicBot getBot() {
|
||||
return bot;
|
||||
public Listener getListener() {
|
||||
return listener;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.bensherriff.siren.listener;
|
||||
|
||||
import com.bensherriff.siren.audio.AudioHandler;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandEvent {
|
||||
|
||||
private final String command;
|
||||
private final String userId;
|
||||
private final List<String> args = new ArrayList<>();
|
||||
private final AudioHandler audioHandler;
|
||||
private final TextChannel textChannel;
|
||||
|
||||
private CommandEvent(CommandBuilder builder) {
|
||||
this.command = builder.command;
|
||||
this.userId = builder.userId;
|
||||
this.args.addAll(builder.args);
|
||||
this.audioHandler = builder.audioHandler;
|
||||
this.textChannel = builder.textChannel;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public List<String> getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public AudioHandler getAudioHandler() {
|
||||
return audioHandler;
|
||||
}
|
||||
|
||||
public TextChannel getTextChannel() {
|
||||
return textChannel;
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private final String command;
|
||||
private final String userId;
|
||||
private List<String> args = new ArrayList<>();
|
||||
private AudioHandler audioHandler;
|
||||
private TextChannel textChannel;
|
||||
|
||||
public CommandBuilder(String command, String userId) {
|
||||
this.command = command;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public CommandBuilder setArgs(List<String> args) {
|
||||
this.args = args;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandBuilder setAudioHandler(AudioHandler audioHandler) {
|
||||
this.audioHandler = audioHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandBuilder setTextChannel(TextChannel textChannel) {
|
||||
this.textChannel = textChannel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandEvent build() {
|
||||
return new CommandEvent(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
164
src/main/java/com/bensherriff/siren/listener/Listener.java
Normal file
164
src/main/java/com/bensherriff/siren/listener/Listener.java
Normal file
@@ -0,0 +1,164 @@
|
||||
package com.bensherriff.siren.listener;
|
||||
|
||||
import com.bensherriff.siren.audio.AudioHandler;
|
||||
import com.bensherriff.siren.audio.PlayerManager;
|
||||
import com.bensherriff.siren.settings.Settings;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
||||
import net.dv8tion.jda.api.events.session.ReadyEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Listener extends ListenerAdapter {
|
||||
protected static final Logger LOGGER = LogManager.getLogger(Listener.class);
|
||||
|
||||
protected final PlayerManager playerManager;
|
||||
protected final Map<Long, AudioHandler> musicManagers;
|
||||
protected final Settings settings;
|
||||
protected JDA jda;
|
||||
|
||||
public Listener(Settings settings) {
|
||||
this.musicManagers = new HashMap<>();
|
||||
this.settings = settings;
|
||||
|
||||
this.playerManager = new PlayerManager(this);
|
||||
this.playerManager.initialize();
|
||||
}
|
||||
|
||||
public JDA getJDA() {
|
||||
return jda;
|
||||
}
|
||||
|
||||
public void setJDA(JDA jda) {
|
||||
this.jda = jda;
|
||||
}
|
||||
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void closeAudioConnection(long guildID) {
|
||||
Guild guild = jda.getGuildById(guildID);
|
||||
if (guild != null) {
|
||||
guild.getAudioManager().closeAudioConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized AudioHandler getGuildAudioPlayer(Guild guild) {
|
||||
long guildId = Long.parseLong(guild.getId());
|
||||
AudioHandler audioHandler = musicManagers.get(guildId);
|
||||
|
||||
if (audioHandler == null) {
|
||||
LOGGER.info("Creating Audio Handler for guild " + guildId);
|
||||
audioHandler = new AudioHandler(playerManager, guildId);
|
||||
musicManagers.put(guildId, audioHandler);
|
||||
}
|
||||
|
||||
if (!audioHandler.equals(guild.getAudioManager().getSendingHandler())) {
|
||||
guild.getAudioManager().setSendingHandler(audioHandler);
|
||||
}
|
||||
|
||||
return audioHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(@NotNull ReadyEvent event) {
|
||||
super.onReady(event);
|
||||
}
|
||||
|
||||
protected void loadAndPlay(final TextChannel channel, final String userID, final String trackUrl) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
|
||||
playerManager.loadItemOrdered(audioHandler, trackUrl, new AudioLoadResultHandler() {
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track) {
|
||||
channel.sendMessage("Adding **" + track.getInfo().title + "** to queue").queue();
|
||||
playTrack(channel.getGuild(), userID, audioHandler, track);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
AudioTrack firstTrack = playlist.getSelectedTrack();
|
||||
|
||||
if (firstTrack == null) {
|
||||
firstTrack = playlist.getTracks().get(0);
|
||||
}
|
||||
|
||||
channel.sendMessage("Adding **" + firstTrack.getInfo().title + "** to queue (first track of playlist " + playlist.getName() + ")").queue();
|
||||
playTrack(channel.getGuild(), userID, audioHandler, firstTrack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noMatches() {
|
||||
channel.sendMessage("Nothing found by " + trackUrl).queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFailed(FriendlyException exception) {
|
||||
channel.sendMessage("Could not play: " + exception.getMessage()).queue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void playTrack(Guild guild, String userID, AudioHandler audioHandler, AudioTrack track) {
|
||||
connectToVoiceChannel(userID, guild.getAudioManager());
|
||||
audioHandler.addTrack(track);
|
||||
}
|
||||
|
||||
protected void stopTrack(TextChannel channel) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
audioHandler.stopTrack();
|
||||
channel.getGuild().getAudioManager().closeAudioConnection();
|
||||
channel.sendMessage("Stopping music").queue();
|
||||
}
|
||||
|
||||
protected void skipTrack(TextChannel channel) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
audioHandler.stopTrack();
|
||||
channel.sendMessage("Skipped to next track").queue();
|
||||
}
|
||||
|
||||
protected void pauseTrack(TextChannel channel) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
audioHandler.setPaused(true);
|
||||
channel.sendMessage("Paused track").queue();
|
||||
}
|
||||
|
||||
protected void resumeTrack(TextChannel channel) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
audioHandler.setPaused(false);
|
||||
channel.sendMessage("Resumed track").queue();
|
||||
}
|
||||
|
||||
protected void changeVolume(TextChannel channel, String vol) {
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
int volume = Integer.parseInt(vol);
|
||||
getSettings().setVolume(volume);
|
||||
audioHandler.setVolume(volume);
|
||||
channel.sendMessage("Set volume to " + volume).queue();
|
||||
}
|
||||
|
||||
private void connectToVoiceChannel(String userID, AudioManager audioManager) {
|
||||
if (!audioManager.isConnected()) {
|
||||
Member member = audioManager.getGuild().getMemberById(userID);
|
||||
if (member != null && member.getVoiceState() != null && member.getVoiceState().inAudioChannel()) {
|
||||
VoiceChannel voiceChannel = Objects.requireNonNull(member.getVoiceState().getChannel()).asVoiceChannel();
|
||||
audioManager.openAudioConnection(voiceChannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.bensherriff.siren.listener;
|
||||
|
||||
import com.bensherriff.siren.settings.Settings;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SlashListener extends Listener {
|
||||
|
||||
public SlashListener(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
|
||||
super.onSlashCommandInteraction(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.bensherriff.siren.listener;
|
||||
|
||||
import com.bensherriff.siren.audio.AudioHandler;
|
||||
import com.bensherriff.siren.settings.Settings;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TextListener extends Listener {
|
||||
|
||||
public TextListener(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
|
||||
if (event.getAuthor().isBot()) return;
|
||||
|
||||
String[] command = event.getMessage().getContentRaw().split(" ");
|
||||
TextChannel channel = event.getChannel().asTextChannel();
|
||||
String userID = event.getAuthor().getId();
|
||||
AudioHandler audioHandler = getGuildAudioPlayer(channel.getGuild());
|
||||
|
||||
CommandEvent commandEvent = new CommandEvent.CommandBuilder(command[0], userID)
|
||||
.setTextChannel(channel)
|
||||
.setAudioHandler(audioHandler)
|
||||
.setArgs(Arrays.asList(command).subList(1, command.length))
|
||||
.build();
|
||||
|
||||
if ("!play".equals(command[0]) && command.length == 2) {
|
||||
loadAndPlay(channel, userID, command[1]);
|
||||
} else if ("!skip".equals(command[0])) {
|
||||
skipTrack(channel);
|
||||
} else if ("!stop".equals(command[0])) {
|
||||
stopTrack(channel);
|
||||
} else if ("!volume".equals(command[0]) && command.length == 2) {
|
||||
changeVolume(channel, command[1]);
|
||||
} else if ("!pause".equals(command[0])) {
|
||||
pauseTrack(channel);
|
||||
} else if ("!resume".equals(command[0])) {
|
||||
resumeTrack(channel);
|
||||
}
|
||||
|
||||
super.onMessageReceived(event);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user