Started work on permission commands and toggling commands on and off within discord.
Changed SubCommand to inherit from SubOption and added SubCommandGroup
This commit is contained in:
parent
3fe33b81dc
commit
86ef41a117
|
|
@ -1,5 +1,6 @@
|
||||||
package com.alttd.commandManager;
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.commands.AddCommand.CommandAdd;
|
||||||
import com.alttd.commandManager.commands.CommandHelp;
|
import com.alttd.commandManager.commands.CommandHelp;
|
||||||
import com.alttd.commandManager.commands.PollCommand.CommandPoll;
|
import com.alttd.commandManager.commands.PollCommand.CommandPoll;
|
||||||
import com.alttd.database.Database;
|
import com.alttd.database.Database;
|
||||||
|
|
@ -29,7 +30,8 @@ public class CommandManager extends ListenerAdapter {
|
||||||
|
|
||||||
public CommandManager(JDA jda) {
|
public CommandManager(JDA jda) {
|
||||||
commands = List.of(new CommandHelp(jda, this),
|
commands = List.of(new CommandHelp(jda, this),
|
||||||
new CommandPoll(jda, this));
|
new CommandPoll(jda, this),
|
||||||
|
new CommandAdd(jda, this));
|
||||||
loadCommands();
|
loadCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,9 +87,10 @@ public class CommandManager extends ListenerAdapter {
|
||||||
|
|
||||||
private void loadCommands() {
|
private void loadCommands() {
|
||||||
String sql = "SELECT * FROM commands";
|
String sql = "SELECT * FROM commands";
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
|
|
@ -100,6 +103,13 @@ public class CommandManager extends ListenerAdapter {
|
||||||
}
|
}
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
Logger.sql(exception);
|
Logger.sql(exception);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (statement != null)
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
Logger.sql(exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,33 @@
|
||||||
package com.alttd.commandManager;
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
|
||||||
public abstract class SubCommand {
|
public abstract class SubCommand extends SubOption{
|
||||||
|
|
||||||
private final DiscordCommand parent;
|
private final SubCommandGroup parentGroup;
|
||||||
|
private final boolean inSubGroup;
|
||||||
|
|
||||||
protected SubCommand(DiscordCommand parent) {
|
protected SubCommand(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
this.parent = parent;
|
super(parent);
|
||||||
|
this.parentGroup = parentGroup;
|
||||||
|
this.inSubGroup = parentGroup != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscordCommand getParent() {
|
public SubCommandGroup getParentGroup() {
|
||||||
return parent;
|
return parentGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getName();
|
public boolean isInSubGroup() {
|
||||||
|
return inSubGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
|
if (isInSubGroup())
|
||||||
|
return getParentGroup().getPermission() + "." + getName();
|
||||||
|
else
|
||||||
return getParent().getPermission() + "." + getName();
|
return getParent().getPermission() + "." + getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void execute(SlashCommandInteractionEvent event);
|
public abstract void suggest(CommandAutoCompleteInteractionEvent event);
|
||||||
|
|
||||||
public abstract String getHelpMessage();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
|
public abstract class SubCommandGroup extends SubOption{
|
||||||
|
protected SubCommandGroup(DiscordCommand parent) {
|
||||||
|
super(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/main/java/com/alttd/commandManager/SubOption.java
Normal file
25
src/main/java/com/alttd/commandManager/SubOption.java
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.alttd.commandManager;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public abstract class SubOption {
|
||||||
|
private final DiscordCommand parent;
|
||||||
|
|
||||||
|
protected SubOption(DiscordCommand parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiscordCommand getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public String getPermission() {
|
||||||
|
return getParent().getPermission() + "." + getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void execute(SlashCommandInteractionEvent event);
|
||||||
|
|
||||||
|
public abstract String getHelpMessage();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.CommandManager;
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubOption;
|
||||||
|
import com.alttd.permissions.PermissionManager;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import com.alttd.util.Util;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
|
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.SubcommandData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class CommandAdd extends DiscordCommand {
|
||||||
|
private final HashMap<String, SubOption> subOptionsMap = new HashMap<>();
|
||||||
|
|
||||||
|
public CommandAdd(JDA jda, CommandManager commandManager) {
|
||||||
|
SlashCommandData slashCommandData = Commands.slash(getName(), "Enable commands and assign permissions")
|
||||||
|
.addSubcommandGroups(
|
||||||
|
new SubcommandGroupData("set", "Set a permission for a user")
|
||||||
|
.addSubcommands(
|
||||||
|
new SubcommandData("user", "Set a permission for a user")
|
||||||
|
.addOption(OptionType.MENTIONABLE, "user", "The user to set the permission for", true)
|
||||||
|
.addOption(OptionType.STRING, "permission", "The permission to set for a user", true, true)
|
||||||
|
.addOption(OptionType.STRING, "state", "To allow or deny the permission (true/false)", true, true),
|
||||||
|
new SubcommandData("group", "Set a permission for a group")
|
||||||
|
.addOption(OptionType.MENTIONABLE, "group", "The group to set the permission for", true)
|
||||||
|
.addOption(OptionType.STRING, "permission", "The permission to set for a group", true, true)
|
||||||
|
.addOption(OptionType.STRING, "state", "To allow or deny the permission (true/false)", true, true)
|
||||||
|
),
|
||||||
|
new SubcommandGroupData("unset", "unset a permission for a user")
|
||||||
|
.addSubcommands(
|
||||||
|
new SubcommandData("user", "Unset a permission for a user")
|
||||||
|
.addOption(OptionType.MENTIONABLE, "user", "The user to unset the permission for", true)
|
||||||
|
.addOption(OptionType.STRING, "permission", "The permission to unset for a user", true, true),
|
||||||
|
new SubcommandData("group", "Unset a permission for a group")
|
||||||
|
.addOption(OptionType.MENTIONABLE, "group", "The group to unset the permission for", true)
|
||||||
|
.addOption(OptionType.STRING, "permission", "The permission to unset for a group", true, true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addSubcommands(
|
||||||
|
new SubcommandData("enable", "Enable a command in a channel")
|
||||||
|
.addOption(OptionType.CHANNEL, "channel", "Channel to enable this command in", true)
|
||||||
|
.addOption(OptionType.STRING, "command", "Name of the command to enable", true, true),
|
||||||
|
new SubcommandData("disable", "Disable a command")
|
||||||
|
.addOption(OptionType.CHANNEL, "channel", "Channel to disable this command in", true)
|
||||||
|
.addOption(OptionType.STRING, "command", "Name of the command to disable", true, true)
|
||||||
|
);
|
||||||
|
slashCommandData.setDefaultEnabled(true);
|
||||||
|
Util.registerSubOptions(subOptionsMap,
|
||||||
|
new SubCommandDisable(commandManager, null, this),
|
||||||
|
new SubCommandEnable(commandManager, null, this));
|
||||||
|
Util.registerCommand(commandManager, jda, slashCommandData, getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "add";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
if (event.getGuild() == null || event.getMember() == null) {
|
||||||
|
event.replyEmbeds(Util.guildOnlyCommand(getName())).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (PermissionManager.getInstance().hasPermission(event.getTextChannel(), event.getIdLong(), Util.getGroupIds(event.getMember()), getPermission())) {
|
||||||
|
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String subcommandName = event.getInteraction().getSubcommandGroup();
|
||||||
|
subcommandName = subcommandName == null ? event.getInteraction().getSubcommandName() : subcommandName;
|
||||||
|
if (subcommandName == null) {
|
||||||
|
Logger.severe("No subcommand found for %", getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubOption subOption = subOptionsMap.get(subcommandName);
|
||||||
|
if (subOption == null) {
|
||||||
|
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
subOption.execute(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.CommandManager;
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandDisable extends SubCommand {
|
||||||
|
|
||||||
|
private final CommandManager commandManager;
|
||||||
|
|
||||||
|
protected SubCommandDisable(CommandManager commandManager, SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
this.commandManager = commandManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "disable";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.CommandManager;
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandEnable extends SubCommand {
|
||||||
|
|
||||||
|
private final CommandManager commandManager;
|
||||||
|
|
||||||
|
protected SubCommandEnable(CommandManager commandManager, SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
this.commandManager = commandManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "enable";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import com.alttd.commandManager.SubOption;
|
||||||
|
import com.alttd.permissions.PermissionManager;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import com.alttd.util.Util;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class SubCommandGroupSet extends SubCommandGroup {
|
||||||
|
|
||||||
|
private final HashMap<String, SubOption> subOptionsMap = new HashMap<>();
|
||||||
|
|
||||||
|
protected SubCommandGroupSet(DiscordCommand parent) {
|
||||||
|
super(parent);
|
||||||
|
Util.registerSubOptions(subOptionsMap,
|
||||||
|
new SubCommandUnsetGroup(this, getParent()),
|
||||||
|
new SubCommandUnsetUser(this, getParent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "set";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
if (PermissionManager.getInstance().hasPermission(event.getTextChannel(), event.getIdLong(), Util.getGroupIds(event.getMember()), getPermission())) {
|
||||||
|
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String subcommandName = event.getInteraction().getSubcommandName();
|
||||||
|
if (subcommandName == null) {
|
||||||
|
Logger.severe("No subcommand found for %", getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubOption subOption = subOptionsMap.get(subcommandName);
|
||||||
|
if (subOption == null) {
|
||||||
|
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
subOption.execute(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import com.alttd.commandManager.SubOption;
|
||||||
|
import com.alttd.permissions.PermissionManager;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import com.alttd.util.Util;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class SubCommandGroupUnset extends SubCommandGroup {
|
||||||
|
|
||||||
|
private final HashMap<String, SubOption> subOptionsMap = new HashMap<>();
|
||||||
|
|
||||||
|
protected SubCommandGroupUnset(DiscordCommand parent) {
|
||||||
|
super(parent);
|
||||||
|
Util.registerSubOptions(subOptionsMap,
|
||||||
|
new SubCommandUnsetGroup(this, getParent()),
|
||||||
|
new SubCommandUnsetUser(this, getParent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "unset";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
if (PermissionManager.getInstance().hasPermission(event.getTextChannel(), event.getIdLong(), Util.getGroupIds(event.getMember()), getPermission())) {
|
||||||
|
event.replyEmbeds(Util.noPermission(getName())).setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String subcommandName = event.getInteraction().getSubcommandName();
|
||||||
|
if (subcommandName == null) {
|
||||||
|
Logger.severe("No subcommand found for %", getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubOption subOption = subOptionsMap.get(subcommandName);
|
||||||
|
if (subOption == null) {
|
||||||
|
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
subOption.execute(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandSetGroup extends SubCommand {
|
||||||
|
|
||||||
|
protected SubCommandSetGroup(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "group";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandSetUser extends SubCommand {
|
||||||
|
|
||||||
|
protected SubCommandSetUser(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "user";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandUnsetGroup extends SubCommand {
|
||||||
|
|
||||||
|
protected SubCommandUnsetGroup(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "group";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.commandManager.commands.AddCommand;
|
||||||
|
|
||||||
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
|
public class SubCommandUnsetUser extends SubCommand {
|
||||||
|
|
||||||
|
protected SubCommandUnsetUser(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
|
super(parentGroup, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "user";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(SlashCommandInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
import com.alttd.commandManager.CommandManager;
|
import com.alttd.commandManager.CommandManager;
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubOption;
|
||||||
import com.alttd.permissions.PermissionManager;
|
import com.alttd.permissions.PermissionManager;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import com.alttd.util.Util;
|
import com.alttd.util.Util;
|
||||||
|
|
@ -18,7 +19,7 @@ import java.util.HashMap;
|
||||||
|
|
||||||
public class CommandPoll extends DiscordCommand {
|
public class CommandPoll extends DiscordCommand {
|
||||||
|
|
||||||
private final HashMap<String, SubCommand> subCommandMap = new HashMap<>();
|
private final HashMap<String, SubOption> subOptionsMap = new HashMap<>();
|
||||||
|
|
||||||
public CommandPoll(JDA jda, CommandManager commandManager) {
|
public CommandPoll(JDA jda, CommandManager commandManager) {
|
||||||
SlashCommandData slashCommandData = Commands.slash(getName(), "Create, edit, and manage polls")
|
SlashCommandData slashCommandData = Commands.slash(getName(), "Create, edit, and manage polls")
|
||||||
|
|
@ -53,15 +54,15 @@ public class CommandPoll extends DiscordCommand {
|
||||||
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true)
|
.addOption(OptionType.CHANNEL, "channel", "Channel this poll is in", true)
|
||||||
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you want the results for", true));
|
.addOption(OptionType.INTEGER, "message_id", "Id of the poll you want the results for", true));
|
||||||
slashCommandData.setDefaultEnabled(true);
|
slashCommandData.setDefaultEnabled(true);
|
||||||
Util.registerSubcommands(subCommandMap,
|
Util.registerSubOptions(subOptionsMap,
|
||||||
new SubCommandAdd(this),
|
new SubCommandAdd(null,this),
|
||||||
new SubCommandAddButton(this),
|
new SubCommandAddButton(null, this),
|
||||||
new SubCommandClose(this),
|
new SubCommandClose(null,this),
|
||||||
new SubCommandEditDescription(this),
|
new SubCommandEditDescription(null, this),
|
||||||
new SubCommandEditTitle(this),
|
new SubCommandEditTitle(null, this),
|
||||||
new SubCommandOpen(this),
|
new SubCommandOpen(null, this),
|
||||||
new SubCommandRemoveButton(this),
|
new SubCommandRemoveButton(null, this),
|
||||||
new SubCommandResults(this));
|
new SubCommandResults(null,this));
|
||||||
Util.registerCommand(commandManager, jda, slashCommandData, getName());
|
Util.registerCommand(commandManager, jda, slashCommandData, getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,21 +82,22 @@ public class CommandPoll extends DiscordCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String subcommandName = event.getInteraction().getSubcommandName();
|
String subcommandName = event.getInteraction().getSubcommandGroup();
|
||||||
|
subcommandName = subcommandName == null ? event.getInteraction().getSubcommandName() : subcommandName;
|
||||||
if (subcommandName == null) {
|
if (subcommandName == null) {
|
||||||
Logger.severe("No subcommand found for %", getName());
|
Logger.severe("No subcommand found for %", getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubCommand subCommand = subCommandMap.get(subcommandName);
|
SubOption subOption = subOptionsMap.get(subcommandName);
|
||||||
if (subCommand == null) {
|
if (subOption == null) {
|
||||||
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
event.replyEmbeds(Util.invalidSubcommand(subcommandName))
|
||||||
.setEphemeral(true)
|
.setEphemeral(true)
|
||||||
.queue();
|
.queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
subCommand.execute(event);
|
subOption.execute(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.config.MessagesConfig;
|
import com.alttd.config.MessagesConfig;
|
||||||
import com.alttd.templates.Parser;
|
import com.alttd.templates.Parser;
|
||||||
import com.alttd.templates.Template;
|
import com.alttd.templates.Template;
|
||||||
|
|
@ -10,6 +11,7 @@ import com.alttd.util.OptionMappingParsing;
|
||||||
import com.alttd.util.Util;
|
import com.alttd.util.Util;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
|
|
||||||
|
|
@ -17,8 +19,8 @@ import java.awt.*;
|
||||||
|
|
||||||
public class SubCommandAdd extends SubCommand {
|
public class SubCommandAdd extends SubCommand {
|
||||||
|
|
||||||
protected SubCommandAdd(DiscordCommand parent) {
|
protected SubCommandAdd(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -57,6 +59,11 @@ public class SubCommandAdd extends SubCommand {
|
||||||
.queue(result -> createPoll(channel, title, result));
|
.queue(result -> createPoll(channel, title, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void createPoll(GuildMessageChannel channel, String title, InteractionHook hook) {
|
private void createPoll(GuildMessageChannel channel, String title, InteractionHook hook) {
|
||||||
channel.sendMessageEmbeds(new EmbedBuilder()
|
channel.sendMessageEmbeds(new EmbedBuilder()
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.templates.Parser;
|
import com.alttd.templates.Parser;
|
||||||
import com.alttd.templates.Template;
|
import com.alttd.templates.Template;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
|
|
@ -12,12 +13,13 @@ import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
|
|
||||||
public class SubCommandAddButton extends SubCommand {
|
public class SubCommandAddButton extends SubCommand {
|
||||||
protected SubCommandAddButton(DiscordCommand parent) {
|
protected SubCommandAddButton(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -77,6 +79,11 @@ public class SubCommandAddButton extends SubCommand {
|
||||||
throwable -> failedToGetMessage(throwable, hook)));
|
throwable -> failedToGetMessage(throwable, hook)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void failedToGetMessage(Throwable throwable, InteractionHook hook) {
|
private void failedToGetMessage(Throwable throwable, InteractionHook hook) {
|
||||||
Logger.warning(throwable.getMessage());
|
Logger.warning(throwable.getMessage());
|
||||||
hook.editOriginalEmbeds(Util.genericErrorEmbed("Failed to get poll message",
|
hook.editOriginalEmbeds(Util.genericErrorEmbed("Failed to get poll message",
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandClose extends SubCommand {
|
public class SubCommandClose extends SubCommand {
|
||||||
protected SubCommandClose(DiscordCommand parent) {
|
protected SubCommandClose(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -26,6 +28,11 @@ public class SubCommandClose extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,19 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import com.alttd.util.Util;
|
import com.alttd.util.Util;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||||
|
|
||||||
public class SubCommandEditDescription extends SubCommand {
|
public class SubCommandEditDescription extends SubCommand {
|
||||||
protected SubCommandEditDescription(DiscordCommand parent) {
|
protected SubCommandEditDescription(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -33,6 +35,11 @@ public class SubCommandEditDescription extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//Copied over while working on add button
|
//Copied over while working on add button
|
||||||
private void updatePoll(GuildMessageChannel channel, int rowId, String buttonName, Message message,
|
private void updatePoll(GuildMessageChannel channel, int rowId, String buttonName, Message message,
|
||||||
InteractionHook hook) {
|
InteractionHook hook) {
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandEditTitle extends SubCommand {
|
public class SubCommandEditTitle extends SubCommand {
|
||||||
protected SubCommandEditTitle(DiscordCommand parent) {
|
protected SubCommandEditTitle(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -29,6 +31,11 @@ public class SubCommandEditTitle extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandOpen extends SubCommand {
|
public class SubCommandOpen extends SubCommand {
|
||||||
protected SubCommandOpen(DiscordCommand parent) {
|
protected SubCommandOpen(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -26,6 +28,11 @@ public class SubCommandOpen extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandRemoveButton extends SubCommand {
|
public class SubCommandRemoveButton extends SubCommand {
|
||||||
protected SubCommandRemoveButton(DiscordCommand parent) {
|
protected SubCommandRemoveButton(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -29,6 +31,11 @@ public class SubCommandRemoveButton extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@ package com.alttd.commandManager.commands.PollCommand;
|
||||||
|
|
||||||
import com.alttd.commandManager.DiscordCommand;
|
import com.alttd.commandManager.DiscordCommand;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubCommand;
|
||||||
|
import com.alttd.commandManager.SubCommandGroup;
|
||||||
import com.alttd.util.OptionMappingParsing;
|
import com.alttd.util.OptionMappingParsing;
|
||||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
|
||||||
public class SubCommandResults extends SubCommand {
|
public class SubCommandResults extends SubCommand {
|
||||||
protected SubCommandResults(DiscordCommand parent) {
|
protected SubCommandResults(SubCommandGroup parentGroup, DiscordCommand parent) {
|
||||||
super(parent);
|
super(parentGroup, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -26,6 +28,11 @@ public class SubCommandResults extends SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suggest(CommandAutoCompleteInteractionEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpMessage() {
|
public String getHelpMessage() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,22 @@ public class DatabaseTables {
|
||||||
"active BIT DEFAULT b'0', " +
|
"active BIT DEFAULT b'0', " +
|
||||||
"poll_title VARCHAR(256) NOT NULL, " +
|
"poll_title VARCHAR(256) NOT NULL, " +
|
||||||
"embed_type VARCHAR(32) DEFAULT 'ABSTRACT_EMBED', " +
|
"embed_type VARCHAR(32) DEFAULT 'ABSTRACT_EMBED', " +
|
||||||
"PRIMARY KEY (UUID, villager_type)" +
|
"PRIMARY KEY (poll_id)" +
|
||||||
|
")";
|
||||||
|
connection.prepareStatement(sql).executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.sql(e);
|
||||||
|
Logger.severe("Unable to create polls table, shutting down...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createCommandsTable() {
|
||||||
|
try {
|
||||||
|
String sql = "CREATE TABLE IF NOT EXISTS commands(" +
|
||||||
|
"command_name VARCHAR(64) NOT NULL, " +
|
||||||
|
"scope VARCHAR(16) NOT NULL, " +
|
||||||
|
"location_id BIGINT NOT NULL, " +
|
||||||
|
"PRIMARY KEY (command_name, scope, location_id)" +
|
||||||
")";
|
")";
|
||||||
connection.prepareStatement(sql).executeUpdate();
|
connection.prepareStatement(sql).executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,15 @@ public class PermissionManager {
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a user has a certain permission and if that permission is enabled in the specified channel
|
||||||
|
*
|
||||||
|
* @param textChannel Text channel command was executed in
|
||||||
|
* @param member Member to check permission for
|
||||||
|
* @param permission Permission to check for
|
||||||
|
*
|
||||||
|
* @return True if the member has permission or is owner, false if not
|
||||||
|
*/
|
||||||
public boolean hasPermission(TextChannel textChannel, Member member, String permission) {
|
public boolean hasPermission(TextChannel textChannel, Member member, String permission) {
|
||||||
return hasPermission(textChannel,
|
return hasPermission(textChannel,
|
||||||
member.getIdLong(),
|
member.getIdLong(),
|
||||||
|
|
@ -34,12 +43,24 @@ public class PermissionManager {
|
||||||
permission);
|
permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a user has a certain permission and if that permission is enabled in the specified channel
|
||||||
|
*
|
||||||
|
* @param textChannel Text channel command was executed in
|
||||||
|
* @param userId ID of the user to check for
|
||||||
|
* @param groupIds List of group id's a user has (can be null or empty)
|
||||||
|
* @param permission Permission to check for
|
||||||
|
*
|
||||||
|
* @return True if the user has permission or is owner, false if not
|
||||||
|
*/
|
||||||
public boolean hasPermission(TextChannel textChannel, long userId, List<Long> groupIds, String permission) {
|
public boolean hasPermission(TextChannel textChannel, long userId, List<Long> groupIds, String permission) {
|
||||||
permission = permission.toLowerCase();
|
permission = permission.toLowerCase();
|
||||||
if (textChannel instanceof PrivateChannel) {
|
if (textChannel instanceof PrivateChannel) {
|
||||||
if (isDisabled(privateEnabledCommands, permission))
|
if (isDisabled(privateEnabledCommands, permission))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
if (textChannel.getGuild().getOwnerIdLong() == userId)
|
||||||
|
return true;
|
||||||
if (isDisabled(channelEnabledCommands.get(textChannel.getIdLong()), permission.toLowerCase()))
|
if (isDisabled(channelEnabledCommands.get(textChannel.getIdLong()), permission.toLowerCase()))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -70,6 +91,11 @@ public class PermissionManager {
|
||||||
return permissions.contains(permission);
|
return permissions.contains(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the permission manager instance
|
||||||
|
*
|
||||||
|
* @return Permission manager instance
|
||||||
|
*/
|
||||||
public static PermissionManager getInstance() {
|
public static PermissionManager getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.alttd.util;
|
||||||
|
|
||||||
import com.alttd.commandManager.CommandManager;
|
import com.alttd.commandManager.CommandManager;
|
||||||
import com.alttd.commandManager.ScopeInfo;
|
import com.alttd.commandManager.ScopeInfo;
|
||||||
import com.alttd.commandManager.SubCommand;
|
import com.alttd.commandManager.SubOption;
|
||||||
import com.alttd.config.MessagesConfig;
|
import com.alttd.config.MessagesConfig;
|
||||||
import com.alttd.templates.Parser;
|
import com.alttd.templates.Parser;
|
||||||
import com.alttd.templates.Template;
|
import com.alttd.templates.Template;
|
||||||
|
|
@ -114,9 +114,9 @@ public class Util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerSubcommands(HashMap<String, SubCommand> subCommandMap, SubCommand... subCommands) {
|
public static void registerSubOptions(HashMap<String, SubOption> subCommandMap, SubOption... subOptions) {
|
||||||
for (SubCommand subCommand : subCommands)
|
for (SubOption subOption : subOptions)
|
||||||
subCommandMap.put(subCommand.getName(), subCommand);
|
subCommandMap.put(subOption.getName(), subOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean validateGuildMessageChannel(SlashCommandInteraction interaction, GuildMessageChannel channel, ChannelType channelType, @NotNull Member member) {
|
public static boolean validateGuildMessageChannel(SlashCommandInteraction interaction, GuildMessageChannel channel, ChannelType channelType, @NotNull Member member) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user