Skip to content

Commit 928b180

Browse files
committed
setting to toggle commands account owner perms
1 parent 0c2f2d9 commit 928b180

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/main/java/dev/zenith/web/WebAPIConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ public class WebAPIConfig {
88
public String authToken = UUID.randomUUID().toString();
99
public boolean rateLimiter = true;
1010
public int rateLimitRequestsPerMinute = 30;
11+
public boolean commandsAccountOwnerPerms = false;
1112
}

src/main/java/dev/zenith/web/api/WebAPICommandSource.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.zenith.command.api.CommandSource;
66
import com.zenith.discord.Embed;
77

8+
import static dev.zenith.web.WebApiPlugin.PLUGIN_CONFIG;
9+
810
public class WebAPICommandSource implements CommandSource {
911
public static final WebAPICommandSource INSTANCE = new WebAPICommandSource();
1012

@@ -15,9 +17,13 @@ public String name() {
1517

1618
@Override
1719
public boolean validateAccountOwner(final CommandContext ctx) {
18-
ctx.getEmbed()
19-
.description("Web API is not authorized to execute this command!");
20-
return false;
20+
if (PLUGIN_CONFIG.commandsAccountOwnerPerms) {
21+
return true;
22+
} else {
23+
ctx.getEmbed()
24+
.description("Web API is not authorized to execute this command!");
25+
return false;
26+
}
2127
}
2228

2329
@Override

src/main/java/dev/zenith/web/command/WebAPICommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public CommandUsage commandUsage() {
2828
.usageLines(
2929
"on/off",
3030
"port <port>",
31-
"auth <token>"
31+
"auth <token>",
32+
"commandsAccountOwnerPerms on/off"
3233
)
3334
.build();
3435
}
@@ -58,6 +59,11 @@ public LiteralArgumentBuilder<CommandContext> register() {
5859
PLUGIN_CONFIG.authToken = getString(c, "token");
5960
c.getSource().getEmbed()
6061
.title("Auth Token Set");
62+
})))
63+
.then(literal("commandsAccountOwnerPerms").then(argument("toggle", toggle()).executes(c -> {
64+
PLUGIN_CONFIG.commandsAccountOwnerPerms = getToggle(c, "toggle");
65+
c.getSource().getEmbed()
66+
.title("Commands Account Owner Perms " + toggleStrCaps(PLUGIN_CONFIG.commandsAccountOwnerPerms));
6167
})));
6268
}
6369

@@ -67,6 +73,7 @@ public void defaultEmbed(Embed embed) {
6773
.addField("Web API", SERVER.isRunning() ? "Running" : "Stopped")
6874
.addField("Port", PLUGIN_CONFIG.port)
6975
.addField("Auth Token", PLUGIN_CONFIG.authToken)
76+
.addField("Commands Account Owner Perms", PLUGIN_CONFIG.commandsAccountOwnerPerms)
7077
.primaryColor();
7178
}
7279
}

0 commit comments

Comments
 (0)