Implement command results in execute function
This commit is contained in:
1 parent
278924e7d9
commit
47e8332931
33 files changed
+416
-238
No files matched your search
@@ -13,7 +13,7 @@ import net.dv8tion.jda.api.entities.Activity;
|
|||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.exceptions.InvalidTokenException;
|
import net.dv8tion.jda.api.exceptions.InvalidTokenException;
|
||||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||||
import netneutrality.core.CommandManager;
|
import netneutrality.command.CommandManager;
|
||||||
import netneutrality.core.LogHandler;
|
import netneutrality.core.LogHandler;
|
||||||
import netneutrality.db.DBController;
|
import netneutrality.db.DBController;
|
||||||
import netneutrality.hooks.SlashCommandHooks;
|
import netneutrality.hooks.SlashCommandHooks;
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ public abstract class AbstractCommand implements ICommand {
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
// Prefer slash commands
|
// Prefer slash commands
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package netneutrality.command;
|
||||||
|
/*
|
||||||
|
* Copyright (c) anthorob
|
||||||
|
*
|
||||||
|
* https://discord.gg/qUa6zNFZsd
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CommandExecutionResult {
|
||||||
|
|
||||||
|
public enum Result {
|
||||||
|
SUCCESS, INFO, WARN, ERROR, NOACTION
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Result result;
|
||||||
|
private final String message;
|
||||||
|
private final Exception exception;
|
||||||
|
|
||||||
|
private CommandExecutionResult(Result result, String message, Exception exception) {
|
||||||
|
this.result = result;
|
||||||
|
this.message = message;
|
||||||
|
this.exception = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CommandExecutionResult(Result result, String message) {
|
||||||
|
this(result, message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Exception getException() {
|
||||||
|
return exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandExecutionResult success(String message) {
|
||||||
|
return new CommandExecutionResult(Result.SUCCESS, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandExecutionResult info(String message) {
|
||||||
|
return new CommandExecutionResult(Result.INFO, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandExecutionResult warn(String message) {
|
||||||
|
return new CommandExecutionResult(Result.WARN, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandExecutionResult error(String message, Exception exception) {
|
||||||
|
return new CommandExecutionResult(Result.ERROR, message, exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandExecutionResult error(String message) {
|
||||||
|
return error(message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandExecutionResult none() {
|
||||||
|
return new CommandExecutionResult(Result.NOACTION, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-3
@@ -1,5 +1,4 @@
|
|||||||
package netneutrality.core;
|
package netneutrality.command;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
*
|
*
|
||||||
@@ -11,7 +10,7 @@ import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
||||||
import netneutrality.NetNeutrality;
|
import netneutrality.NetNeutrality;
|
||||||
import netneutrality.command.AbstractCommand;
|
import netneutrality.core.LogHandler;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
@@ -38,7 +38,7 @@ public interface ICommand {
|
|||||||
boolean canBeExecutedFrom(Guild guild, MessageChannel channel);
|
boolean canBeExecutedFrom(Guild guild, MessageChannel channel);
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
void execute(MessageCommandContext context);
|
CommandExecutionResult execute(MessageCommandContext context);
|
||||||
|
|
||||||
void execute(SlashCommandContext context);
|
CommandExecutionResult execute(SlashCommandContext context);
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
import netneutrality.command.AbstractCommand;
|
import netneutrality.command.AbstractCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.command.CommandType;
|
import netneutrality.command.CommandType;
|
||||||
import netneutrality.core.LogHandler;
|
import netneutrality.core.LogHandler;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
@@ -70,12 +71,12 @@ public class BlacklistCommand extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
String sub = context.getEvent().getFullCommandName().split(" ")[1];
|
String sub = context.getEvent().getFullCommandName().split(" ")[1];
|
||||||
DBBlacklist controller = DBController.get(DBBlacklist.class);
|
DBBlacklist controller = DBController.get(DBBlacklist.class);
|
||||||
String word = context.getEvent().getOption("word", "", OptionMapping::getAsString);
|
String word = context.getEvent().getOption("word", "", OptionMapping::getAsString);
|
||||||
@@ -106,5 +107,7 @@ public class BlacklistCommand extends AbstractCommand {
|
|||||||
case "disable" -> controller.disable(word, context);
|
case "disable" -> controller.disable(word, context);
|
||||||
case "enable" -> controller.enable(word, context);
|
case "enable" -> controller.enable(word, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||||
import netneutrality.command.AbstractCommand;
|
import netneutrality.command.AbstractCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.command.CommandType;
|
import netneutrality.command.CommandType;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
@@ -54,7 +55,7 @@ public class HelpCommand extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
if (context.getArgs().length == 0) {
|
if (context.getArgs().length == 0) {
|
||||||
List<MessageEmbed> help = MessageFunction.buildHelpMessage(context.getGuildUser());
|
List<MessageEmbed> help = MessageFunction.buildHelpMessage(context.getGuildUser());
|
||||||
|
|
||||||
@@ -62,13 +63,14 @@ public class HelpCommand extends AbstractCommand {
|
|||||||
context.replyPrivate(help);
|
context.replyPrivate(help);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
List<MessageEmbed> help = MessageFunction.buildHelpMessage(context.getGuildUser());
|
List<MessageEmbed> help = MessageFunction.buildHelpMessage(context.getGuildUser());
|
||||||
|
|
||||||
context.replyEphemeral("Help has been sent in DM!");
|
|
||||||
context.sendMessageInPrivate(help);
|
context.sendMessageInPrivate(help);
|
||||||
|
return CommandExecutionResult.success("Help has been sent in DM!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ package netneutrality.command.basic;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractCommand;
|
import netneutrality.command.AbstractCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.command.CommandType;
|
import netneutrality.command.CommandType;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
@@ -49,14 +50,16 @@ public class PingCommand extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
if (context.getArgs().length == 0)
|
if (context.getArgs().length == 0)
|
||||||
context.reply(String.format("Pong! [%d ms]", context.getJDA().getGatewayPing()));
|
context.reply(String.format("Pong! [%d ms]", context.getJDA().getGatewayPing()));
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
context.reply(String.format("Pong! [%d ms]", context.getJDA().getGatewayPing()));
|
return CommandExecutionResult.success(String.format("Pong! [%d ms]", context.getJDA().getGatewayPing()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||||
import netneutrality.command.AbstractCommand;
|
import netneutrality.command.AbstractCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.command.CommandType;
|
import netneutrality.command.CommandType;
|
||||||
import netneutrality.core.GuildManager;
|
import netneutrality.core.GuildManager;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
@@ -79,7 +80,7 @@ public class ConfigureCommand extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
String[] args = context.getArgs();
|
String[] args = context.getArgs();
|
||||||
GuildManager guildManager = GuildManager.getManager(context.getGuild());
|
GuildManager guildManager = GuildManager.getManager(context.getGuild());
|
||||||
|
|
||||||
@@ -204,10 +205,12 @@ public class ConfigureCommand extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
String sub = context.getEvent().getFullCommandName().split(" ")[1];
|
String sub = context.getEvent().getFullCommandName().split(" ")[1];
|
||||||
GuildManager guildManager = GuildManager.getManager(context.getGuild());
|
GuildManager guildManager = GuildManager.getManager(context.getGuild());
|
||||||
context.ackAndWait(true);
|
context.ackAndWait(true);
|
||||||
@@ -218,14 +221,14 @@ public class ConfigureCommand extends AbstractCommand {
|
|||||||
|
|
||||||
if (role.getPosition() == -1) {
|
if (role.getPosition() == -1) {
|
||||||
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_ROLE, null);
|
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_ROLE, null);
|
||||||
context.replyEphemeral("Everyone can now use music commands");
|
|
||||||
return;
|
return CommandExecutionResult.success("Everyone can now use music commands");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role.getGuild().getId().equals(context.getGuild().getId())) {
|
if (role.getGuild().getId().equals(context.getGuild().getId())) {
|
||||||
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_ROLE, role.getId());
|
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_ROLE, role.getId());
|
||||||
context.replyEphemeral("Successfully set %s as the role needed for music command", role.getAsMention());
|
|
||||||
return;
|
return CommandExecutionResult.success(String.format("Successfully set %s as the role needed for music command", role.getAsMention()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,15 +237,15 @@ public class ConfigureCommand extends AbstractCommand {
|
|||||||
|
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_CHANNEL, null);
|
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_CHANNEL, null);
|
||||||
context.replyEphemeral("No channel restrictions for music commands");
|
|
||||||
return;
|
return CommandExecutionResult.success("No channel restrictions for music commands");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel instanceof TextChannel) {
|
if (channel instanceof TextChannel) {
|
||||||
if (channel.getGuild().getId().equals(context.getGuild().getId())) {
|
if (channel.getGuild().getId().equals(context.getGuild().getId())) {
|
||||||
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_CHANNEL, channel.getId());
|
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_CHANNEL, channel.getId());
|
||||||
context.replyEphemeral("Successfully set %s as the channel required to execute music command", channel.getAsMention());
|
|
||||||
return;
|
return CommandExecutionResult.success(String.format("Successfully set %s as the channel required to execute music command", channel.getAsMention()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,16 +256,14 @@ public class ConfigureCommand extends AbstractCommand {
|
|||||||
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_VOLUME, String.valueOf(volume));
|
guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_VOLUME, String.valueOf(volume));
|
||||||
MusicManager.get(context.getGuild()).setVolume(volume);
|
MusicManager.get(context.getGuild()).setVolume(volume);
|
||||||
|
|
||||||
context.replyEphemeral("Default volume for music player is now %d", volume);
|
return CommandExecutionResult.success(String.format("Default volume for music player is now %d", volume));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("debug".equals(sub)) {
|
if ("debug".equals(sub)) {
|
||||||
boolean debug = context.getEvent().getOption("debug", true, OptionMapping::getAsBoolean);
|
boolean debug = context.getEvent().getOption("debug", true, OptionMapping::getAsBoolean);
|
||||||
|
|
||||||
guildManager.setDebug(debug);
|
guildManager.setDebug(debug);
|
||||||
context.reply("Error logging is now %s for this guild", (debug ? "enabled" : "disabled"));
|
|
||||||
return;
|
return CommandExecutionResult.success(String.format("Error logging is now %s for this guild", (debug ? "enabled" : "disabled")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("show-all".equals(sub)) {
|
if ("show-all".equals(sub)) {
|
||||||
@@ -282,5 +283,7 @@ public class ConfigureCommand extends AbstractCommand {
|
|||||||
|
|
||||||
context.replyEphemeral(builder.build());
|
context.replyEphemeral(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractCommand;
|
import netneutrality.command.AbstractCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.command.CommandType;
|
import netneutrality.command.CommandType;
|
||||||
import netneutrality.core.LogHandler;
|
import netneutrality.core.LogHandler;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
@@ -62,7 +63,7 @@ public class CryptoPriceCommand extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
String[] args = context.getArgs();
|
String[] args = context.getArgs();
|
||||||
String currency = "USD";
|
String currency = "USD";
|
||||||
|
|
||||||
@@ -71,8 +72,8 @@ public class CryptoPriceCommand extends AbstractCommand {
|
|||||||
try {
|
try {
|
||||||
currency = Currency.getInstance(args[1].toUpperCase()).getCurrencyCode();
|
currency = Currency.getInstance(args[1].toUpperCase()).getCurrencyCode();
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
context.reply("Please enter a valid currency");
|
|
||||||
return;
|
return CommandExecutionResult.warn("Please enter a valid currency");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,10 +102,12 @@ public class CryptoPriceCommand extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
Locale usa = new Locale("en", "US");
|
Locale usa = new Locale("en", "US");
|
||||||
NumberFormat dollarFormat = NumberFormat.getCurrencyInstance(usa);
|
NumberFormat dollarFormat = NumberFormat.getCurrencyInstance(usa);
|
||||||
dollarFormat.setMaximumFractionDigits(24);
|
dollarFormat.setMaximumFractionDigits(24);
|
||||||
@@ -115,8 +118,7 @@ public class CryptoPriceCommand extends AbstractCommand {
|
|||||||
try {
|
try {
|
||||||
currency = Currency.getInstance(currency).getCurrencyCode();
|
currency = Currency.getInstance(currency).getCurrencyCode();
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
context.reply("Please enter a valid currency");
|
return CommandExecutionResult.error("Please enter a valid currency");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String finalCurrency = currency.toUpperCase();
|
String finalCurrency = currency.toUpperCase();
|
||||||
@@ -143,5 +145,7 @@ public class CryptoPriceCommand extends AbstractCommand {
|
|||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ package netneutrality.command.music;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.command.CommandType;
|
import netneutrality.command.CommandType;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
@@ -41,19 +42,20 @@ public class BitconnectCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
player.play("https://www.youtube.com/watch?v=e5nyQmaq4k4", context, false, true);
|
player.play("https://www.youtube.com/watch?v=e5nyQmaq4k4", context, false, true);
|
||||||
|
|
||||||
context.deleteMessage();
|
context.deleteMessage();
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
player.play("https://www.youtube.com/watch?v=e5nyQmaq4k4", context, false, true);
|
player.play("https://www.youtube.com/watch?v=e5nyQmaq4k4", context, false, true);
|
||||||
context.reply("Ready to invest?");
|
return CommandExecutionResult.success("Ready to invest?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ package netneutrality.command.music;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -42,11 +43,11 @@ public class ClearQueueCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (!MusicUtils.checkIfConnected(player, context))
|
if (!MusicUtils.checkIfConnected(player, context))
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
|
|
||||||
if (context.getArgs().length == 0) {
|
if (context.getArgs().length == 0) {
|
||||||
context.reply("Select the track you want to delete from the queue (track# or all)");
|
context.reply("Select the track you want to delete from the queue (track# or all)");
|
||||||
@@ -70,11 +71,7 @@ public class ClearQueueCommand extends AbstractMusicCommand {
|
|||||||
int num = Integer.parseInt(context.getArgument(0));
|
int num = Integer.parseInt(context.getArgument(0));
|
||||||
|
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
if (player.removeFromQueue(num)) {
|
return player.getScheduler().getQueueManager().removeFromQueue(num);
|
||||||
context.reply("Removed track #%d from the queue", num);
|
|
||||||
} else {
|
|
||||||
context.reply("Error while removing track #%d from the queue", num);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
context.reply("Number out of range");
|
context.reply("Number out of range");
|
||||||
}
|
}
|
||||||
@@ -84,22 +81,19 @@ public class ClearQueueCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
if (!MusicUtils.checkIfConnected(manager, context))
|
if (!MusicUtils.checkIfConnected(manager, context))
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
|
|
||||||
int queueSize = manager.getQueueSize();
|
return manager.getScheduler().getQueueManager().clearQueue();
|
||||||
if (queueSize > 0) {
|
|
||||||
manager.getScheduler().getQueueManager().clearQueue();
|
|
||||||
context.reply(String.format("Removed %d track%s from the queue", queueSize--, (queueSize > 1 ? "s" : "")));
|
|
||||||
} else {
|
|
||||||
context.reply("Queue is empty!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ package netneutrality.command.music;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -37,7 +38,7 @@ public class CurrentlyPlayingCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(player, context) && player.isCurrentlyPlaying()) {
|
if (MusicUtils.checkIfConnected(player, context) && player.isCurrentlyPlaying()) {
|
||||||
@@ -46,15 +47,18 @@ public class CurrentlyPlayingCommand extends AbstractMusicCommand {
|
|||||||
context.reply("Bot isn't playing any tracks right now");
|
context.reply("Bot isn't playing any tracks right now");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(manager, context) && manager.isCurrentlyPlaying()) {
|
if (MusicUtils.checkIfConnected(manager, context) && manager.isCurrentlyPlaying()) {
|
||||||
context.reply(MessageFunction.buildCurrentlyPlayingMessage(manager));
|
context.reply(MessageFunction.buildCurrentlyPlayingMessage(manager));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ package netneutrality.command.music;
|
|||||||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.exceptions.CommandExecutionException;
|
import netneutrality.exceptions.CommandExecutionException;
|
||||||
@@ -37,7 +38,7 @@ public class JoinCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (context.getGuildUser().getVoiceState() == null) {
|
if (context.getGuildUser().getVoiceState() == null) {
|
||||||
@@ -45,13 +46,11 @@ public class JoinCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!context.getGuildUser().getVoiceState().inAudioChannel()) {
|
if (!context.getGuildUser().getVoiceState().inAudioChannel()) {
|
||||||
context.reply("You are not in a voice channel");
|
return CommandExecutionResult.warn("You are not in a voice channel");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.isConnected()) {
|
if (player.isConnected()) {
|
||||||
context.reply("Player is already in a voice channel");
|
return CommandExecutionResult.warn("Player is already in a voice channel");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VoiceChannel vChannel = (VoiceChannel) context.getGuildUser().getVoiceState().getChannel();
|
VoiceChannel vChannel = (VoiceChannel) context.getGuildUser().getVoiceState().getChannel();
|
||||||
@@ -60,10 +59,11 @@ public class JoinCommand extends AbstractMusicCommand {
|
|||||||
context.reply("Joining current voice channel");
|
context.reply("Joining current voice channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
@@ -72,13 +72,11 @@ public class JoinCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!context.getGuildUser().getVoiceState().inAudioChannel()) {
|
if (!context.getGuildUser().getVoiceState().inAudioChannel()) {
|
||||||
context.reply("You are not in a voice channel");
|
return CommandExecutionResult.warn("You are not in a voice channel");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.isConnected()) {
|
if (player.isConnected()) {
|
||||||
context.reply("Player is already in a voice channel");
|
return CommandExecutionResult.warn("Player is already in a voice channel");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VoiceChannel vChannel = (VoiceChannel) context.getGuildUser().getVoiceState().getChannel();
|
VoiceChannel vChannel = (VoiceChannel) context.getGuildUser().getVoiceState().getChannel();
|
||||||
@@ -86,5 +84,7 @@ public class JoinCommand extends AbstractMusicCommand {
|
|||||||
player.connect(vChannel);
|
player.connect(vChannel);
|
||||||
context.reply("Joining current voice channel");
|
context.reply("Joining current voice channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ package netneutrality.command.music;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -36,17 +37,19 @@ public class LeaveCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(player, context)) {
|
if (MusicUtils.checkIfConnected(player, context)) {
|
||||||
player.leave();
|
player.leave();
|
||||||
context.reply("Leaving voice channel and clearing queue");
|
context.reply("Leaving voice channel and clearing queue");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
@@ -54,5 +57,7 @@ public class LeaveCommand extends AbstractMusicCommand {
|
|||||||
player.leave();
|
player.leave();
|
||||||
context.reply("Leaving voice channel and clearing queue");
|
context.reply("Leaving voice channel and clearing queue");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -37,21 +38,23 @@ public class PlayCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (context.getArgs().length > 0) {
|
if (context.getArgs().length > 0) {
|
||||||
player.play(context.getMessageText(), context, false, false);
|
player.play(context.getMessageText(), context, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
String query = context.getEvent().getOption("query", OptionMapping::getAsString);
|
String query = context.getEvent().getOption("query", OptionMapping::getAsString);
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
manager.play(query, context, false, false);
|
manager.play(query, context, false, false);
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -58,11 +59,11 @@ public class QueueCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (!MusicUtils.checkIfConnected(player, context))
|
if (!MusicUtils.checkIfConnected(player, context))
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
|
|
||||||
if (context.getArgs().length == 0) {
|
if (context.getArgs().length == 0) {
|
||||||
context.reply("Select the track you want to delete from the queue (track# or all)");
|
context.reply("Select the track you want to delete from the queue (track# or all)");
|
||||||
@@ -86,11 +87,7 @@ public class QueueCommand extends AbstractMusicCommand {
|
|||||||
int num = Integer.parseInt(context.getArgument(0));
|
int num = Integer.parseInt(context.getArgument(0));
|
||||||
|
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
if (player.removeFromQueue(num)) {
|
return player.getScheduler().getQueueManager().removeFromQueue(num);
|
||||||
context.reply("Removed track #%d from the queue", num);
|
|
||||||
} else {
|
|
||||||
context.reply("Error while removing track #%d from the queue", num);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
context.reply("Number out of range");
|
context.reply("Number out of range");
|
||||||
}
|
}
|
||||||
@@ -100,47 +97,34 @@ public class QueueCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
String sub = context.getEvent().getFullCommandName().split(" ")[1];
|
String sub = context.getEvent().getFullCommandName().split(" ")[1];
|
||||||
|
|
||||||
if (!MusicUtils.checkIfConnected(manager, context)) {
|
if (!MusicUtils.checkIfConnected(manager, context)) {
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sub) {
|
switch (sub) {
|
||||||
case "clear-all" -> {
|
case "clear-all" -> {
|
||||||
int queueSize = manager.getQueueSize();
|
return manager.getScheduler().getQueueManager().clearQueue();
|
||||||
|
|
||||||
if (queueSize > 0) {
|
|
||||||
manager.getScheduler().getQueueManager().clearQueue();
|
|
||||||
context.reply(String.format("Removed %d track%s from the queue", queueSize--, (queueSize > 1 ? "s" : "")));
|
|
||||||
} else {
|
|
||||||
context.reply("Queue is already empty!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "delete-track" -> {
|
case "delete-track" -> {
|
||||||
int position = context.getEvent().getOption("position", 0, OptionMapping::getAsInt);
|
int position = context.getEvent().getOption("position", 0, OptionMapping::getAsInt);
|
||||||
|
return manager.getScheduler().getQueueManager().removeFromQueue(position);
|
||||||
if (position > 0) {
|
|
||||||
if (manager.removeFromQueue(position)) {
|
|
||||||
context.reply("Removed track #%d from the queue", position);
|
|
||||||
} else {
|
|
||||||
context.reply("Position is out of bounds");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "show-queue" -> context.reply(MessageFunction.buildViewQueueMessage(manager, true));
|
case "show-queue" -> context.reply(MessageFunction.buildViewQueueMessage(manager, true));
|
||||||
|
|
||||||
case "shuffle" -> {
|
case "shuffle" -> {
|
||||||
manager.getScheduler().getQueueManager().shuffle();
|
return manager.getScheduler().getQueueManager().shuffle();
|
||||||
context.reply("Queue is now shuffled.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "from-user" -> {
|
case "from-user" -> {
|
||||||
@@ -174,6 +158,6 @@ public class QueueCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ package netneutrality.command.music;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
import netneutrality.utils.MusicUtils;
|
import netneutrality.utils.MusicUtils;
|
||||||
@@ -34,13 +35,14 @@ public class ShuffleCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(manager, context)) {
|
if (MusicUtils.checkIfConnected(manager, context)) {
|
||||||
manager.getScheduler().getQueueManager().shuffle();
|
return manager.getScheduler().getQueueManager().shuffle();
|
||||||
context.reply("Queue is now shuffled.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -41,11 +42,11 @@ public class SkipCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (!MusicUtils.checkIfConnected(player, context))
|
if (!MusicUtils.checkIfConnected(player, context))
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
|
|
||||||
if (UserFunction.isAdmin(context.getGuildUser()) || MusicUtils.isUserDj(context.getGuildUser())) {
|
if (UserFunction.isAdmin(context.getGuildUser()) || MusicUtils.isUserDj(context.getGuildUser())) {
|
||||||
if (UserFunction.isAdmin(context.getGuildUser()) && context.getArgs().length > 0) {
|
if (UserFunction.isAdmin(context.getGuildUser()) && context.getArgs().length > 0) {
|
||||||
@@ -65,22 +66,19 @@ public class SkipCommand extends AbstractMusicCommand {
|
|||||||
player.voteSkip(context);
|
player.voteSkip(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
int skips = context.getEvent().getOption("skip", 0, OptionMapping::getAsInt);
|
int skips = context.getEvent().getOption("skip", 1, OptionMapping::getAsInt);
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(manager, context)) {
|
if (MusicUtils.checkIfConnected(manager, context)) {
|
||||||
if (skips > 0) {
|
return manager.getScheduler().getQueueManager().skip(skips);
|
||||||
context.reply("Skipping %s track%s", skips, (skips > 1 ? "s" : ""));
|
|
||||||
manager.getScheduler().getQueueManager().skip(skips);
|
|
||||||
} else {
|
|
||||||
context.reply("Skipping current track");
|
|
||||||
manager.getScheduler().getQueueManager().skip(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ package netneutrality.command.music;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -37,28 +38,31 @@ public class StopCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (!MusicUtils.checkIfConnected(player, context))
|
if (!MusicUtils.checkIfConnected(player, context))
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
|
|
||||||
// Need a resume command before
|
// Need a resume command before
|
||||||
// if (UserFunction.isAdmin(context.getGuildUser()) || MusicUtils.isUserDj(context.getGuildUser())) {
|
|
||||||
if (UserFunction.isAdmin(context.getGuildUser())) {
|
if (UserFunction.isAdmin(context.getGuildUser())) {
|
||||||
player.stopTrack();
|
player.stopTrack();
|
||||||
context.reply("Stopping current track");
|
context.reply("Stopping current track");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(manager, context)) {
|
if (MusicUtils.checkIfConnected(manager, context)) {
|
||||||
manager.stopTrack();
|
manager.stopTrack();
|
||||||
context.reply("Stopping music playback");
|
return CommandExecutionResult.success("Stopping music playback");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ package netneutrality.command.music;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -36,7 +37,7 @@ public class ViewQueueCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(player, context)) {
|
if (MusicUtils.checkIfConnected(player, context)) {
|
||||||
@@ -48,10 +49,11 @@ public class ViewQueueCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
context.ackAndWait();
|
context.ackAndWait();
|
||||||
|
|
||||||
@@ -61,8 +63,10 @@ public class ViewQueueCommand extends AbstractMusicCommand {
|
|||||||
if (queueSize > 0) {
|
if (queueSize > 0) {
|
||||||
context.reply(MessageFunction.buildViewQueueMessage(manager, true));
|
context.reply(MessageFunction.buildViewQueueMessage(manager, true));
|
||||||
} else {
|
} else {
|
||||||
context.reply("Queue is empty!");
|
return CommandExecutionResult.warn("Queue is empty!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
|
|||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -41,11 +42,11 @@ public class VolumeCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager player = MusicManager.get(context.getGuild());
|
MusicManager player = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (!MusicUtils.checkIfConnected(player, context))
|
if (!MusicUtils.checkIfConnected(player, context))
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
|
|
||||||
if (UserFunction.isAdmin(context.getGuildUser()) || MusicUtils.isUserDj(context.getGuildUser())) {
|
if (UserFunction.isAdmin(context.getGuildUser()) || MusicUtils.isUserDj(context.getGuildUser())) {
|
||||||
try {
|
try {
|
||||||
@@ -61,16 +62,20 @@ public class VolumeCommand extends AbstractMusicCommand {
|
|||||||
context.reply("Please enter a value from 0 to 100");
|
context.reply("Please enter a value from 0 to 100");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
int volume = context.getEvent().getOption("volume", 30, OptionMapping::getAsInt);
|
int volume = context.getEvent().getOption("volume", 30, OptionMapping::getAsInt);
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(manager, context)) {
|
if (MusicUtils.checkIfConnected(manager, context)) {
|
||||||
context.reply("Volume set to %s", volume);
|
|
||||||
manager.setVolume(volume);
|
manager.setVolume(volume);
|
||||||
|
return CommandExecutionResult.success(String.format("Volume set to %s", volume));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ package netneutrality.command.music;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import netneutrality.command.AbstractMusicCommand;
|
import netneutrality.command.AbstractMusicCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
@@ -35,20 +36,24 @@ public class VoteSkipCommand extends AbstractMusicCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MessageCommandContext context) {
|
public CommandExecutionResult execute(MessageCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(manager, context)) {
|
if (MusicUtils.checkIfConnected(manager, context)) {
|
||||||
manager.voteSkip(context);
|
manager.voteSkip(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(SlashCommandContext context) {
|
public CommandExecutionResult execute(SlashCommandContext context) {
|
||||||
MusicManager manager = MusicManager.get(context.getGuild());
|
MusicManager manager = MusicManager.get(context.getGuild());
|
||||||
|
|
||||||
if (MusicUtils.checkIfConnected(manager, context)) {
|
if (MusicUtils.checkIfConnected(manager, context)) {
|
||||||
manager.voteSkip(context);
|
return manager.voteSkip(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package netneutrality.core;
|
||||||
|
/*
|
||||||
|
* Copyright (c) anthorob
|
||||||
|
*
|
||||||
|
* https://discord.gg/qUa6zNFZsd
|
||||||
|
*/
|
||||||
|
|
||||||
|
import io.sentry.Sentry;
|
||||||
|
import netneutrality.command.AbstractCommand;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
|
import netneutrality.command.CommandManager;
|
||||||
|
import netneutrality.core.context.CommandContext;
|
||||||
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
|
import netneutrality.exceptions.CommandExecutionException;
|
||||||
|
import netneutrality.utils.UserFunction;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import static netneutrality.command.CommandExecutionResult.Result.*;
|
||||||
|
|
||||||
|
public class CommandProcessor {
|
||||||
|
|
||||||
|
private final static Logger logger = LogManager.getLogger(CommandProcessor.class);
|
||||||
|
private final String commandName;
|
||||||
|
private final CommandContext context;
|
||||||
|
|
||||||
|
public CommandProcessor(String commandName, CommandContext context) {
|
||||||
|
this.commandName = commandName;
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispatch() {
|
||||||
|
|
||||||
|
if (!CommandManager.isValidCommand(commandName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractCommand command = CommandManager.getCommand(commandName);
|
||||||
|
logger.info("Executing command {} on guild {}", command.getCommandName(), context.getGuild().getId());
|
||||||
|
|
||||||
|
if (context instanceof SlashCommandContext slashCommandContext)
|
||||||
|
logger.debug("SlashCommandInteractionId: {}", slashCommandContext.getEvent().getInteraction().getId());
|
||||||
|
|
||||||
|
configureSentry(command);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (context instanceof MessageCommandContext && command.needAdmin() && !UserFunction.isAdmin(context.getGuildUser())) {
|
||||||
|
context.reply("You are not powerful enough, scrub");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.canBeExecutedBy(context.getGuild(), context.getGuildUser())) {
|
||||||
|
if (command.canBeExecutedFrom(context.getGuild(), context.getChannel())) {
|
||||||
|
CommandExecutionResult commandExecutionResult = null;
|
||||||
|
|
||||||
|
if (context instanceof SlashCommandContext slashCommandContext) {
|
||||||
|
commandExecutionResult = command.execute(slashCommandContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context instanceof MessageCommandContext messageCommandContext) {
|
||||||
|
commandExecutionResult = command.execute(messageCommandContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandExecutionResult == null) {
|
||||||
|
throw new RuntimeException("Command type is not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandExecutionResult.Result result = commandExecutionResult.getResult();
|
||||||
|
String message = commandExecutionResult.getMessage();
|
||||||
|
if (result == NOACTION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == ERROR) {
|
||||||
|
Exception exception = commandExecutionResult.getException();
|
||||||
|
|
||||||
|
logger.error("Error from command {}: {}", command.getCommandName(), message, exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.reply(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: make better
|
||||||
|
} catch (CommandExecutionException exception) {
|
||||||
|
LogHandler.log(exception);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
LogHandler.log(new CommandExecutionException("Error during command execution", context, exception));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureSentry(AbstractCommand command) {
|
||||||
|
|
||||||
|
Sentry.configureScope(scope -> {
|
||||||
|
scope.setContexts("command", command.getCommandName());
|
||||||
|
scope.setContexts("isAdmin", UserFunction.isAdmin(context.getGuildUser()));
|
||||||
|
scope.setContexts("canBeExecuted", command.canBeExecutedBy(context.getGuild(), context.getGuildUser()));
|
||||||
|
scope.setTag("channel", context.getChannel().getId());
|
||||||
|
|
||||||
|
if (context instanceof SlashCommandContext slashCommandContext)
|
||||||
|
scope.setTag("interactionId", slashCommandContext.getEvent().getInteraction().getId());
|
||||||
|
|
||||||
|
if (context instanceof MessageCommandContext messageCommandContext)
|
||||||
|
scope.setTag("message", messageCommandContext.getMessage().getId());
|
||||||
|
|
||||||
|
scope.setTag("guild", context.getGuild().getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,6 +57,4 @@ public interface CommandContext {
|
|||||||
default void replyToMessage(MessageEmbed... embeds) {
|
default void replyToMessage(MessageEmbed... embeds) {
|
||||||
replyToMessage(MessageCreateData.fromEmbeds(embeds));
|
replyToMessage(MessageCreateData.fromEmbeds(embeds));
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatchToCommand(String commandName);
|
|
||||||
}
|
}
|
||||||
@@ -13,13 +13,9 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
|||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
import netneutrality.command.AbstractCommand;
|
import netneutrality.command.AbstractCommand;
|
||||||
import netneutrality.core.CommandManager;
|
|
||||||
import netneutrality.core.GuildManager;
|
import netneutrality.core.GuildManager;
|
||||||
import netneutrality.core.LogHandler;
|
|
||||||
import netneutrality.exceptions.CommandExecutionException;
|
|
||||||
import netneutrality.thread.ThreadManager;
|
import netneutrality.thread.ThreadManager;
|
||||||
import netneutrality.utils.Settings;
|
import netneutrality.utils.Settings;
|
||||||
import netneutrality.utils.UserFunction;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@@ -193,39 +189,4 @@ public class MessageCommandContext implements CommandContext {
|
|||||||
return creatorId.equals(member.getId());
|
return creatorId.equals(member.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchToCommand(String commandName) {
|
|
||||||
if (!CommandManager.isValidCommand(commandName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractCommand command = CommandManager.getCommand(commandName);
|
|
||||||
this.command = command;
|
|
||||||
//TODO: Add usage check
|
|
||||||
|
|
||||||
Sentry.configureScope(scope -> {
|
|
||||||
scope.setContexts("command", command.getCommandName());
|
|
||||||
scope.setContexts("isAdmin", UserFunction.isAdmin(member));
|
|
||||||
scope.setContexts("canBeExecuted", command.canBeExecutedBy(guild, member));
|
|
||||||
scope.setTag("channel", channel.getId());
|
|
||||||
scope.setTag("message", message.getId());
|
|
||||||
scope.setTag("guild", guild.getId());
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (command.needAdmin() && !UserFunction.isAdmin(member)) {
|
|
||||||
reply("You are not powerful enough, scrub");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.canBeExecutedBy(guild, member)) {
|
|
||||||
if (command.canBeExecutedFrom(guild, channel)) {
|
|
||||||
command.execute(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (CommandExecutionException e) {
|
|
||||||
LogHandler.log(e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogHandler.log(new CommandExecutionException("Error during command execution", this, e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
package netneutrality.core.context;
|
package netneutrality.core.context;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) anthorob
|
* Copyright (c) anthorob
|
||||||
*
|
*
|
||||||
* https://discord.gg/qUa6zNFZsd
|
* https://discord.gg/qUa6zNFZsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import io.sentry.Sentry;
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
@@ -19,9 +17,6 @@ import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
|||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageEditData;
|
import net.dv8tion.jda.api.utils.messages.MessageEditData;
|
||||||
import netneutrality.command.AbstractCommand;
|
import netneutrality.command.AbstractCommand;
|
||||||
import netneutrality.core.CommandManager;
|
|
||||||
import netneutrality.core.LogHandler;
|
|
||||||
import netneutrality.exceptions.CommandExecutionException;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -174,32 +169,12 @@ public class SlashCommandContext implements CommandContext {
|
|||||||
ackAndWait(false);
|
ackAndWait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchToCommand(String commandName) {
|
public void ack() {
|
||||||
if (!CommandManager.isValidCommand(commandName)) {
|
ackAndWait();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractCommand command = CommandManager.getCommand(commandName);
|
public void ephemeral() {
|
||||||
this.command = command;
|
ackAndWait(true);
|
||||||
|
|
||||||
Sentry.configureScope(scope -> {
|
|
||||||
scope.setContexts("command", command.getCommandName());
|
|
||||||
scope.setContexts("canBeExecuted", command.canBeExecutedBy(guild, member));
|
|
||||||
scope.setTag("channel", channel.getId());
|
|
||||||
scope.setTag("interactionId", event.getInteraction().getId());
|
|
||||||
scope.setTag("guild", guild.getId());
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (command.canBeExecutedBy(guild, member)) {
|
|
||||||
command.execute(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (CommandExecutionException exception) {
|
|
||||||
LogHandler.log(exception);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
LogHandler.log(new CommandExecutionException("Error during command execution", this, exception));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ package netneutrality.hooks;
|
|||||||
|
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
import netneutrality.core.CommandProcessor;
|
||||||
import netneutrality.core.context.SlashCommandContext;
|
import netneutrality.core.context.SlashCommandContext;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -17,6 +18,8 @@ public class SlashCommandHooks extends ListenerAdapter {
|
|||||||
String commandName = event.getName();
|
String commandName = event.getName();
|
||||||
|
|
||||||
SlashCommandContext commandContext = SlashCommandContext.createContext(event);
|
SlashCommandContext commandContext = SlashCommandContext.createContext(event);
|
||||||
commandContext.dispatchToCommand(commandName);
|
CommandProcessor processor = new CommandProcessor(commandName, commandContext);
|
||||||
|
processor.dispatch();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import io.sentry.Sentry;
|
|||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
import netneutrality.core.CommandProcessor;
|
||||||
import netneutrality.core.GuildManager;
|
import netneutrality.core.GuildManager;
|
||||||
import netneutrality.core.context.MessageCommandContext;
|
import netneutrality.core.context.MessageCommandContext;
|
||||||
import netneutrality.utils.Settings;
|
import netneutrality.utils.Settings;
|
||||||
@@ -28,7 +29,6 @@ public class MessageReceivedHandler extends ListenerAdapter {
|
|||||||
Message message = event.getMessage();
|
Message message = event.getMessage();
|
||||||
|
|
||||||
MessageCommandContext context = MessageCommandContext.createContext(event);
|
MessageCommandContext context = MessageCommandContext.createContext(event);
|
||||||
Sentry.addBreadcrumb(Breadcrumb.info("New message from " + context.getGuildUser().getEffectiveName()));
|
|
||||||
|
|
||||||
GuildManager.getManager(context.getGuild()).checkAndLogMessage(message, context.getGuildUser(), context.getChannel());
|
GuildManager.getManager(context.getGuild()).checkAndLogMessage(message, context.getGuildUser(), context.getChannel());
|
||||||
|
|
||||||
@@ -40,7 +40,8 @@ public class MessageReceivedHandler extends ListenerAdapter {
|
|||||||
// rawMessage = rawMessage.substring(prefix.length()).trim();
|
// rawMessage = rawMessage.substring(prefix.length()).trim();
|
||||||
String commandString = rawMessage.split(" ", 2)[0];
|
String commandString = rawMessage.split(" ", 2)[0];
|
||||||
|
|
||||||
context.dispatchToCommand(commandString);
|
CommandProcessor processor = new CommandProcessor(commandString, context);
|
||||||
|
processor.dispatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@ import net.dv8tion.jda.api.entities.Guild;
|
|||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import netneutrality.core.GuildManager;
|
import netneutrality.core.GuildManager;
|
||||||
import netneutrality.core.LogHandler;
|
import netneutrality.core.LogHandler;
|
||||||
import netneutrality.core.context.CommandContext;
|
import netneutrality.core.context.CommandContext;
|
||||||
@@ -152,7 +153,7 @@ public class MusicManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void play(String url, CommandContext context, boolean needToBeConnected, boolean silent) {
|
public synchronized void play(String url, CommandContext context, boolean needToBeConnected, boolean silent) {
|
||||||
logger.debug("Guild {}: request to play {} by user {}", guild.getId(), url, context.getGuildUser().getId());
|
logger.debug("Guild {}: request to play '{}' by user {}", guild.getId(), url, context.getGuildUser().getId());
|
||||||
|
|
||||||
List<LoadableSong> toLoad = new ArrayList<>();
|
List<LoadableSong> toLoad = new ArrayList<>();
|
||||||
toLoad.add(new LoadableSong(null, url, null));
|
toLoad.add(new LoadableSong(null, url, null));
|
||||||
@@ -194,24 +195,24 @@ public class MusicManager {
|
|||||||
loader.loadAllSongs(songs);
|
loader.loadAllSongs(songs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean removeFromQueue(int index) {
|
|
||||||
return scheduler.getQueueManager().removeFromQueue(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void stopTrack() {
|
public synchronized void stopTrack() {
|
||||||
player.stopTrack();
|
player.stopTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void voteSkip(CommandContext context) {
|
public synchronized CommandExecutionResult voteSkip(CommandContext context) {
|
||||||
VoiceChannel voiceChannel = (VoiceChannel) guild.getAudioManager().getConnectedChannel();
|
VoiceChannel voiceChannel = (VoiceChannel) guild.getAudioManager().getConnectedChannel();
|
||||||
QueueManager.TrackInfo info = scheduler.getQueueManager().peekHeadOfQueue();
|
|
||||||
|
|
||||||
if (!isCurrentlyPlaying() || voiceChannel == null) {
|
if (voiceChannel == null) {
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isCurrentlyPlaying()) {
|
||||||
|
return CommandExecutionResult.none();
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueManager.TrackInfo info = scheduler.getQueueManager().peekHeadOfQueue();
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Minus the bot itself
|
// Minus the bot itself
|
||||||
@@ -219,9 +220,9 @@ public class MusicManager {
|
|||||||
|
|
||||||
if (connected < 3) {
|
if (connected < 3) {
|
||||||
context.reply("Skipping current track since not enough people are connected to the voice channel.");
|
context.reply("Skipping current track since not enough people are connected to the voice channel.");
|
||||||
scheduler.getQueueManager().skip(1);
|
scheduler.getQueueManager().skip();
|
||||||
|
|
||||||
return;
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
double needed = connected / 2.1;
|
double needed = connected / 2.1;
|
||||||
@@ -230,11 +231,12 @@ public class MusicManager {
|
|||||||
logger.debug("VoteSkip: guild={}, connected={}, needed={}, skips={}, user={}", context.getGuild().getId(), connected, needed, info.getSkips().size(), context.getGuildUser().getId());
|
logger.debug("VoteSkip: guild={}, connected={}, needed={}, skips={}, user={}", context.getGuild().getId(), connected, needed, info.getSkips().size(), context.getGuildUser().getId());
|
||||||
|
|
||||||
if (info.getSkips().size() > needed) {
|
if (info.getSkips().size() > needed) {
|
||||||
context.reply("Skipping current track: %s", info.getTrack().getInfo().title);
|
return scheduler.getQueueManager().skip();
|
||||||
scheduler.getQueueManager().skip(1);
|
|
||||||
} else {
|
} else {
|
||||||
context.reply("Adding your vote to skip the current track. Current votes: %d/%d", info.getSkips().size(), (int) Math.ceil(needed));
|
context.reply("Adding your vote to skip the current track. Current votes: %d/%d", info.getSkips().size(), (int) Math.ceil(needed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setVolume(int volume) {
|
public synchronized void setVolume(int volume) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
|||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import netneutrality.command.CommandExecutionResult;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -136,12 +137,22 @@ public class QueueManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearQueue() {
|
public CommandExecutionResult clearQueue() {
|
||||||
scheduler.getMusicManager().stopLoading();
|
scheduler.getMusicManager().stopLoading();
|
||||||
scheduler.getMusicManager().leave();
|
scheduler.getMusicManager().leave();
|
||||||
|
|
||||||
|
if (queue.isEmpty()) {
|
||||||
|
return CommandExecutionResult.warn("Queue is empty!");
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (queue) {
|
synchronized (queue) {
|
||||||
|
int queueSize = queue.size();
|
||||||
|
if (queueSize == 0) {
|
||||||
|
return CommandExecutionResult.warn("Queue is empty!");
|
||||||
|
}
|
||||||
|
|
||||||
queue.clear();
|
queue.clear();
|
||||||
|
return CommandExecutionResult.success(String.format("Removed %d track%s from the queue", queueSize--, (queueSize > 1 ? "s" : "")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,19 +221,19 @@ public class QueueManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void skip() {
|
public CommandExecutionResult skip() {
|
||||||
skip(1);
|
return skip(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void skip(int nbTrack) {
|
public CommandExecutionResult skip(int nbTrack) {
|
||||||
if (nbTrack == 0)
|
if (nbTrack == 0) {
|
||||||
return;
|
nbTrack = 1;
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (queue) {
|
synchronized (queue) {
|
||||||
|
|
||||||
if (queue.isEmpty()) {
|
if (queue.isEmpty()) {
|
||||||
scheduler.getMusicManager().leave();
|
scheduler.getMusicManager().leave();
|
||||||
return;
|
return CommandExecutionResult.info("Queue is empty, leaving voice channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbTrack > queue.size()) {
|
if (nbTrack > queue.size()) {
|
||||||
@@ -234,11 +245,22 @@ public class QueueManager {
|
|||||||
queue.poll();
|
queue.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (queue.isEmpty()) {
|
||||||
|
scheduler.getMusicManager().leave();
|
||||||
|
return CommandExecutionResult.info("Queue is empty, leaving voice channel");
|
||||||
|
}
|
||||||
|
|
||||||
startNextTrack();
|
startNextTrack();
|
||||||
|
|
||||||
|
return CommandExecutionResult.success(String.format("Skipping %s track%s..", nbTrack, (nbTrack > 1 ? "s" : "")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shuffle() {
|
public CommandExecutionResult shuffle() {
|
||||||
|
if (queue.size() > 3) {
|
||||||
|
return CommandExecutionResult.none();
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (queue) {
|
synchronized (queue) {
|
||||||
if (queue.size() > 3) {
|
if (queue.size() > 3) {
|
||||||
logger.debug("Guild {}: shuffling queue", guild.getId());
|
logger.debug("Guild {}: shuffling queue", guild.getId());
|
||||||
@@ -251,29 +273,43 @@ public class QueueManager {
|
|||||||
queue.clear();
|
queue.clear();
|
||||||
queue.add(current);
|
queue.add(current);
|
||||||
queue.addAll(newQueue);
|
queue.addAll(newQueue);
|
||||||
|
|
||||||
|
return CommandExecutionResult.success("Queue is now shuffled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CommandExecutionResult.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeFromQueue(int index) {
|
public CommandExecutionResult removeFromQueue(int index) {
|
||||||
|
if (queue.isEmpty() || index < 1) {
|
||||||
|
return CommandExecutionResult.none();
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (queue) {
|
synchronized (queue) {
|
||||||
if (queue.size() > 0 && index <= queue.size()) {
|
if (queue.isEmpty()) {
|
||||||
|
return CommandExecutionResult.none();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index > queue.size()) {
|
||||||
|
return CommandExecutionResult.error("Position is out of bounds");
|
||||||
|
}
|
||||||
|
|
||||||
logger.debug("Guild {}: removing index {} from queue", guild.getId(), index - 1);
|
logger.debug("Guild {}: removing index {} from queue", guild.getId(), index - 1);
|
||||||
|
|
||||||
if (index == 1) {
|
if (index > 1) {
|
||||||
skip(1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<TrackInfo> newQueue = new ArrayList<>(queue);
|
List<TrackInfo> newQueue = new ArrayList<>(queue);
|
||||||
newQueue.remove(index - 1);
|
newQueue.remove(index - 1);
|
||||||
|
|
||||||
queue.clear();
|
queue.clear();
|
||||||
queue.addAll(newQueue);
|
queue.addAll(newQueue);
|
||||||
return true;
|
|
||||||
|
return CommandExecutionResult.success(String.format("Removed track #%d from the queue", index));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
skip();
|
||||||
|
return CommandExecutionResult.none();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
|
|||||||
import netneutrality.NetNeutrality;
|
import netneutrality.NetNeutrality;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MusicPlayerAutoDisconnectThread implements Runnable {
|
public class MusicPlayerAutoDisconnectThread implements Runnable {
|
||||||
|
|
||||||
final MusicManager manager;
|
private final Logger logger = LogManager.getLogger(MusicPlayerAutoDisconnectThread.class);
|
||||||
|
private final MusicManager manager;
|
||||||
|
|
||||||
//TODO: move to scheduler
|
//TODO: move to scheduler
|
||||||
public MusicPlayerAutoDisconnectThread(MusicManager musicManager) {
|
public MusicPlayerAutoDisconnectThread(MusicManager musicManager) {
|
||||||
@@ -35,7 +37,7 @@ public class MusicPlayerAutoDisconnectThread implements Runnable {
|
|||||||
Thread.sleep(30000);
|
Thread.sleep(30000);
|
||||||
|
|
||||||
if (conditionsMetToDisconnect(channel)) {
|
if (conditionsMetToDisconnect(channel)) {
|
||||||
LogManager.getLogger(MusicPlayerAutoDisconnectThread.class).debug("Guild {}: auto-disconnect player from voice channel: {}", guild.getId(), channel.getId());
|
logger.debug("Guild {}: auto-disconnect player from voice channel: {}", guild.getId(), channel.getId());
|
||||||
manager.leave();
|
manager.leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,6 +50,6 @@ public class MusicPlayerAutoDisconnectThread implements Runnable {
|
|||||||
private boolean conditionsMetToDisconnect(VoiceChannel channel) {
|
private boolean conditionsMetToDisconnect(VoiceChannel channel) {
|
||||||
List<Member> members = channel.getMembers().stream().filter(member -> !member.getId().equals(NetNeutrality.getSelf().getId())).toList();
|
List<Member> members = channel.getMembers().stream().filter(member -> !member.getId().equals(NetNeutrality.getSelf().getId())).toList();
|
||||||
|
|
||||||
return members.size() == 0 || manager.getScheduler().getQueueManager().isEmpty();
|
return members.isEmpty() || manager.getScheduler().getQueueManager().isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
|
|||||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||||
import netneutrality.command.AbstractCommand;
|
import netneutrality.command.AbstractCommand;
|
||||||
import netneutrality.command.CommandType;
|
import netneutrality.command.CommandType;
|
||||||
import netneutrality.core.CommandManager;
|
import netneutrality.command.CommandManager;
|
||||||
import netneutrality.core.context.CommandContext;
|
import netneutrality.core.context.CommandContext;
|
||||||
import netneutrality.exceptions.CommandException;
|
import netneutrality.exceptions.CommandException;
|
||||||
import netneutrality.music.MusicManager;
|
import netneutrality.music.MusicManager;
|
||||||
|
|||||||
Reference in new issue
Block a user