mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Update docs
This commit is contained in:
parent
6cdc85facd
commit
1abb0204a2
@ -12,7 +12,9 @@ package net.mamoe.mirai.console.permission
|
|||||||
import kotlin.annotation.AnnotationTarget.*
|
import kotlin.annotation.AnnotationTarget.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标记一个实验性的权限系统 API
|
* 标记一个实验性的权限系统 API.
|
||||||
|
*
|
||||||
|
* 权限系统是在 1.0-M4 引入的一个实验性系统, 目前不具有 API 稳定性.
|
||||||
*/
|
*/
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
|
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
|
||||||
|
@ -30,7 +30,8 @@ public interface PermissionService<P : Permission> {
|
|||||||
|
|
||||||
public fun getGrantedPermissions(permissibleIdentifier: PermissibleIdentifier): Sequence<P>
|
public fun getGrantedPermissions(permissibleIdentifier: PermissibleIdentifier): Sequence<P>
|
||||||
|
|
||||||
public fun testPermission(permissibleIdentifier: PermissibleIdentifier, permissionId: PermissionId): Boolean {
|
public fun testPermission(permissibleIdentifier: PermissibleIdentifier, permission: P): Boolean {
|
||||||
|
val permissionId = permission.id
|
||||||
val all = this[permissionId]?.parentsWithSelfSequence() ?: return false
|
val all = this[permissionId]?.parentsWithSelfSequence() ?: return false
|
||||||
return getGrantedPermissions(permissibleIdentifier).any { p ->
|
return getGrantedPermissions(permissibleIdentifier).any { p ->
|
||||||
all.any { p.id == it.id }
|
all.any { p.id == it.id }
|
||||||
@ -61,6 +62,11 @@ public interface PermissionService<P : Permission> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalPermission
|
||||||
|
public fun <P : Permission> PermissionService<P>.getOrFail(id: PermissionId): P {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ExperimentalPermission
|
@ExperimentalPermission
|
||||||
internal fun PermissionService<*>.allocatePermissionIdForPlugin(name: String, id: String) =
|
internal fun PermissionService<*>.allocatePermissionIdForPlugin(name: String, id: String) =
|
||||||
PermissionId("plugin.${name.toLowerCase()}", id.toLowerCase())
|
PermissionId("plugin.${name.toLowerCase()}", id.toLowerCase())
|
||||||
@ -85,7 +91,7 @@ public fun PermissibleIdentifier.hasPermission(permission: Permission): Boolean
|
|||||||
@ExperimentalPermission
|
@ExperimentalPermission
|
||||||
public fun PermissibleIdentifier.hasPermission(permissionId: PermissionId): Boolean =
|
public fun PermissibleIdentifier.hasPermission(permissionId: PermissionId): Boolean =
|
||||||
(PermissionService.INSTANCE as PermissionService<Permission>).run {
|
(PermissionService.INSTANCE as PermissionService<Permission>).run {
|
||||||
testPermission(this@hasPermission, permissionId)
|
testPermission(this@hasPermission, get(permissionId) ?: PermissionNotFoundException(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExperimentalPermission
|
@ExperimentalPermission
|
||||||
|
Loading…
Reference in New Issue
Block a user