Add "command." prefix to command permissions

This commit is contained in:
Him188 2020-09-13 01:15:20 +08:00
parent 9139d62a7c
commit 6f7cc1a78d
3 changed files with 3 additions and 4 deletions

View File

@ -20,7 +20,6 @@ import net.mamoe.mirai.console.internal.command.CommandManagerImpl
import net.mamoe.mirai.console.internal.command.CommandManagerImpl.allRegisteredCommands import net.mamoe.mirai.console.internal.command.CommandManagerImpl.allRegisteredCommands
import net.mamoe.mirai.console.internal.util.runIgnoreException import net.mamoe.mirai.console.internal.util.runIgnoreException
import net.mamoe.mirai.console.permission.Permission import net.mamoe.mirai.console.permission.Permission
import net.mamoe.mirai.console.permission.PermissionId
import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.permission.PermissionService
import net.mamoe.mirai.console.permission.PermissionService.Companion.denyPermission import net.mamoe.mirai.console.permission.PermissionService.Companion.denyPermission
import net.mamoe.mirai.console.permission.PermissionService.Companion.findCorrespondingPermissionOrFail import net.mamoe.mirai.console.permission.PermissionService.Companion.findCorrespondingPermissionOrFail
@ -51,7 +50,7 @@ public object BuiltInCommands {
@ConsoleExperimentalApi @ConsoleExperimentalApi
public val parentPermission: Permission by lazy { public val parentPermission: Permission by lazy {
PermissionService.INSTANCE.register( PermissionService.INSTANCE.register(
PermissionId("console", "*"), ConsoleCommandOwner.permissionId("*"),
"The parent of any built-in commands" "The parent of any built-in commands"
) )
} }

View File

@ -36,5 +36,5 @@ public interface CommandOwner : PermissionIdNamespace {
internal object ConsoleCommandOwner : CommandOwner { internal object ConsoleCommandOwner : CommandOwner {
override val parentPermission: Permission get() = BuiltInCommands.parentPermission override val parentPermission: Permission get() = BuiltInCommands.parentPermission
override fun permissionId(name: String): PermissionId = PermissionId("console", name) override fun permissionId(name: String): PermissionId = PermissionId("console", "command.$name")
} }

View File

@ -88,7 +88,7 @@ internal fun Group.fuzzySearchMember(
} }
internal fun Command.createOrFindCommandPermission(parent: Permission): Permission { internal fun Command.createOrFindCommandPermission(parent: Permission): Permission {
val id = owner.permissionId(primaryName) val id = owner.permissionId("command.$primaryName")
return PermissionService.INSTANCE[id] ?: PermissionService.INSTANCE.register(id, description, parent) return PermissionService.INSTANCE[id] ?: PermissionService.INSTANCE.register(id, description, parent)
} }