From 3a45254fee1deb9e01e2d27e10c889c0b6148d92 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 12 Sep 2020 19:00:18 +0800 Subject: [PATCH] Rename BuiltInCommands.rootPermission to BuiltInCommands.parentPermission; Update docs --- .../mirai/console/command/BuiltInCommands.kt | 6 +----- .../mamoe/mirai/console/command/CommandOwner.kt | 17 +++++++---------- .../mirai/console/permission/Permission.kt | 2 +- .../console/permission/PermissionIdNamespace.kt | 6 ++++++ 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/BuiltInCommands.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/BuiltInCommands.kt index 827a216d8..fe39c5268 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/BuiltInCommands.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/BuiltInCommands.kt @@ -47,7 +47,7 @@ internal interface BuiltInCommandInternal : Command, BuiltInCommand @OptIn(ExperimentalPermission::class) public object BuiltInCommands { @ConsoleExperimentalApi - public val rootPermission: Permission by lazy { + public val parentPermission: Permission by lazy { PermissionService.INSTANCE.register( PermissionId("console", "*"), "The parent of any built-in commands" @@ -67,7 +67,6 @@ public object BuiltInCommands { public object HelpCommand : SimpleCommand( ConsoleCommandOwner, "help", description = "Command list", - parentPermission = rootPermission, ), BuiltInCommandInternal { @Handler public suspend fun CommandSender.handle() { @@ -87,7 +86,6 @@ public object BuiltInCommands { public object StopCommand : SimpleCommand( ConsoleCommandOwner, "stop", "shutdown", "exit", description = "Stop the whole world.", - parentPermission = rootPermission, ), BuiltInCommandInternal { private val closingLock = Mutex() @@ -123,7 +121,6 @@ public object BuiltInCommands { public object LoginCommand : SimpleCommand( ConsoleCommandOwner, "login", "登录", description = "Log in a bot account.", - parentPermission = rootPermission, ), BuiltInCommandInternal { @Handler public suspend fun CommandSender.handle(id: Long, password: String) { @@ -160,7 +157,6 @@ public object BuiltInCommands { }.getOrElse { illegalArgument("指令不存在: $id", it) } } }, - parentPermission = rootPermission, ), BuiltInCommandInternal { // TODO: 2020/9/10 improve Permission command @SubCommand("permit", "grant", "add") diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt index bbe1bd642..22a988511 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt @@ -10,11 +10,14 @@ package net.mamoe.mirai.console.command import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregisterAllCommands -import net.mamoe.mirai.console.permission.* +import net.mamoe.mirai.console.permission.ExperimentalPermission +import net.mamoe.mirai.console.permission.Permission +import net.mamoe.mirai.console.permission.PermissionId +import net.mamoe.mirai.console.permission.PermissionIdNamespace import net.mamoe.mirai.console.plugin.jvm.JvmPlugin /** - * 指令的所有者. 目前仅作为标识作用. + * 指令的所有者. * * @see CommandManager.unregisterAllCommands 取消注册所有属于一个 [CommandOwner] 的指令 * @see CommandManager.registeredCommands 获取已经注册了的属于一个 [CommandOwner] 的指令列表. @@ -24,11 +27,8 @@ import net.mamoe.mirai.console.plugin.jvm.JvmPlugin @OptIn(ExperimentalPermission::class) public interface CommandOwner : PermissionIdNamespace { /** - * 此 [PermissionIdNamespace] 拥有的指令都默认将 [parentPermission] 作为父权限. - * - * TODO document + * 在构造指令时, [Command.permission] 默认会使用 [parentPermission] 作为 [Permission.parent] */ - @ExperimentalPermission public val parentPermission: Permission } @@ -36,10 +36,7 @@ public interface CommandOwner : PermissionIdNamespace { * 代表控制台所有者. 所有的 mirai-console 内建的指令都属于 [ConsoleCommandOwner]. */ internal object ConsoleCommandOwner : CommandOwner { - @ExperimentalPermission - override val parentPermission: Permission - get() = RootPermission + override val parentPermission: Permission get() = BuiltInCommands.parentPermission - @ExperimentalPermission override fun permissionId(id: String): PermissionId = PermissionId("console", id) } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permission.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permission.kt index be88bbd34..963863be7 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permission.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permission.kt @@ -27,7 +27,7 @@ import net.mamoe.mirai.console.command.Command * #### 指令的权限 * 每个指令都拥有一个 [Command.permission]. * - * [BuiltInCommands.rootPermission] 为所有内建指令的权限. + * [BuiltInCommands.parentPermission] 为所有内建指令的权限. * * #### 手动申请权限 * [PermissionService.register] diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt index 305369090..60e47ff91 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt @@ -9,6 +9,12 @@ package net.mamoe.mirai.console.permission +/** + * [PermissionId] 的命名空间. 用于提供 [PermissionId.namespace]. + */ public interface PermissionIdNamespace { + /** + * 创建一个此命名空间下的 [PermitteeId] + */ public fun permissionId(id: String): PermissionId } \ No newline at end of file