diff --git a/readme.md b/readme.md index 4d1efcc..e1f090d 100644 --- a/readme.md +++ b/readme.md @@ -13,5 +13,5 @@ All users that have the app installed can use the /note (command name configurab #### Admin Only configured admin user can add notes. To add a note, you need to have your user id specified in the noted.properties -configuration file. You can use add-note command to add a note, edit-note to edit a note, delete-note to delete a note. +configuration file. You can specify multiple user ids separated by `,`. You can use add-note command to add a note, edit-note to edit a note, delete-note to delete a note. Those commands are only available in the direct message channel with the bot. diff --git a/src/main/java/me/youhavetrouble/noted/Main.java b/src/main/java/me/youhavetrouble/noted/Main.java index f2969b6..e10057f 100644 --- a/src/main/java/me/youhavetrouble/noted/Main.java +++ b/src/main/java/me/youhavetrouble/noted/Main.java @@ -6,11 +6,14 @@ 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 org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.*; import java.util.Collections; +import java.util.HashSet; import java.util.Properties; +import java.util.Set; import java.util.concurrent.Executors; import java.util.logging.Logger; @@ -21,7 +24,7 @@ public class Main { private static final Properties properties = new Properties(); private static String version = "Unknown version"; private static Storage storage; - private static Long adminId; + private static final Set adminIds = new HashSet<>(); public static String command; public static JDA jda; @@ -44,7 +47,17 @@ public class Main { logger.info("Starting " + version); - adminId = Long.parseLong(properties.getProperty("ADMIN_USER_ID")); + String adminIdString = properties.getProperty("ADMIN_USER_ID"); + if (adminIdString != null) { + String[] adminIds = adminIdString.split(","); + for (String id : adminIds) { + try { + Main.adminIds.add(Long.parseLong(id)); + } catch (NumberFormatException e) { + logger.warning("Invalid admin user ID: " + id); + } + } + } jda = JDABuilder.createLight(properties.getProperty("DISCORD_TOKEN"), Collections.emptyList()) .setCallbackPool(Executors.newVirtualThreadPerTaskExecutor()) @@ -96,9 +109,9 @@ public class Main { } } - @Nullable - public static Long getAdminId() { - return adminId; + @NotNull + public static Set getAdminIds() { + return adminIds; } public static String getVersion() { diff --git a/src/main/java/me/youhavetrouble/noted/command/Command.java b/src/main/java/me/youhavetrouble/noted/command/Command.java index 983ecb3..f198b84 100644 --- a/src/main/java/me/youhavetrouble/noted/command/Command.java +++ b/src/main/java/me/youhavetrouble/noted/command/Command.java @@ -29,8 +29,7 @@ public abstract class Command extends ListenerAdapter { } boolean canUse(User user) { - Long adminId = Main.getAdminId(); - return adminId != null && adminId.equals(user.getIdLong()); + return Main.getAdminIds().contains(user.getIdLong()); } public static void registerCommand(Command command) {