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.DiscordSRV;
|
||||||
import com.discordsrv.common.command.game.GameCommandExecutionHelper;
|
import com.discordsrv.common.command.game.GameCommandExecutionHelper;
|
||||||
import com.discordsrv.common.config.main.DiscordCommandConfig;
|
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.Logger;
|
||||||
import com.discordsrv.common.logging.NamedLogger;
|
import com.discordsrv.common.logging.NamedLogger;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
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) {
|
public boolean isNotAcceptableCommand(DiscordGuildMember member, DiscordUser user, String command, boolean suggestions) {
|
||||||
DiscordCommandConfig.ExecuteConfig config = discordSRV.config().discordCommand.execute;
|
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)) {
|
if (!filter.isAcceptableCommand(member, user, command, suggestions, helper)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.discordsrv.common.config.main;
|
package com.discordsrv.common.config.main;
|
||||||
|
|
||||||
import com.discordsrv.common.config.main.generic.DestinationConfig;
|
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.ConfigSerializable;
|
||||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||||
|
|
||||||
@ -67,15 +67,15 @@ public class ConsoleConfig {
|
|||||||
public static class Execution {
|
public static class Execution {
|
||||||
|
|
||||||
public Execution() {
|
public Execution() {
|
||||||
filters.add(
|
executionConditions.add(
|
||||||
new GameCommandFilterConfig(
|
new GameCommandExecutionConditionConfig(
|
||||||
new ArrayList<>(),
|
new ArrayList<>(),
|
||||||
false,
|
false,
|
||||||
new ArrayList<>(Arrays.asList("list", "whitelist"))
|
new ArrayList<>(Arrays.asList("list", "whitelist"))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
filters.add(
|
executionConditions.add(
|
||||||
new GameCommandFilterConfig(
|
new GameCommandExecutionConditionConfig(
|
||||||
new ArrayList<>(),
|
new ArrayList<>(),
|
||||||
true,
|
true,
|
||||||
new ArrayList<>(Arrays.asList(
|
new ArrayList<>(Arrays.asList(
|
||||||
@ -92,7 +92,7 @@ public class ConsoleConfig {
|
|||||||
public boolean enabled = true;
|
public boolean enabled = true;
|
||||||
|
|
||||||
@Comment("At least one condition has to match to allow execution")
|
@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")
|
@Comment("If a command is inputted starting with /, a warning response will be given if this is enabled")
|
||||||
public boolean enableSlashWarning = true;
|
public boolean enableSlashWarning = true;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.discordsrv.common.config.main;
|
package com.discordsrv.common.config.main;
|
||||||
|
|
||||||
import com.discordsrv.common.config.configurate.annotation.Constants;
|
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.ConfigSerializable;
|
||||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||||
|
|
||||||
@ -18,8 +18,8 @@ public class DiscordCommandConfig {
|
|||||||
public static class ExecuteConfig {
|
public static class ExecuteConfig {
|
||||||
|
|
||||||
public ExecuteConfig() {
|
public ExecuteConfig() {
|
||||||
filters.add(
|
executionConditions.add(
|
||||||
new GameCommandFilterConfig(
|
new GameCommandExecutionConditionConfig(
|
||||||
new ArrayList<>(),
|
new ArrayList<>(),
|
||||||
false,
|
false,
|
||||||
new ArrayList<>(Arrays.asList("say", "/gamemode(?: (?:survival|spectator)(?: .+)?)?/"))
|
new ArrayList<>(Arrays.asList("say", "/gamemode(?: (?:survival|spectator)(?: .+)?)?/"))
|
||||||
@ -42,7 +42,7 @@ public class DiscordCommandConfig {
|
|||||||
public OutputMode outputMode = OutputMode.MARKDOWN;
|
public OutputMode outputMode = OutputMode.MARKDOWN;
|
||||||
|
|
||||||
@Comment("At least one condition has to match to allow execution")
|
@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" +
|
@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.")
|
"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;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ConfigSerializable
|
@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.roleAndUserIds = roleAndUserIds;
|
||||||
this.blacklist = blacklist;
|
this.blacklist = blacklist;
|
||||||
this.commands = commands;
|
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<>();
|
public List<Long> roleAndUserIds = new ArrayList<>();
|
||||||
|
|
||||||
@Comment("true for blacklist (blocking commands), false for whitelist (allowing commands)")
|
@Comment("true for blacklist (blocking commands), false for whitelist (allowing commands)")
|
@ -19,10 +19,12 @@
|
|||||||
package com.discordsrv.common.config.main.generic;
|
package com.discordsrv.common.config.main.generic;
|
||||||
|
|
||||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||||
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class ThreadConfig {
|
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 Long channelId = 0L;
|
||||||
|
|
||||||
public String threadName = "Minecraft Server chat bridge";
|
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.command.game.GameCommandExecutionHelper;
|
||||||
import com.discordsrv.common.config.main.ConsoleConfig;
|
import com.discordsrv.common.config.main.ConsoleConfig;
|
||||||
import com.discordsrv.common.config.main.generic.DestinationConfig;
|
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.LogEntry;
|
||||||
import com.discordsrv.common.console.entry.LogMessage;
|
import com.discordsrv.common.console.entry.LogMessage;
|
||||||
import com.discordsrv.common.console.message.ConsoleMessage;
|
import com.discordsrv.common.console.message.ConsoleMessage;
|
||||||
@ -133,7 +133,7 @@ public class SingleConsoleHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean pass = false;
|
boolean pass = false;
|
||||||
for (GameCommandFilterConfig filter : config.commandExecution.filters) {
|
for (GameCommandExecutionConditionConfig filter : config.commandExecution.executionConditions) {
|
||||||
if (filter.isAcceptableCommand(member, user, command, false, helper)) {
|
if (filter.isAcceptableCommand(member, user, command, false, helper)) {
|
||||||
pass = true;
|
pass = true;
|
||||||
break;
|
break;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.discordsrv.common.command.game;
|
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.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -15,67 +15,72 @@ public class GameCommandFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test1() {
|
public void test1() {
|
||||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test", "test", false, helper));
|
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("test", "test", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test2() {
|
public void test2() {
|
||||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("test", "tester", false, helper));
|
Assertions.assertFalse(GameCommandExecutionConditionConfig.isCommandMatch("test", "tester", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void argumentTest() {
|
public void argumentTest() {
|
||||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test arg", "test arg", false, helper));
|
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test arg", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void suggestTest() {
|
public void suggestTest() {
|
||||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test arg", "test", true, helper));
|
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test", true, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extraTest() {
|
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
|
@Test
|
||||||
public void argumentOverflowTest1() {
|
public void argumentOverflowTest1() {
|
||||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("test arg", "test argument", false, helper));
|
Assertions.assertFalse(
|
||||||
|
GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test argument", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sameCommandTest1() {
|
public void sameCommandTest1() {
|
||||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("plugin1:test", "test", false, helper));
|
Assertions.assertFalse(GameCommandExecutionConditionConfig.isCommandMatch("plugin1:test", "test", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sameCommandTest2() {
|
public void sameCommandTest2() {
|
||||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("plugin2:test", "test", false, helper));
|
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("plugin2:test", "test", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void regexTest1() {
|
public void regexTest1() {
|
||||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("/test/", "test", false, helper));
|
Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("/test/", "test", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void regexTest2() {
|
public void regexTest2() {
|
||||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("/test/", "test extra", false, helper));
|
Assertions.assertFalse(GameCommandExecutionConditionConfig.isCommandMatch("/test/", "test extra", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void regexTest3() {
|
public void regexTest3() {
|
||||||
Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("/test( argument)?/", "test argument", false, helper));
|
Assertions.assertTrue(
|
||||||
|
GameCommandExecutionConditionConfig.isCommandMatch("/test( argument)?/", "test argument", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void regexTest4() {
|
public void regexTest4() {
|
||||||
Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("/test( argument)?/", "test fail", false, helper));
|
Assertions.assertFalse(
|
||||||
|
GameCommandExecutionConditionConfig.isCommandMatch("/test( argument)?/", "test fail", false, helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void regexTest5() {
|
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 {
|
public static class ExecutionHelper implements GameCommandExecutionHelper {
|
||||||
|
Loading…
Reference in New Issue
Block a user