make getting note command configurable

This commit is contained in:
2024-08-09 21:50:00 +02:00
parent a3b0efa74b
commit ee694c088f
3 changed files with 35 additions and 22 deletions
@@ -3,6 +3,7 @@ package me.youhavetrouble.noted;
import me.youhavetrouble.noted.listener.SlashCommandListener; import me.youhavetrouble.noted.listener.SlashCommandListener;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.interactions.IntegrationType; import net.dv8tion.jda.api.interactions.IntegrationType;
import net.dv8tion.jda.api.interactions.InteractionContextType; import net.dv8tion.jda.api.interactions.InteractionContextType;
@@ -25,6 +26,7 @@ public class Main {
private static String version = "Unknown version"; private static String version = "Unknown version";
private static Storage storage; private static Storage storage;
private static Long adminId; private static Long adminId;
public static String command;
public static JDA jda; public static JDA jda;
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
@@ -51,12 +53,20 @@ public class Main {
jda = JDABuilder.createLight(properties.getProperty("DISCORD_TOKEN"), Collections.emptyList()) jda = JDABuilder.createLight(properties.getProperty("DISCORD_TOKEN"), Collections.emptyList())
.setCallbackPool(Executors.newVirtualThreadPerTaskExecutor()) .setCallbackPool(Executors.newVirtualThreadPerTaskExecutor())
.setActivity(Activity.customStatus("Notekeeping...")) .setActivity(Activity.customStatus("Notekeeping..."))
.setStatus(OnlineStatus.ONLINE)
.addEventListeners(new SlashCommandListener()) .addEventListeners(new SlashCommandListener())
.build(); .build();
jda.awaitReady(); 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) .setIntegrationTypes(IntegrationType.GUILD_INSTALL, IntegrationType.USER_INSTALL)
.addOptions( .addOptions(
new OptionData(OptionType.STRING, "alias", "The ID of the note", true, true), new OptionData(OptionType.STRING, "alias", "The ID of the note", true, true),
@@ -42,8 +42,7 @@ public class SlashCommandListener extends ListenerAdapter {
@Override @Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
switch (event.getName()) { if (Main.command.equals(event.getName())) {
case "note" -> {
OptionMapping noteIdOption = event.getOption("alias"); OptionMapping noteIdOption = event.getOption("alias");
OptionMapping ephemeralOption = event.getOption("ephemeral"); OptionMapping ephemeralOption = event.getOption("ephemeral");
if (noteIdOption == null) { if (noteIdOption == null) {
@@ -63,7 +62,10 @@ public class SlashCommandListener extends ListenerAdapter {
} }
String noteId = noteIdOption.getAsString(); String noteId = noteIdOption.getAsString();
getNote(event, noteId, ephemeral); getNote(event, noteId, ephemeral);
return;
} }
switch (event.getName()) {
case "add-note" -> { case "add-note" -> {
Long adminId = Main.getAdminId(); Long adminId = Main.getAdminId();
if (adminId == null || !adminId.equals(event.getUser().getIdLong())) { if (adminId == null || !adminId.equals(event.getUser().getIdLong())) {
+1
View File
@@ -1,2 +1,3 @@
DISCORD_TOKEN=your_bot_token_here DISCORD_TOKEN=your_bot_token_here
ADMIN_USER_ID=your_user_id_here ADMIN_USER_ID=your_user_id_here
COMMAND=note