make getting note command configurable
This commit is contained in:
@@ -3,6 +3,7 @@ package me.youhavetrouble.noted;
|
||||
import me.youhavetrouble.noted.listener.SlashCommandListener;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.OnlineStatus;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import net.dv8tion.jda.api.interactions.IntegrationType;
|
||||
import net.dv8tion.jda.api.interactions.InteractionContextType;
|
||||
@@ -25,6 +26,7 @@ public class Main {
|
||||
private static String version = "Unknown version";
|
||||
private static Storage storage;
|
||||
private static Long adminId;
|
||||
public static String command;
|
||||
public static JDA jda;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
@@ -51,12 +53,20 @@ public class Main {
|
||||
jda = JDABuilder.createLight(properties.getProperty("DISCORD_TOKEN"), Collections.emptyList())
|
||||
.setCallbackPool(Executors.newVirtualThreadPerTaskExecutor())
|
||||
.setActivity(Activity.customStatus("Notekeeping..."))
|
||||
.setStatus(OnlineStatus.ONLINE)
|
||||
.addEventListeners(new SlashCommandListener())
|
||||
.build();
|
||||
|
||||
jda.awaitReady();
|
||||
|
||||
jda.upsertCommand(Commands.slash("note", "Get a note")
|
||||
command = properties.getProperty("COMMAND", "note");
|
||||
if (command.equals("add-note") || command.equals("edit-note")) {
|
||||
logger.warning("The command name " + command + " is reserved. Please change the command name in noted.properties.");
|
||||
logger.warning("The command name has been changed to 'note'.");
|
||||
command = "note";
|
||||
}
|
||||
|
||||
jda.upsertCommand(Commands.slash(command, "Get a note")
|
||||
.setIntegrationTypes(IntegrationType.GUILD_INSTALL, IntegrationType.USER_INSTALL)
|
||||
.addOptions(
|
||||
new OptionData(OptionType.STRING, "alias", "The ID of the note", true, true),
|
||||
|
||||
@@ -42,28 +42,30 @@ public class SlashCommandListener extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
switch (event.getName()) {
|
||||
case "note" -> {
|
||||
OptionMapping noteIdOption = event.getOption("alias");
|
||||
OptionMapping ephemeralOption = event.getOption("ephemeral");
|
||||
if (noteIdOption == null) {
|
||||
event.reply("Please provide a note alias.")
|
||||
.setEphemeral(true)
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
boolean ephemeral = false;
|
||||
try {
|
||||
ephemeral = ephemeralOption != null && ephemeralOption.getAsBoolean();
|
||||
} catch (IllegalArgumentException e) {
|
||||
event.reply("Invalid value for ephemeral.")
|
||||
.setEphemeral(true)
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
String noteId = noteIdOption.getAsString();
|
||||
getNote(event, noteId, ephemeral);
|
||||
if (Main.command.equals(event.getName())) {
|
||||
OptionMapping noteIdOption = event.getOption("alias");
|
||||
OptionMapping ephemeralOption = event.getOption("ephemeral");
|
||||
if (noteIdOption == null) {
|
||||
event.reply("Please provide a note alias.")
|
||||
.setEphemeral(true)
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
boolean ephemeral = false;
|
||||
try {
|
||||
ephemeral = ephemeralOption != null && ephemeralOption.getAsBoolean();
|
||||
} catch (IllegalArgumentException e) {
|
||||
event.reply("Invalid value for ephemeral.")
|
||||
.setEphemeral(true)
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
String noteId = noteIdOption.getAsString();
|
||||
getNote(event, noteId, ephemeral);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.getName()) {
|
||||
case "add-note" -> {
|
||||
Long adminId = Main.getAdminId();
|
||||
if (adminId == null || !adminId.equals(event.getUser().getIdLong())) {
|
||||
|
||||
Reference in New Issue
Block a user