mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-01 08:39:31 +01:00
Clarify config comments for threads and command execution filters, rename filters to execution conditions
This commit is contained in:
parent
1d5a5381a0
commit
91f9f36e63
@ -10,7 +10,7 @@ import com.discordsrv.api.discord.events.interaction.command.DiscordCommandAutoC
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.command.game.GameCommandExecutionHelper;
|
||||
import com.discordsrv.common.config.main.DiscordCommandConfig;
|
||||
import com.discordsrv.common.config.main.generic.GameCommandFilterConfig;
|
||||
import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionConfig;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.logging.NamedLogger;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
@ -59,7 +59,7 @@ public class ExecuteCommand implements Consumer<DiscordChatInputInteractionEvent
|
||||
public boolean isNotAcceptableCommand(DiscordGuildMember member, DiscordUser user, String command, boolean suggestions) {
|
||||
DiscordCommandConfig.ExecuteConfig config = discordSRV.config().discordCommand.execute;
|
||||
|
||||
for (GameCommandFilterConfig filter : config.filters) {
|
||||
for (GameCommandExecutionConditionConfig filter : config.executionConditions) {
|
||||
if (!filter.isAcceptableCommand(member, user, command, suggestions, helper)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.discordsrv.common.config.main;
|
||||
|
||||
import com.discordsrv.common.config.main.generic.DestinationConfig;
|
||||
import com.discordsrv.common.config.main.generic.GameCommandFilterConfig;
|
||||
import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionConfig;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
@ -67,15 +67,15 @@ public class ConsoleConfig {
|
||||
public static class Execution {
|
||||
|
||||
public Execution() {
|
||||
filters.add(
|
||||
new GameCommandFilterConfig(
|
||||
executionConditions.add(
|
||||
new GameCommandExecutionConditionConfig(
|
||||
new ArrayList<>(),
|
||||
false,
|
||||
new ArrayList<>(Arrays.asList("list", "whitelist"))
|
||||
)
|
||||
);
|
||||
filters.add(
|
||||
new GameCommandFilterConfig(
|
||||
executionConditions.add(
|
||||
new GameCommandExecutionConditionConfig(
|
||||
new ArrayList<>(),
|
||||
true,
|
||||
new ArrayList<>(Arrays.asList(
|
||||
@ -92,7 +92,7 @@ public class ConsoleConfig {
|
||||
public boolean enabled = true;
|
||||
|
||||
@Comment("At least one condition has to match to allow execution")
|
||||
public List<GameCommandFilterConfig> filters = new ArrayList<>();
|
||||
public List<GameCommandExecutionConditionConfig> executionConditions = new ArrayList<>();
|
||||
|
||||
@Comment("If a command is inputted starting with /, a warning response will be given if this is enabled")
|
||||
public boolean enableSlashWarning = true;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.discordsrv.common.config.main;
|
||||
|
||||
import com.discordsrv.common.config.configurate.annotation.Constants;
|
||||
import com.discordsrv.common.config.main.generic.GameCommandFilterConfig;
|
||||
import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionConfig;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
@ -18,8 +18,8 @@ public class DiscordCommandConfig {
|
||||
public static class ExecuteConfig {
|
||||
|
||||
public ExecuteConfig() {
|
||||
filters.add(
|
||||
new GameCommandFilterConfig(
|
||||
executionConditions.add(
|
||||
new GameCommandExecutionConditionConfig(
|
||||
new ArrayList<>(),
|
||||
false,
|
||||
new ArrayList<>(Arrays.asList("say", "/gamemode(?: (?:survival|spectator)(?: .+)?)?/"))
|
||||
@ -42,7 +42,7 @@ public class DiscordCommandConfig {
|
||||
public OutputMode outputMode = OutputMode.MARKDOWN;
|
||||
|
||||
@Comment("At least one condition has to match to allow execution")
|
||||
public List<GameCommandFilterConfig> filters = new ArrayList<>();
|
||||
public List<GameCommandExecutionConditionConfig> executionConditions = new ArrayList<>();
|
||||
|
||||
@Comment("If commands should be suggested while typing\n" +
|
||||
"Suggestions go through the server's main thread (on servers with a main thread) to ensure compatability.")
|
||||
|
@ -12,17 +12,18 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ConfigSerializable
|
||||
public class GameCommandFilterConfig {
|
||||
public class GameCommandExecutionConditionConfig {
|
||||
|
||||
public GameCommandFilterConfig() {}
|
||||
@SuppressWarnings("unused") // Configurate
|
||||
public GameCommandExecutionConditionConfig() {}
|
||||
|
||||
public GameCommandFilterConfig(List<Long> roleAndUserIds, boolean blacklist, List<String> commands) {
|
||||
public GameCommandExecutionConditionConfig(List<Long> roleAndUserIds, boolean blacklist, List<String> commands) {
|
||||
this.roleAndUserIds = roleAndUserIds;
|
||||
this.blacklist = blacklist;
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
@Comment("The role and user ids which this filter applies to")
|
||||
@Comment("The role and user ids that should be allowed to run the commands specified in this condition")
|
||||
public List<Long> roleAndUserIds = new ArrayList<>();
|
||||
|
||||
@Comment("true for blacklist (blocking commands), false for whitelist (allowing commands)")
|
@ -19,10 +19,12 @@
|
||||
package com.discordsrv.common.config.main.generic;
|
||||
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
@ConfigSerializable
|
||||
public class ThreadConfig {
|
||||
|
||||
@Comment("Specify the text or forum channel id and the name of the thread (the thread will be automatically created if it doesn't exist)")
|
||||
public Long channelId = 0L;
|
||||
|
||||
public String threadName = "Minecraft Server chat bridge";
|
||||
|
@ -16,7 +16,7 @@ import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.command.game.GameCommandExecutionHelper;
|
||||
import com.discordsrv.common.config.main.ConsoleConfig;
|
||||
import com.discordsrv.common.config.main.generic.DestinationConfig;
|
||||
import com.discordsrv.common.config.main.generic.GameCommandFilterConfig;
|
||||
import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionConfig;
|
||||
import com.discordsrv.common.console.entry.LogEntry;
|
||||
import com.discordsrv.common.console.entry.LogMessage;
|
||||
import com.discordsrv.common.console.message.ConsoleMessage;
|
||||
@ -133,7 +133,7 @@ public class SingleConsoleHandler {
|
||||
}
|
||||
|
||||
boolean pass = false;
|
||||
for (GameCommandFilterConfig filter : config.commandExecution.filters) {
|
||||
for (GameCommandExecutionConditionConfig filter : config.commandExecution.executionConditions) {
|
||||
if (filter.isAcceptableCommand(member, user, command, false, helper)) {
|
||||
pass = true;
|
||||
break;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.discordsrv.common.command.game;
|
||||
|
||||
import com.discordsrv.common.config.main.generic.GameCommandFilterConfig;
|
||||
import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionConfig;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -15,67 +15,72 @@ public class GameCommandFilterTest {
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test", "test", false, helper));
|
||||
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("test", "test", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("test", "tester", false, helper));
|
||||
Assertions.assertFalse(GameCommandExecutionConditionConfig.isCommandMatch("test", "tester", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void argumentTest() {
|
||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test arg", "test arg", false, helper));
|
||||
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test arg", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suggestTest() {
|
||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test arg", "test", true, helper));
|
||||
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test", true, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extraTest() {
|
||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test arg", "test arg extra arguments after that", false, helper));
|
||||
Assertions.assertTrue(
|
||||
GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test arg extra arguments after that", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void argumentOverflowTest1() {
|
||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("test arg", "test argument", false, helper));
|
||||
Assertions.assertFalse(
|
||||
GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test argument", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameCommandTest1() {
|
||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("plugin1:test", "test", false, helper));
|
||||
Assertions.assertFalse(GameCommandExecutionConditionConfig.isCommandMatch("plugin1:test", "test", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameCommandTest2() {
|
||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("plugin2:test", "test", false, helper));
|
||||
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("plugin2:test", "test", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regexTest1() {
|
||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("/test/", "test", false, helper));
|
||||
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("/test/", "test", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regexTest2() {
|
||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("/test/", "test extra", false, helper));
|
||||
Assertions.assertFalse(GameCommandExecutionConditionConfig.isCommandMatch("/test/", "test extra", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regexTest3() {
|
||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("/test( argument)?/", "test argument", false, helper));
|
||||
Assertions.assertTrue(
|
||||
GameCommandExecutionConditionConfig.isCommandMatch("/test( argument)?/", "test argument", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regexTest4() {
|
||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("/test( argument)?/", "test fail", false, helper));
|
||||
Assertions.assertFalse(
|
||||
GameCommandExecutionConditionConfig.isCommandMatch("/test( argument)?/", "test fail", false, helper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regexTest5() {
|
||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("/test( argument)?/", "test", true, helper));
|
||||
Assertions.assertTrue(
|
||||
GameCommandExecutionConditionConfig.isCommandMatch("/test( argument)?/", "test", true, helper));
|
||||
}
|
||||
|
||||
public static class ExecutionHelper implements GameCommandExecutionHelper {
|
||||
|
Loading…
Reference in New Issue
Block a user