mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Fix permission duplication
This commit is contained in:
parent
8dd302073b
commit
5cd35d7fbe
@ -15,7 +15,7 @@ import net.mamoe.kjbb.JvmBlockingBridge
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.executeCommand
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
|
||||
import net.mamoe.mirai.console.command.java.JCommand
|
||||
import net.mamoe.mirai.console.internal.command.createCommandPermission
|
||||
import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission
|
||||
import net.mamoe.mirai.console.internal.command.isValidSubName
|
||||
import net.mamoe.mirai.console.permission.ExperimentalPermission
|
||||
import net.mamoe.mirai.console.permission.Permission
|
||||
@ -118,5 +118,5 @@ public abstract class AbstractCommand
|
||||
}.toTypedArray()
|
||||
|
||||
@OptIn(ExperimentalPermission::class)
|
||||
public override val permission: Permission by lazy { createCommandPermission(parentPermission) }
|
||||
public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) }
|
||||
}
|
@ -14,7 +14,7 @@ package net.mamoe.mirai.console.command
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.execute
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.executeCommand
|
||||
import net.mamoe.mirai.console.command.java.JRawCommand
|
||||
import net.mamoe.mirai.console.internal.command.createCommandPermission
|
||||
import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission
|
||||
import net.mamoe.mirai.console.permission.ExperimentalPermission
|
||||
import net.mamoe.mirai.console.permission.Permission
|
||||
import net.mamoe.mirai.console.permission.PermissionId
|
||||
@ -49,7 +49,7 @@ public abstract class RawCommand @OptIn(ExperimentalPermission::class) construct
|
||||
public override val prefixOptional: Boolean = false
|
||||
) : Command {
|
||||
@OptIn(ExperimentalPermission::class)
|
||||
public override val permission: Permission by lazy { createCommandPermission(parentPermission) }
|
||||
public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) }
|
||||
|
||||
/**
|
||||
* 在指令被执行时调用.
|
||||
|
@ -13,7 +13,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import net.mamoe.mirai.console.command.*
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.execute
|
||||
import net.mamoe.mirai.console.internal.command.createCommandPermission
|
||||
import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission
|
||||
import net.mamoe.mirai.console.permission.ExperimentalPermission
|
||||
import net.mamoe.mirai.console.permission.Permission
|
||||
import net.mamoe.mirai.console.permission.PermissionId
|
||||
@ -67,7 +67,7 @@ public abstract class JRawCommand @OptIn(ExperimentalPermission::class)
|
||||
|
||||
/** 指令权限 */
|
||||
@ExperimentalPermission
|
||||
public final override var permission: Permission = createCommandPermission(parentPermission)
|
||||
public final override var permission: Permission = createOrFindCommandPermission(parentPermission)
|
||||
protected set
|
||||
|
||||
/** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */
|
||||
|
@ -79,7 +79,7 @@ internal abstract class AbstractReflectionCommand @OptIn(ExperimentalPermission:
|
||||
internal val defaultSubCommand: DefaultSubCommandDescriptor by lazy {
|
||||
DefaultSubCommandDescriptor(
|
||||
"",
|
||||
createCommandPermission(parentPermission),
|
||||
createOrFindCommandPermission(parentPermission),
|
||||
onCommand = { sender: CommandSender, args: MessageChain ->
|
||||
sender.onDefault(args)
|
||||
}
|
||||
|
@ -143,8 +143,9 @@ internal fun Group.fuzzySearchMember(
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPermission::class)
|
||||
internal fun Command.createCommandPermission(parent: PermissionId): Permission {
|
||||
return PermissionService.INSTANCE.register(owner.permissionId(primaryName), description, parent)
|
||||
internal fun Command.createOrFindCommandPermission(parent: PermissionId): Permission {
|
||||
val id = owner.permissionId(primaryName)
|
||||
return PermissionService.INSTANCE[id] ?: PermissionService.INSTANCE.register(id, description, parent)
|
||||
}
|
||||
|
||||
//// internal
|
||||
|
@ -56,7 +56,7 @@ public fun Permission.parentsWithSelfSequence(): Sequence<Permission> =
|
||||
*/
|
||||
@Serializable
|
||||
@ExperimentalPermission
|
||||
public class PermissionImpl(
|
||||
public data class PermissionImpl(
|
||||
override val id: PermissionId,
|
||||
override val description: String,
|
||||
override val parentId: PermissionId = RootPermission.id
|
||||
|
Loading…
Reference in New Issue
Block a user