Skip to content

Commit

Permalink
Fix permission troubleshooter
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Dec 3, 2024
1 parent 78d2ddc commit 04483f3
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions plugin/src/main/kotlin/space/votebot/util/PermissionUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ private val requiredPermissions =
suspend fun <A : Arguments> SlashCommandContext<*, A, *>.checkPermissions(channel: GuildMessageChannel): Boolean {
val selfPermissions = channel.getEffectivePermissions(channel.kord.selfId)
if (requiredPermissions !in selfPermissions) {
sendMissingPermissions(VoteBotTranslations.Vote.Create.MissingPermissions.bot, channel, channel.kord.selfId, selfPermissions)
sendMissingPermissions(
VoteBotTranslations.Vote.Create.MissingPermissions.bot,
channel,
channel.kord.selfId,
selfPermissions
)
return false
}

val userPermissions = channel.getEffectivePermissions(user.id)
if ((requiredPermissions - Permission.ViewChannel) !in userPermissions) {
sendMissingPermissions(VoteBotTranslations.Vote.Create.MissingPermissions.user, channel, user.id, userPermissions)
sendMissingPermissions(
VoteBotTranslations.Vote.Create.MissingPermissions.user,
channel,
user.id,
userPermissions
)
return false
}

Expand Down Expand Up @@ -64,11 +74,9 @@ private suspend fun SlashCommandContext<*, *, *>.sendMissingPermissions(
val missingPermissions = (requiredPermissions - permissions).values.map {
translate(
VoteBotTranslations.Vote.Create.MissingPermissions.Explainer.permission,
arrayOf(
it.translate(this@sendMissingPermissions),
(it in serverPermissions).translate(),
(it in permissions).translate(),
)
it.translate(this@sendMissingPermissions),
(it in serverPermissions).translate(),
(it in permissions).translate(),
)
}.joinToString("\n")

Expand Down

0 comments on commit 04483f3

Please sign in to comment.