From 9118ceefd8240c8a239911873dba268dbf05a70f Mon Sep 17 00:00:00 2001 From: Alex G Date: Wed, 10 Jan 2024 21:20:22 -0500 Subject: [PATCH] feat: added userId entry to perms Allowed add/remove subtypes within the permissions command to be used without user mentions, and simply just the user ID FS-34 --- .../commands/developer/PermissionCommand.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/dev/salmonllama/fsbot/commands/developer/PermissionCommand.java b/src/main/java/dev/salmonllama/fsbot/commands/developer/PermissionCommand.java index 121c24d..0fc1e4e 100644 --- a/src/main/java/dev/salmonllama/fsbot/commands/developer/PermissionCommand.java +++ b/src/main/java/dev/salmonllama/fsbot/commands/developer/PermissionCommand.java @@ -93,7 +93,7 @@ public class PermissionCommand extends Command { perm -> ctx.getApi().getUserById(perm.getUserId()).thenAcceptAsync( (discordUser) -> text.append(perm.getUserId()) .append(" - ") - .append(discordUser.getDiscriminatedName()) + .append(discordUser.getName()) .append(System.lineSeparator()) ).join() ) @@ -116,14 +116,14 @@ public class PermissionCommand extends Command { } private void add(CommandContext ctx) { + String userId; if (ctx.getMessage().getMentionedUsers().isEmpty()) { - System.out.println("No mentioned users"); - // If no mentioned users, improper usage - return; + // If no mentioned users, then the user ID = args[1] + userId = ctx.getArgs()[1]; + } else { + userId = ctx.getMessage().getMentionedUsers().get(0).getIdAsString(); } - String userId = ctx.getMessage().getMentionedUsers().get(0).getIdAsString(); - StaticPermission perm = new StaticPermission.StaticPermissionBuilder(userId).setPermission(ctx.getArgs()[2]).build(); StaticPermissionController.insert(perm).thenAcceptAsync((Void) -> { @@ -131,19 +131,19 @@ public class PermissionCommand extends Command { .setTitle("Permissions Added") .addField("User:", userId) .addField("Permission:", ctx.getArgs()[2]); - ctx.reply(response); }); } private void remove(CommandContext ctx) { // TODO: Remove is not functional - if (ctx.getMessage().getMentionedUsers().isEmpty()) { - // If no mentioned users, improper usage - return; - } + String userId = ctx.getArgs()[1]; - String userId = ctx.getMessage().getMentionedUsers().get(0).getIdAsString(); - - StaticPermissionController.delete(userId, ctx.getArgs()[2]).thenAcceptAsync((Void) -> System.out.println("Permission removed")).exceptionally(ExceptionLogger.get()); + StaticPermissionController.delete(userId, ctx.getArgs()[2]).thenAcceptAsync((Void) -> { + EmbedBuilder response = new EmbedBuilder() + .setTitle("Permissions Removed") + .addField("User:", userId) + .addField("Permission:", ctx.getArgs()[2]); + ctx.reply(response); + }).exceptionally(ExceptionLogger.get()); } }