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