Skip to content

Commit

Permalink
Add safety checks for using roles in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Apr 6, 2021
1 parent 6fd2ed1 commit 665dfb1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ml/duncte123/skybot/SkyBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 665dfb1

Please sign in to comment.