allow multiple admin users
This commit is contained in:
@@ -13,5 +13,5 @@ All users that have the app installed can use the /note (command name configurab
|
|||||||
|
|
||||||
#### Admin
|
#### Admin
|
||||||
Only configured admin user can add notes. To add a note, you need to have your user id specified in the noted.properties
|
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.
|
Those commands are only available in the direct message channel with the bot.
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ 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.OnlineStatus;
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -21,7 +24,7 @@ public class Main {
|
|||||||
private static final Properties properties = new Properties();
|
private static final Properties properties = new Properties();
|
||||||
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 final Set<Long> adminIds = new HashSet<>();
|
||||||
public static String command;
|
public static String command;
|
||||||
public static JDA jda;
|
public static JDA jda;
|
||||||
|
|
||||||
@@ -44,7 +47,17 @@ public class Main {
|
|||||||
|
|
||||||
logger.info("Starting " + version);
|
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())
|
jda = JDABuilder.createLight(properties.getProperty("DISCORD_TOKEN"), Collections.emptyList())
|
||||||
.setCallbackPool(Executors.newVirtualThreadPerTaskExecutor())
|
.setCallbackPool(Executors.newVirtualThreadPerTaskExecutor())
|
||||||
@@ -96,9 +109,9 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NotNull
|
||||||
public static Long getAdminId() {
|
public static Set<Long> getAdminIds() {
|
||||||
return adminId;
|
return adminIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVersion() {
|
public static String getVersion() {
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ public abstract class Command extends ListenerAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean canUse(User user) {
|
boolean canUse(User user) {
|
||||||
Long adminId = Main.getAdminId();
|
return Main.getAdminIds().contains(user.getIdLong());
|
||||||
return adminId != null && adminId.equals(user.getIdLong());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerCommand(Command command) {
|
public static void registerCommand(Command command) {
|
||||||
|
|||||||
Reference in New Issue
Block a user