forked from kordlib/kord
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify permission overwrite API (Fix kordlib#302)
- Loading branch information
1 parent
6bb7881
commit e71399b
Showing
8 changed files
with
99 additions
and
94 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
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
44 changes: 44 additions & 0 deletions
44
rest/src/main/kotlin/builder/channel/PermissionOverritesBuilder.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,44 @@ | ||
package dev.kord.rest.builder.channel | ||
|
||
import dev.kord.common.entity.Overwrite | ||
import dev.kord.common.entity.OverwriteType | ||
import dev.kord.common.entity.Snowflake | ||
import kotlin.contracts.ExperimentalContracts | ||
import kotlin.contracts.InvocationKind | ||
import kotlin.contracts.contract | ||
|
||
/** | ||
* Interface containing shared behavior on all builders modifying permission overwrites. | ||
*/ | ||
interface PermissionOverritesBuilder { | ||
/** | ||
* The permission overwrites for this category. | ||
*/ | ||
var permissionOverwrites: MutableSet<Overwrite>? | ||
} | ||
|
||
/** | ||
* adds a [Overwrite] for the [memberId]. | ||
*/ | ||
@OptIn(ExperimentalContracts::class) | ||
inline fun PermissionOverritesBuilder.addMemberOverwrite(memberId: Snowflake, builder: PermissionOverwriteBuilder.() -> Unit) { | ||
contract { | ||
callsInPlace(builder, InvocationKind.EXACTLY_ONCE) | ||
} | ||
val overwrite = permissionOverwrites ?: mutableSetOf() | ||
overwrite.add(PermissionOverwriteBuilder(OverwriteType.Member, memberId).apply(builder).toOverwrite()) | ||
permissionOverwrites = overwrite | ||
} | ||
|
||
/** | ||
* adds a [Overwrite] for the [roleId]. | ||
*/ | ||
@OptIn(ExperimentalContracts::class) | ||
inline fun PermissionOverritesBuilder.addRoleOverwrite(roleId: Snowflake, builder: PermissionOverwriteBuilder.() -> Unit) { | ||
contract { | ||
callsInPlace(builder, InvocationKind.EXACTLY_ONCE) | ||
} | ||
val overwrite = permissionOverwrites ?: mutableSetOf() | ||
overwrite.add(PermissionOverwriteBuilder(OverwriteType.Role, roleId).apply(builder).toOverwrite()) | ||
permissionOverwrites = overwrite | ||
} |
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