-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement slash command permissions (#253)
* Implement slash command permissions * Undo some formatting that should now have happened * Undo some more formatting * Implement some requested changes * Add core representation * Remove duplicated method * Change name * Implement requested changes - Fix compilation error * More requested changes * Add Test
- Loading branch information
1 parent
b82cb7d
commit ec02f48
Showing
13 changed files
with
406 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
common/src/test/resources/json/interaction/slash_command_permissions_update.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"id": "833008574669651989", | ||
"application_id": "535129406650318860", | ||
"guild_id": "809471441719787602", | ||
"permissions": [ | ||
{ | ||
"id": "827126703301066792", | ||
"type": 1, | ||
"permission": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dev.kord.core.cache.data | ||
|
||
import dev.kord.common.annotation.KordPreview | ||
import dev.kord.common.entity.DiscordGuildApplicationCommandPermission | ||
import dev.kord.common.entity.Snowflake | ||
|
||
@KordPreview | ||
data class GuildApplicationCommandPermissionData( | ||
val id: Snowflake, | ||
val type: DiscordGuildApplicationCommandPermission.Type, | ||
val permission: Boolean | ||
) { | ||
companion object { | ||
fun from(permission: DiscordGuildApplicationCommandPermission) = with(permission) { | ||
GuildApplicationCommandPermissionData(id, type, this.permission) | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionsData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.kord.core.cache.data | ||
|
||
import dev.kord.common.annotation.KordPreview | ||
import dev.kord.common.entity.DiscordGuildApplicationCommandPermissions | ||
import dev.kord.common.entity.Snowflake | ||
|
||
@KordPreview | ||
data class GuildApplicationCommandPermissionsData( | ||
val id: Snowflake, | ||
val applicationId: Snowflake, | ||
val guildId: Snowflake, | ||
val permissions: List<GuildApplicationCommandPermissionData> | ||
) { | ||
|
||
companion object { | ||
fun from(permissions: DiscordGuildApplicationCommandPermissions) = with(permissions) { | ||
GuildApplicationCommandPermissionsData( | ||
id, | ||
applicationId, | ||
guildId, | ||
this.permissions.map(GuildApplicationCommandPermissionData::from) | ||
) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
core/src/main/kotlin/entity/interaction/ApplicationGuildCommandPermissions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.kord.core.entity.interaction | ||
|
||
import dev.kord.common.annotation.KordPreview | ||
import dev.kord.common.entity.DiscordGuildApplicationCommandPermission | ||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.core.cache.data.GuildApplicationCommandPermissionData | ||
import dev.kord.core.cache.data.GuildApplicationCommandPermissionsData | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
|
||
@KordPreview | ||
class GuildApplicationCommandPermission(val data: GuildApplicationCommandPermissionData) { | ||
|
||
val id: Snowflake get() = data.id | ||
|
||
val type: DiscordGuildApplicationCommandPermission.Type get() = data.type | ||
|
||
val permission: Boolean get() = data.permission | ||
} | ||
|
||
@KordPreview | ||
class ApplicationCommandPermissions(val data: GuildApplicationCommandPermissionsData) { | ||
val id: Snowflake get() = data.id | ||
|
||
val applicationId: Snowflake get() = data.applicationId | ||
|
||
val guildId: Snowflake get() = data.guildId | ||
|
||
val permissions: Flow<GuildApplicationCommandPermission> | ||
get() = flow { | ||
data.permissions.forEach { emit(GuildApplicationCommandPermission(it)) } | ||
} | ||
} |
Oops, something went wrong.