diff --git a/common/src/main/java/com/discordsrv/common/core/logging/impl/DiscordSRVLogger.java b/common/src/main/java/com/discordsrv/common/core/logging/impl/DiscordSRVLogger.java index f125822f..8d558f1e 100644 --- a/common/src/main/java/com/discordsrv/common/core/logging/impl/DiscordSRVLogger.java +++ b/common/src/main/java/com/discordsrv/common/core/logging/impl/DiscordSRVLogger.java @@ -146,7 +146,7 @@ public class DiscordSRVLogger implements Logger { where = "Server ID " + Long.toUnsignedString(guildId); } - String msg = DiscordPermissionUtil.createErrorMessage(EnumSet.of(permission), where); + String msg = DiscordPermissionUtil.createErrorMessage(guildChannel, EnumSet.of(permission), where); if (message == null) { message = msg; } else { diff --git a/common/src/main/java/com/discordsrv/common/util/DiscordPermissionUtil.java b/common/src/main/java/com/discordsrv/common/util/DiscordPermissionUtil.java index 873d6277..92aea49e 100644 --- a/common/src/main/java/com/discordsrv/common/util/DiscordPermissionUtil.java +++ b/common/src/main/java/com/discordsrv/common/util/DiscordPermissionUtil.java @@ -20,6 +20,7 @@ package com.discordsrv.common.util; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; @@ -41,7 +42,7 @@ public final class DiscordPermissionUtil { channel = ((ThreadChannel) channel).getParentChannel(); } EnumSet missingPermissions = getMissingPermissions(channel, permissions); - return createErrorMessage(missingPermissions, "#" + channel.getName()); + return createErrorMessage(channel, missingPermissions, "#" + channel.getName()); } public static EnumSet getMissingPermissions(GuildChannel channel, Collection permissions) { @@ -63,7 +64,7 @@ public final class DiscordPermissionUtil { public static String missingPermissionsString(Guild guild, Collection permissions) { EnumSet missingPermissions = getMissingPermissions(guild, permissions); - return createErrorMessage(missingPermissions, guild.getName()); + return createErrorMessage(null, missingPermissions, guild.getName()); } public static EnumSet getMissingPermissions(Guild guild, Collection permissions) { @@ -76,12 +77,34 @@ public final class DiscordPermissionUtil { return missingPermissions; } - public static String createErrorMessage(EnumSet permissions, String where) { + public static String createErrorMessage(GuildChannel channel, EnumSet permissions, String where) { if (permissions.isEmpty()) { return null; } - return "the bot is lacking permissions in " + where + ": " - + permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")); + return "the bot is lacking permissions in " + where + ": " + permissions.stream() + .map(permission -> getPermissionName(channel, permission)) + .collect(Collectors.joining(", ")); + } + + public static String getPermissionName(GuildChannel channel, Permission permission) { + if (channel instanceof ForumChannel) { + switch (permission) { + case MESSAGE_SEND: return "Create Posts"; + case MESSAGE_SEND_IN_THREADS: return "Send Messages in Posts"; + case MANAGE_THREADS: return "Manage Posts"; + case MESSAGE_HISTORY: return "Read Post History"; + } + } + + switch (permission) { + case MANAGE_CHANNEL: return "Manage Channel" + (channel != null ? "s" : ""); + case VIEW_CHANNEL: return "View Channel" + (channel != null ? "s" : ""); + case MANAGE_PERMISSIONS: return "Manage Permission" + (channel != null ? "s" : ""); + case MANAGE_GUILD_EXPRESSIONS: return "Manage Expressions"; + case CREATE_INSTANT_INVITE: return "Create Invite"; + } + + return permission.getName(); } }