Skip to content

Commit

Permalink
Fix some more permission errors & fix weird toString output
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 25, 2024
1 parent 9ae68ca commit 00132c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public data class Poll(
public data class ActualOption(override val position: Int?, val option: String, val emoji: Emoji?) : Option() {
@Serializable
public data class Emoji(val id: ULong?, val name: String?)

override fun toString(): String = option
}

/**
Expand Down
8 changes: 3 additions & 5 deletions plugin/src/main/kotlin/space/votebot/util/PermissionUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import dev.kord.common.entity.Snowflake
import dev.kord.core.entity.channel.GuildMessageChannel
import dev.kord.core.entity.channel.TopGuildMessageChannel
import dev.kord.core.entity.channel.thread.ThreadChannel
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.schlaubi.mikbot.plugin.api.util.discordError

suspend fun <A : Arguments> SlashCommandContext<*, A, *>.checkPermissions(channel: GuildMessageChannel) {
val restChannel = channel.withStrategy(EntitySupplyStrategy.rest)
val selfPermissions = restChannel.getEffectivePermissions(channel.kord.selfId)
val selfPermissions = channel.getEffectivePermissions(channel.kord.selfId)
val requiredPermissions =
Permissions(Permission.SendMessages, Permission.EmbedLinks, Permission.AttachFiles, Permission.ViewChannel)
if (requiredPermissions !in selfPermissions) {
discordError(translate("vote.create.missing_permissions.bot", arrayOf(channel.mention)))
}

val userPermissions = restChannel.getEffectivePermissions(user.id)
if (requiredPermissions !in userPermissions) {
val userPermissions = channel.getEffectivePermissions(user.id)
if ((requiredPermissions - Permission.ViewChannel) !in userPermissions) {
discordError(translate("vote.create.missing_permissions.user", arrayOf(channel.mention)))
}
}
Expand Down

0 comments on commit 00132c0

Please sign in to comment.