From 665dfb18317d805c29391aa21c492dee1db3cc91 Mon Sep 17 00:00:00 2001 From: duncte123 Date: Tue, 6 Apr 2021 17:31:28 +0200 Subject: [PATCH] Add safety checks for using roles in settings --- build.gradle.kts | 2 +- src/main/java/ml/duncte123/skybot/SkyBot.java | 2 +- .../guild/owner/settings/SettingsCommand.java | 17 +++++++++++++++++ .../commands/uncategorized/RoleInfoCommand.kt | 9 +++++---- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 53bc7f815..aa5555004 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -88,7 +88,7 @@ dependencies { // JDA (java discord api) // implementation(group = "com.github.dv8fromtheworld", name = "JDA", version = "4208971") { - implementation(group = "net.dv8tion", name = "JDA", version = "4.2.1_253") { + implementation(group = "net.dv8tion", name = "JDA", version = "4.2.1_254") { exclude(module = "opus-java") } diff --git a/src/main/java/ml/duncte123/skybot/SkyBot.java b/src/main/java/ml/duncte123/skybot/SkyBot.java index fda9ab8c7..2df8fa6fa 100644 --- a/src/main/java/ml/duncte123/skybot/SkyBot.java +++ b/src/main/java/ml/duncte123/skybot/SkyBot.java @@ -120,7 +120,7 @@ private SkyBot() throws LoginException { // Not using this because it overrides the member cache policy // we're calling loadMembers once the guild is ready // .setChunkingFilter((guildId) -> guildId == Settings.SUPPORT_GUILD_ID) - .enableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOTE, CacheFlag.MEMBER_OVERRIDES) + .enableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOTE, CacheFlag.MEMBER_OVERRIDES, CacheFlag.ROLE_TAGS) // Can't enable CLIENT_STATUS because we don't have GatewayIntent.GUILD_PRESENCES // (is it worth it to enable it for one command?) .disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS) diff --git a/src/main/java/ml/duncte123/skybot/commands/guild/owner/settings/SettingsCommand.java b/src/main/java/ml/duncte123/skybot/commands/guild/owner/settings/SettingsCommand.java index 205078e20..2c1079ec7 100644 --- a/src/main/java/ml/duncte123/skybot/commands/guild/owner/settings/SettingsCommand.java +++ b/src/main/java/ml/duncte123/skybot/commands/guild/owner/settings/SettingsCommand.java @@ -663,6 +663,23 @@ private Role getFoundRoleOrNull(CommandContext ctx) { return null; } + final Role.RoleTags tags = foundRole.getTags(); + + if (tags.isBot()) { + sendMsg(ctx, "I cannot give this role to members because it belongs to <@" + tags.getBotIdLong() + '>'); + return null; + } + + if (tags.isBoost()) { + sendMsg(ctx, "I cannot give the boost role to members"); + return null; + } + + if (tags.isIntegration()) { + sendMsg(ctx, "I cannot give this role to members because it is managed by an integration (for example twitch subscriber roles)"); + return null; + } + return foundRole; } diff --git a/src/main/kotlin/ml/duncte123/skybot/commands/uncategorized/RoleInfoCommand.kt b/src/main/kotlin/ml/duncte123/skybot/commands/uncategorized/RoleInfoCommand.kt index 7f4149d22..44e511221 100644 --- a/src/main/kotlin/ml/duncte123/skybot/commands/uncategorized/RoleInfoCommand.kt +++ b/src/main/kotlin/ml/duncte123/skybot/commands/uncategorized/RoleInfoCommand.kt @@ -60,14 +60,12 @@ class RoleInfoCommand : Command() { return } - // In order: get the highest role - // Map the permissions to a readable string - // Get the amount of members with this role - // Get the creation times of this role val role = roles[0] val perms = role.permissions.joinToString { it.getName() } val memberCount = ctx.jdaGuild.findMembersWithRoles(role).get().size val times = role.parseTimeCreated() + val tags = role.tags + val botDisp = if (tags.isBot) "\n**Bot:** <@${tags.botIdLong}>" else "" val embed = EmbedUtils.getDefaultEmbed() .setColor(role.colorRaw) @@ -81,6 +79,9 @@ class RoleInfoCommand : Command() { |**Position:** ${role.position} |**Members with this role:** $memberCount |**Managed:** ${role.isManaged.toEmoji()} + |**Bot role:** ${tags.isBot.toEmoji()}$botDisp + |**Boost role:** ${tags.isBoost.toEmoji()} + |**Integration role:** ${tags.isIntegration.toEmoji()} |**Hoisted:** ${role.isHoisted.toEmoji()} |**Mentionable:** ${role.isMentionable.toEmoji()} |**Permissions:** $perms