From e62302e024be9a30a596f85a0a78faf9fcedccc9 Mon Sep 17 00:00:00 2001 From: Vankka Date: Sun, 17 Nov 2024 14:42:12 +0200 Subject: [PATCH] Add server filter to custom commands --- .../discordsrv/common/config/main/CustomCommandConfig.java | 4 ++++ .../common/feature/customcommands/CustomCommandModule.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/common/src/main/java/com/discordsrv/common/config/main/CustomCommandConfig.java b/common/src/main/java/com/discordsrv/common/config/main/CustomCommandConfig.java index 2b39a288..7d51e31f 100644 --- a/common/src/main/java/com/discordsrv/common/config/main/CustomCommandConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/main/CustomCommandConfig.java @@ -64,6 +64,10 @@ public static CustomCommandConfig defaultHelloWorld() { public List options = new ArrayList<>(); + @Comment("The Discord server id to register this command in\n" + + "Use 0 for all Discord servers, or -1 to make the command global") + public long serverId = 0; + @Comment("Only one of the constraints has to be true to allow execution") public List constraints = new ArrayList<>(Collections.singletonList(new ConstraintConfig())); diff --git a/common/src/main/java/com/discordsrv/common/feature/customcommands/CustomCommandModule.java b/common/src/main/java/com/discordsrv/common/feature/customcommands/CustomCommandModule.java index f245b8b3..6eb9c0aa 100644 --- a/common/src/main/java/com/discordsrv/common/feature/customcommands/CustomCommandModule.java +++ b/common/src/main/java/com/discordsrv/common/feature/customcommands/CustomCommandModule.java @@ -101,6 +101,9 @@ public void reload(Consumer resultConsumer) { ); } + commandBuilder.setGuildOnly(config.serverId >= 0); + commandBuilder.setGuildId(config.serverId > 0 ? config.serverId : null); + ExecutionHandler handler = new ExecutionHandler(config); commandBuilder.setEventHandler(handler::accept); DiscordCommand command = commandBuilder.build();