mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Rename BuiltInCommands.rootPermission to BuiltInCommands.parentPermission;
Update docs
This commit is contained in:
parent
7b8e9cc1c6
commit
3a45254fee
@ -47,7 +47,7 @@ internal interface BuiltInCommandInternal : Command, BuiltInCommand
|
|||||||
@OptIn(ExperimentalPermission::class)
|
@OptIn(ExperimentalPermission::class)
|
||||||
public object BuiltInCommands {
|
public object BuiltInCommands {
|
||||||
@ConsoleExperimentalApi
|
@ConsoleExperimentalApi
|
||||||
public val rootPermission: Permission by lazy {
|
public val parentPermission: Permission by lazy {
|
||||||
PermissionService.INSTANCE.register(
|
PermissionService.INSTANCE.register(
|
||||||
PermissionId("console", "*"),
|
PermissionId("console", "*"),
|
||||||
"The parent of any built-in commands"
|
"The parent of any built-in commands"
|
||||||
@ -67,7 +67,6 @@ public object BuiltInCommands {
|
|||||||
public object HelpCommand : SimpleCommand(
|
public object HelpCommand : SimpleCommand(
|
||||||
ConsoleCommandOwner, "help",
|
ConsoleCommandOwner, "help",
|
||||||
description = "Command list",
|
description = "Command list",
|
||||||
parentPermission = rootPermission,
|
|
||||||
), BuiltInCommandInternal {
|
), BuiltInCommandInternal {
|
||||||
@Handler
|
@Handler
|
||||||
public suspend fun CommandSender.handle() {
|
public suspend fun CommandSender.handle() {
|
||||||
@ -87,7 +86,6 @@ public object BuiltInCommands {
|
|||||||
public object StopCommand : SimpleCommand(
|
public object StopCommand : SimpleCommand(
|
||||||
ConsoleCommandOwner, "stop", "shutdown", "exit",
|
ConsoleCommandOwner, "stop", "shutdown", "exit",
|
||||||
description = "Stop the whole world.",
|
description = "Stop the whole world.",
|
||||||
parentPermission = rootPermission,
|
|
||||||
), BuiltInCommandInternal {
|
), BuiltInCommandInternal {
|
||||||
|
|
||||||
private val closingLock = Mutex()
|
private val closingLock = Mutex()
|
||||||
@ -123,7 +121,6 @@ public object BuiltInCommands {
|
|||||||
public object LoginCommand : SimpleCommand(
|
public object LoginCommand : SimpleCommand(
|
||||||
ConsoleCommandOwner, "login", "登录",
|
ConsoleCommandOwner, "login", "登录",
|
||||||
description = "Log in a bot account.",
|
description = "Log in a bot account.",
|
||||||
parentPermission = rootPermission,
|
|
||||||
), BuiltInCommandInternal {
|
), BuiltInCommandInternal {
|
||||||
@Handler
|
@Handler
|
||||||
public suspend fun CommandSender.handle(id: Long, password: String) {
|
public suspend fun CommandSender.handle(id: Long, password: String) {
|
||||||
@ -160,7 +157,6 @@ public object BuiltInCommands {
|
|||||||
}.getOrElse { illegalArgument("指令不存在: $id", it) }
|
}.getOrElse { illegalArgument("指令不存在: $id", it) }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parentPermission = rootPermission,
|
|
||||||
), BuiltInCommandInternal {
|
), BuiltInCommandInternal {
|
||||||
// TODO: 2020/9/10 improve Permission command
|
// TODO: 2020/9/10 improve Permission command
|
||||||
@SubCommand("permit", "grant", "add")
|
@SubCommand("permit", "grant", "add")
|
||||||
|
@ -10,11 +10,14 @@
|
|||||||
package net.mamoe.mirai.console.command
|
package net.mamoe.mirai.console.command
|
||||||
|
|
||||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregisterAllCommands
|
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
|
import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指令的所有者. 目前仅作为标识作用.
|
* 指令的所有者.
|
||||||
*
|
*
|
||||||
* @see CommandManager.unregisterAllCommands 取消注册所有属于一个 [CommandOwner] 的指令
|
* @see CommandManager.unregisterAllCommands 取消注册所有属于一个 [CommandOwner] 的指令
|
||||||
* @see CommandManager.registeredCommands 获取已经注册了的属于一个 [CommandOwner] 的指令列表.
|
* @see CommandManager.registeredCommands 获取已经注册了的属于一个 [CommandOwner] 的指令列表.
|
||||||
@ -24,11 +27,8 @@ import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
|
|||||||
@OptIn(ExperimentalPermission::class)
|
@OptIn(ExperimentalPermission::class)
|
||||||
public interface CommandOwner : PermissionIdNamespace {
|
public interface CommandOwner : PermissionIdNamespace {
|
||||||
/**
|
/**
|
||||||
* 此 [PermissionIdNamespace] 拥有的指令都默认将 [parentPermission] 作为父权限.
|
* 在构造指令时, [Command.permission] 默认会使用 [parentPermission] 作为 [Permission.parent]
|
||||||
*
|
|
||||||
* TODO document
|
|
||||||
*/
|
*/
|
||||||
@ExperimentalPermission
|
|
||||||
public val parentPermission: Permission
|
public val parentPermission: Permission
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,10 +36,7 @@ public interface CommandOwner : PermissionIdNamespace {
|
|||||||
* 代表控制台所有者. 所有的 mirai-console 内建的指令都属于 [ConsoleCommandOwner].
|
* 代表控制台所有者. 所有的 mirai-console 内建的指令都属于 [ConsoleCommandOwner].
|
||||||
*/
|
*/
|
||||||
internal object ConsoleCommandOwner : CommandOwner {
|
internal object ConsoleCommandOwner : CommandOwner {
|
||||||
@ExperimentalPermission
|
override val parentPermission: Permission get() = BuiltInCommands.parentPermission
|
||||||
override val parentPermission: Permission
|
|
||||||
get() = RootPermission
|
|
||||||
|
|
||||||
@ExperimentalPermission
|
|
||||||
override fun permissionId(id: String): PermissionId = PermissionId("console", id)
|
override fun permissionId(id: String): PermissionId = PermissionId("console", id)
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ import net.mamoe.mirai.console.command.Command
|
|||||||
* #### 指令的权限
|
* #### 指令的权限
|
||||||
* 每个指令都拥有一个 [Command.permission].
|
* 每个指令都拥有一个 [Command.permission].
|
||||||
*
|
*
|
||||||
* [BuiltInCommands.rootPermission] 为所有内建指令的权限.
|
* [BuiltInCommands.parentPermission] 为所有内建指令的权限.
|
||||||
*
|
*
|
||||||
* #### 手动申请权限
|
* #### 手动申请权限
|
||||||
* [PermissionService.register]
|
* [PermissionService.register]
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.permission
|
package net.mamoe.mirai.console.permission
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [PermissionId] 的命名空间. 用于提供 [PermissionId.namespace].
|
||||||
|
*/
|
||||||
public interface PermissionIdNamespace {
|
public interface PermissionIdNamespace {
|
||||||
|
/**
|
||||||
|
* 创建一个此命名空间下的 [PermitteeId]
|
||||||
|
*/
|
||||||
public fun permissionId(id: String): PermissionId
|
public fun permissionId(id: String): PermissionId
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user