Public API stabilization: Review and remove ExperimentalPermission annotations

This commit is contained in:
Him188 2020-09-12 19:26:36 +08:00
parent 6ebad54856
commit c5e68885c7
28 changed files with 47 additions and 163 deletions

View File

@ -37,8 +37,8 @@ import kotlin.coroutines.CoroutineContext
*
* 这些 API 只应由前端实现者使用, 而不应该被插件或其他调用者使用.
*/
@Retention(AnnotationRetention.SOURCE)
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Retention(AnnotationRetention.BINARY)
@RequiresOptIn(level = RequiresOptIn.Level.ERROR)
@Target(CLASS, TYPEALIAS, FUNCTION, PROPERTY, FIELD, CONSTRUCTOR)
@MustBeDocumented
public annotation class ConsoleFrontEndImplementation

View File

@ -19,11 +19,14 @@ import net.mamoe.mirai.console.command.description.*
import net.mamoe.mirai.console.internal.command.CommandManagerImpl
import net.mamoe.mirai.console.internal.command.CommandManagerImpl.allRegisteredCommands
import net.mamoe.mirai.console.internal.util.runIgnoreException
import net.mamoe.mirai.console.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.Companion.denyPermission
import net.mamoe.mirai.console.permission.PermissionService.Companion.findCorrespondingPermissionOrFail
import net.mamoe.mirai.console.permission.PermissionService.Companion.getPermittedPermissions
import net.mamoe.mirai.console.permission.PermissionService.Companion.grantPermission
import net.mamoe.mirai.console.permission.PermitteeId
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
import net.mamoe.mirai.console.util.ConsoleInternalApi
import net.mamoe.mirai.event.events.EventCancelledException
@ -44,7 +47,6 @@ internal interface BuiltInCommandInternal : Command, BuiltInCommand
* 内建指令列表
*/
@Suppress("unused")
@OptIn(ExperimentalPermission::class)
public object BuiltInCommands {
@ConsoleExperimentalApi
public val parentPermission: Permission by lazy {
@ -145,12 +147,11 @@ public object BuiltInCommands {
}
}
@OptIn(ExperimentalPermission::class)
public object PermissionCommand : CompositeCommand(
ConsoleCommandOwner, "permission", "权限", "perm",
description = "Manage permissions",
overrideContext = buildCommandArgumentContext {
PermitteeId::class with PermissibleIdentifierArgumentParser
PermitteeId::class with PermitteeIdArgumentParser
Permission::class with PermissionIdArgumentParser.map { id ->
kotlin.runCatching {
id.findCorrespondingPermissionOrFail()

View File

@ -17,7 +17,6 @@ import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
import net.mamoe.mirai.console.command.java.JCommand
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
import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.message.data.SingleMessage
@ -42,12 +41,12 @@ public interface Command {
public val names: Array<out String>
/**
* 用法说明, 用于发送给用户. 一般 [usage] 包含 [description].
* 用法说明, 用于发送给用户. [usage] 一般包含 [description].
*/
public val usage: String
/**
* 指令描述, 用于显示在 [BuiltInCommands.Help]
* 指令描述, 用于显示在 [BuiltInCommands.HelpCommand]
*/
public val description: String
@ -99,7 +98,6 @@ public suspend inline fun Command.onCommand(sender: CommandSender, args: Message
* @see RawCommand
*/
public abstract class AbstractCommand
@OptIn(ExperimentalPermission::class)
@JvmOverloads constructor(
/** 指令拥有者. */
public override val owner: CommandOwner,
@ -107,7 +105,7 @@ public abstract class AbstractCommand
description: String = "<no description available>",
parentPermission: Permission = owner.parentPermission,
/** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */
public override val prefixOptional: Boolean = false
public override val prefixOptional: Boolean = false,
) : Command {
public override val description: String = description.trimIndent()
public override val names: Array<out String> =
@ -115,6 +113,5 @@ public abstract class AbstractCommand
list.firstOrNull { !it.isValidSubName() }?.let { error("Invalid name: $it") }
}.toTypedArray()
@OptIn(ExperimentalPermission::class)
public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) }
}

View File

@ -10,7 +10,6 @@
package net.mamoe.mirai.console.command
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregisterAllCommands
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
@ -24,7 +23,6 @@ import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
*
* @see JvmPlugin 是一个 [CommandOwner]
*/
@OptIn(ExperimentalPermission::class)
public interface CommandOwner : PermissionIdNamespace {
/**
* 在构造指令时, [Command.permission] 默认会使用 [parentPermission] 作为 [Permission.parent]

View File

@ -9,7 +9,7 @@
@file:Suppress(
"NOTHING_TO_INLINE", "INAPPLICABLE_JVM_NAME", "FunctionName", "SuspendFunctionOnCoroutineScope",
"unused", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER"
"unused"
)
package net.mamoe.mirai.console.command
@ -33,7 +33,6 @@ import net.mamoe.mirai.console.internal.command.qualifiedNameOrTip
import net.mamoe.mirai.console.internal.data.castOrNull
import net.mamoe.mirai.console.internal.plugin.rootCauseOrSelf
import net.mamoe.mirai.console.permission.AbstractPermitteeId
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.Permittee
import net.mamoe.mirai.console.permission.PermitteeId
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
@ -47,7 +46,6 @@ import net.mamoe.mirai.message.data.PlainText
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.coroutines.CoroutineContext
import kotlin.internal.LowPriorityInOverloadResolution
/**
* 指令发送者.
@ -136,7 +134,6 @@ import kotlin.internal.LowPriorityInOverloadResolution
* @see toCommandSender
* @see asCommandSender
*/
@OptIn(ExperimentalPermission::class)
public interface CommandSender : CoroutineScope, Permittee {
/**
* 与这个 [CommandSender] 相关的 [Bot].
@ -441,7 +438,6 @@ public fun CommandSender.isNotUser(): Boolean {
* @return [ifIsConsole] [ifIsUser] 执行结果.
*/
@JvmSynthetic
@LowPriorityInOverloadResolution
public inline fun <R> CommandSender.fold(
ifIsConsole: ConsoleCommandSender.() -> R,
ifIsUser: UserCommandSender.() -> R,
@ -464,7 +460,7 @@ public inline fun <R> CommandSender.fold(
*
* ### 实验性 API
*
* 这是预览版本 API. 如果你对 [UserCommandSender.fold] 有建议, 请在 [mamoe/mirai-console/issues](https://github.com/mamoe/mirai-console/issues/new) 提交.
* 这是预览版本 API. 如果你对 [UserCommandSender.foldContext] 有建议, 请在 [mamoe/mirai-console/issues](https://github.com/mamoe/mirai-console/issues/new) 提交.
*
* @return [inGroup] [inPrivate] 执行结果.
*/
@ -517,7 +513,6 @@ public abstract class ConsoleCommandSender @ConsoleFrontEndImplementation constr
public final override val name: String get() = NAME
public final override fun toString(): String = NAME
@ExperimentalPermission
public final override val permitteeId: AbstractPermitteeId.Console = AbstractPermitteeId.Console
public companion object INSTANCE : ConsoleCommandSender(), CoroutineScope {
@ -615,7 +610,6 @@ public open class FriendCommandSender internal constructor(
public override val subject: Contact get() = user
public override fun toString(): String = "FriendCommandSender($user)"
@ExperimentalPermission
public override val permitteeId: PermitteeId = AbstractPermitteeId.ExactFriend(user.id)
@JvmBlockingBridge
@ -638,7 +632,6 @@ public open class MemberCommandSender internal constructor(
public override val subject: Group get() = group
public override fun toString(): String = "MemberCommandSender($user)"
@ExperimentalPermission
public override val permitteeId: PermitteeId = AbstractPermitteeId.ExactMember(group.id, user.id)
@JvmBlockingBridge
@ -661,7 +654,6 @@ public open class TempCommandSender internal constructor(
public override val subject: Contact get() = group
public override fun toString(): String = "TempCommandSender($user)"
@ExperimentalPermission
public override val permitteeId: PermitteeId =
AbstractPermitteeId.ExactTemp(user.group.id, user.id)

View File

@ -20,9 +20,7 @@ package net.mamoe.mirai.console.command
import net.mamoe.mirai.console.command.description.*
import net.mamoe.mirai.console.internal.command.AbstractReflectionCommand
import net.mamoe.mirai.console.internal.command.CompositeCommandSubCommandAnnotationResolver
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.Permission
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
import net.mamoe.mirai.message.data.MessageChain
import kotlin.annotation.AnnotationRetention.RUNTIME
import kotlin.annotation.AnnotationTarget.FUNCTION
@ -81,14 +79,13 @@ import kotlin.annotation.AnnotationTarget.FUNCTION
*
* @see buildCommandArgumentContext
*/
@ConsoleExperimentalApi
public abstract class CompositeCommand @OptIn(ExperimentalPermission::class) constructor(
public abstract class CompositeCommand(
owner: CommandOwner,
vararg names: String,
description: String = "no description available",
parentPermission: Permission = owner.parentPermission,
prefixOptional: Boolean = false,
overrideContext: CommandArgumentContext = EmptyCommandArgumentContext
overrideContext: CommandArgumentContext = EmptyCommandArgumentContext,
) : Command, AbstractReflectionCommand(owner, names, description, parentPermission, prefixOptional),
CommandArgumentContextAware {

View File

@ -15,7 +15,6 @@ 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.createOrFindCommandPermission
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.Permission
import net.mamoe.mirai.message.data.MessageChain
@ -30,7 +29,7 @@ import net.mamoe.mirai.message.data.MessageChain
* @see SimpleCommand 简单指令
* @see CompositeCommand 复合指令
*/
public abstract class RawCommand @OptIn(ExperimentalPermission::class) constructor(
public abstract class RawCommand(
/**
* 指令拥有者.
* @see CommandOwner
@ -45,9 +44,8 @@ public abstract class RawCommand @OptIn(ExperimentalPermission::class) construct
/** 指令父权限 */
parentPermission: Permission = owner.parentPermission,
/** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */
public override val prefixOptional: Boolean = false
public override val prefixOptional: Boolean = false,
) : Command {
@OptIn(ExperimentalPermission::class)
public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) }
/**

View File

@ -22,7 +22,6 @@ import net.mamoe.mirai.console.command.description.*
import net.mamoe.mirai.console.command.java.JSimpleCommand
import net.mamoe.mirai.console.internal.command.AbstractReflectionCommand
import net.mamoe.mirai.console.internal.command.SimpleCommandSubCommandAnnotationResolver
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.Permission
import net.mamoe.mirai.message.data.MessageChain
@ -49,13 +48,13 @@ import net.mamoe.mirai.message.data.MessageChain
* @see JSimpleCommand Java 实现
* @see [CommandManager.executeCommand]
*/
public abstract class SimpleCommand @OptIn(ExperimentalPermission::class) constructor(
public abstract class SimpleCommand(
owner: CommandOwner,
vararg names: String,
description: String = "no description available",
parentPermission: Permission = owner.parentPermission,
prefixOptional: Boolean = false,
overrideContext: CommandArgumentContext = EmptyCommandArgumentContext
overrideContext: CommandArgumentContext = EmptyCommandArgumentContext,
) : Command, AbstractReflectionCommand(owner, names, description, parentPermission, prefixOptional),
CommandArgumentContextAware {

View File

@ -16,7 +16,6 @@ import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.command.CompositeCommand
import net.mamoe.mirai.console.command.SimpleCommand
import net.mamoe.mirai.console.command.description.CommandArgumentContext.ParserPair
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.PermissionId
import net.mamoe.mirai.console.permission.PermitteeId
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
@ -66,7 +65,6 @@ public interface CommandArgumentContext {
/**
* 内建的默认 [CommandArgumentParser]
*/
@OptIn(ExperimentalPermission::class)
public object Builtins : CommandArgumentContext by (buildCommandArgumentContext {
Int::class with IntArgumentParser
Byte::class with ByteArgumentParser
@ -85,7 +83,7 @@ public interface CommandArgumentContext {
Bot::class with ExistingBotArgumentParser
PermissionId::class with PermissionIdArgumentParser
PermitteeId::class with PermissibleIdentifierArgumentParser
PermitteeId::class with PermitteeIdArgumentParser
})
}

View File

@ -14,7 +14,6 @@ import net.mamoe.mirai.console.command.*
import net.mamoe.mirai.console.command.CommandSender.Companion.asCommandSender
import net.mamoe.mirai.console.internal.command.fuzzySearchMember
import net.mamoe.mirai.console.permission.AbstractPermitteeId
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.PermissionId
import net.mamoe.mirai.console.permission.PermitteeId
import net.mamoe.mirai.contact.*
@ -308,7 +307,6 @@ public object ExistingMemberArgumentParser : InternalCommandArgumentParserExtens
}
}
@ExperimentalPermission
public object PermissionIdArgumentParser : CommandArgumentParser<PermissionId> {
override fun parse(raw: String, sender: CommandSender): PermissionId {
return kotlin.runCatching { PermissionId.parseFromString(raw) }.getOrElse {
@ -317,8 +315,7 @@ public object PermissionIdArgumentParser : CommandArgumentParser<PermissionId> {
}
}
@ExperimentalPermission
public object PermissibleIdentifierArgumentParser : CommandArgumentParser<PermitteeId> {
public object PermitteeIdArgumentParser : CommandArgumentParser<PermitteeId> {
override fun parse(raw: String, sender: CommandSender): PermitteeId {
return if (raw == "~") sender.permitteeId
else kotlin.runCatching { AbstractPermitteeId.parseFromString(raw) }.getOrElse {

View File

@ -14,9 +14,7 @@ import net.mamoe.mirai.console.command.CommandManager
import net.mamoe.mirai.console.command.CommandOwner
import net.mamoe.mirai.console.command.CompositeCommand
import net.mamoe.mirai.console.command.description.buildCommandArgumentContext
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.Permission
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
/**
* 复合指令. 指令注册时候会通过反射构造指令解析器.
@ -68,8 +66,7 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi
*
* @see buildCommandArgumentContext
*/
@ConsoleExperimentalApi
public abstract class JCompositeCommand @OptIn(ExperimentalPermission::class)
public abstract class JCompositeCommand
@JvmOverloads constructor(
owner: CommandOwner,
vararg names: String,
@ -79,7 +76,6 @@ public abstract class JCompositeCommand @OptIn(ExperimentalPermission::class)
public final override var description: String = "<no descriptions given>"
protected set
@OptIn(ExperimentalPermission::class)
public final override var permission: Permission = super.permission
protected set

View File

@ -14,7 +14,6 @@ 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.createOrFindCommandPermission
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.Permission
import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.message.data.SingleMessage
@ -45,7 +44,7 @@ import net.mamoe.mirai.message.data.SingleMessage
*
* @see JRawCommand
*/
public abstract class JRawCommand @OptIn(ExperimentalPermission::class)
public abstract class JRawCommand
@JvmOverloads constructor(
/**
* 指令拥有者.
@ -65,7 +64,6 @@ public abstract class JRawCommand @OptIn(ExperimentalPermission::class)
protected set
/** 指令权限 */
@ExperimentalPermission
public final override var permission: Permission = createOrFindCommandPermission(parentPermission)
protected set

View File

@ -14,7 +14,6 @@ import net.mamoe.mirai.console.command.CommandManager.INSTANCE.executeCommand
import net.mamoe.mirai.console.command.CommandOwner
import net.mamoe.mirai.console.command.SimpleCommand
import net.mamoe.mirai.console.command.description.CommandArgumentContext
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.Permission
/**
@ -40,7 +39,7 @@ import net.mamoe.mirai.console.permission.Permission
* @see SimpleCommand
* @see [CommandManager.executeCommand]
*/
public abstract class JSimpleCommand @OptIn(ExperimentalPermission::class) constructor(
public abstract class JSimpleCommand(
owner: CommandOwner,
vararg names: String,
basePermission: Permission,
@ -48,7 +47,6 @@ public abstract class JSimpleCommand @OptIn(ExperimentalPermission::class) const
public override var description: String = super.description
protected set
@ExperimentalPermission
public override var permission: Permission = super.permission
protected set
public override var prefixOptional: Boolean = super.prefixOptional

View File

@ -7,7 +7,6 @@ import net.mamoe.mirai.console.extensions.PermissionServiceProvider
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector.ExtensionPoint.selectSingleton
import net.mamoe.mirai.console.internal.data.kClassQualifiedNameOrTip
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.PermissionService
import net.mamoe.mirai.console.plugin.Plugin
import net.mamoe.mirai.console.plugin.name
@ -67,7 +66,6 @@ public class ScopedComponentStorage(
/**
* 注册一个 [PermissionService]
*/
@ExperimentalPermission
public fun contributePermissionService(
lazyInstance: () -> PermissionService<*>,
) {

View File

@ -3,7 +3,6 @@ package net.mamoe.mirai.console.extensions
import net.mamoe.mirai.console.extension.AbstractExtensionPoint
import net.mamoe.mirai.console.extension.SingletonExtension
import net.mamoe.mirai.console.extension.SingletonExtensionPoint
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.PermissionService
/**
@ -11,17 +10,14 @@ import net.mamoe.mirai.console.permission.PermissionService
*
* 当插件注册 [PermissionService] , 默认会使用插件的 [PermissionService].
*/
@ExperimentalPermission
public interface PermissionServiceProvider : SingletonExtension<PermissionService<*>> {
public companion object ExtensionPoint :
AbstractExtensionPoint<PermissionServiceProvider>(PermissionServiceProvider::class),
SingletonExtensionPoint<PermissionServiceProvider>
}
@ExperimentalPermission
public class PermissionServiceProviderImpl(override val instance: PermissionService<*>) : PermissionServiceProvider
@ExperimentalPermission
public class LazyPermissionServiceProviderImpl(initializer: () -> PermissionService<*>) : PermissionServiceProvider {
override val instance: PermissionService<*> by lazy(initializer)
}

View File

@ -39,7 +39,6 @@ import net.mamoe.mirai.console.internal.extensions.BuiltInSingletonExtensionSele
import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService
import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl
import net.mamoe.mirai.console.internal.util.autoHexToBytes
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.PermissionService
import net.mamoe.mirai.console.permission.PermissionService.Companion.grantPermission
import net.mamoe.mirai.console.permission.RootPermission
@ -93,7 +92,6 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
override fun createLogger(identity: String?): MiraiLogger = instance.createLogger(identity)
@OptIn(ConsoleExperimentalApi::class, ExperimentalPermission::class)
@Suppress("RemoveRedundantBackticks")
internal fun doStart() {
phase `greeting`@{

View File

@ -16,7 +16,6 @@ import net.mamoe.mirai.console.command.Command.Companion.primaryName
import net.mamoe.mirai.console.command.description.CommandArgumentContext
import net.mamoe.mirai.console.command.description.CommandArgumentContextAware
import net.mamoe.mirai.console.internal.data.kClassQualifiedNameOrTip
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.Permission
import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission
import net.mamoe.mirai.message.data.*
@ -46,13 +45,13 @@ internal object SimpleCommandSubCommandAnnotationResolver :
baseCommand.names
}
internal abstract class AbstractReflectionCommand @OptIn(ExperimentalPermission::class)
internal abstract class AbstractReflectionCommand
@JvmOverloads constructor(
owner: CommandOwner,
names: Array<out String>,
description: String = "<no description available>",
parentPermission: Permission = owner.parentPermission,
prefixOptional: Boolean = false
prefixOptional: Boolean = false,
) : Command, AbstractCommand(
owner,
names = names,
@ -120,27 +119,26 @@ internal abstract class AbstractReflectionCommand @OptIn(ExperimentalPermission:
}
}
internal class DefaultSubCommandDescriptor @OptIn(ExperimentalPermission::class) constructor(
internal class DefaultSubCommandDescriptor(
val description: String,
val permission: Permission,
val onCommand: suspend (sender: CommandSender, rawArgs: MessageChain) -> Unit
val onCommand: suspend (sender: CommandSender, rawArgs: MessageChain) -> Unit,
)
internal inner class SubCommandDescriptor @OptIn(ExperimentalPermission::class) constructor(
internal inner class SubCommandDescriptor(
val names: Array<out String>,
val params: Array<CommandParameter<*>>,
val description: String,
val permission: Permission,
val onCommand: suspend (sender: CommandSender, parsedArgs: Array<out Any>) -> Boolean,
val context: CommandArgumentContext
val context: CommandArgumentContext,
) {
val usage: String = createUsage(this@AbstractReflectionCommand)
@OptIn(ExperimentalPermission::class)
internal suspend fun parseAndExecute(
sender: CommandSender,
argsWithSubCommandNameNotRemoved: MessageChain,
removeSubName: Boolean
removeSubName: Boolean,
) {
val args = parseArgs(sender, argsWithSubCommandNameNotRemoved, if (removeSubName) 1 else 0)
if (!this.permission.testPermission(sender)) {
@ -251,7 +249,6 @@ internal fun AbstractReflectionCommand.SubCommandDescriptor.createUsage(baseComm
appendLine()
}.trimEnd()
@OptIn(ExperimentalPermission::class)
internal fun AbstractReflectionCommand.createSubCommand(
function: KFunction<*>,
context: CommandArgumentContext

View File

@ -10,12 +10,10 @@
package net.mamoe.mirai.console.internal.command
import net.mamoe.mirai.console.command.*
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission
import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.message.data.asMessageChain
@OptIn(ExperimentalPermission::class)
@JvmSynthetic
@Throws(CommandExecutionException::class)
internal suspend fun CommandSender.executeCommandInternal(

View File

@ -11,7 +11,6 @@ package net.mamoe.mirai.console.internal.command
import net.mamoe.mirai.console.command.Command
import net.mamoe.mirai.console.command.Command.Companion.primaryName
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.Permission
import net.mamoe.mirai.console.permission.PermissionService
import net.mamoe.mirai.contact.Group
@ -53,56 +52,6 @@ internal fun String.fuzzyMatchWith(target: String): Double {
return match.toDouble() / (longerLength + (shorterLength - match))
}
internal inline fun <T : Any> Collection<T>.fuzzySearch(
target: String,
crossinline index: (T) -> String
): T? {
var maxElement: T? = null
var max = 0.0
for (t in this) {
val r = index(t).fuzzyMatchWith(target)
if (r > max) {
maxElement = t
max = r
}
}
if (max >= 0.7) {
return maxElement
}
return null
}
/**
* 模糊搜索一个List中index最接近target的东西
* 并且确保target是唯一的
* 如搜索index为XXXXYY list中同时存在XXXXYYY XXXXYYYY 将返回null
*/
internal inline fun <T : Any> Collection<T>.fuzzySearchOnly(
target: String,
index: (T) -> String
): T? {
var potential: T? = null
var rate = 0.0
var collide = 0
this.forEach {
with(index(it).fuzzyMatchWith(target)) {
if (this > rate) {
rate = this
potential = it
}
if (this == 1.0) {
collide++
}
if (collide > 1) {
return null//collide
}
}
}
return potential
}
/**
* @return candidates
@ -138,7 +87,6 @@ internal fun Group.fuzzySearchMember(
}
}
@OptIn(ExperimentalPermission::class)
internal fun Command.createOrFindCommandPermission(parent: Permission): Permission {
val id = owner.permissionId(primaryName)
return PermissionService.INSTANCE[id] ?: PermissionService.INSTANCE.register(id, description, parent)

View File

@ -14,7 +14,6 @@ import net.mamoe.mirai.console.data.PluginData
import net.mamoe.mirai.console.data.PluginDataHolder
import net.mamoe.mirai.console.data.PluginDataStorage
import net.mamoe.mirai.console.internal.command.qualifiedNameOrTip
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.SilentLogger
@ -65,7 +64,6 @@ internal open class MultiFilePluginDataStorageImpl(
@ConsoleExperimentalApi
public override fun store(holder: PluginDataHolder, instance: PluginData) {
@OptIn(ExperimentalPermission::class)
val yaml =/* if (instance.saveName == "PermissionService") Json {
prettyPrint = true
ignoreUnknownKeys = true

View File

@ -13,10 +13,6 @@ import net.mamoe.mirai.console.data.PluginDataExtensions
import net.mamoe.mirai.console.permission.*
import net.mamoe.mirai.console.permission.PermitteeId.Companion.hasChild
/**
*
*/
@ExperimentalPermission
internal abstract class AbstractConcurrentPermissionService<P : Permission> : PermissionService<P> {
protected abstract val permissions: MutableMap<PermissionId, P>
protected abstract val grantedPermissionsMap: PluginDataExtensions.NotNullMutableMap<PermissionId, MutableCollection<PermitteeId>>

View File

@ -21,7 +21,6 @@ import kotlin.reflect.KClass
import kotlin.reflect.full.isSuperclassOf
@Suppress("unused") // don't pollute top-level
@OptIn(ExperimentalPermission::class)
internal fun PermissionService<*>.checkType(permissionType: KClass<out Permission>): PermissionService<Permission> {
require(this.permissionType.isSuperclassOf(permissionType)) {
"Custom-constructed Permission instance is not allowed (Required ${this.permissionType}, found ${permissionType}. " +
@ -32,7 +31,6 @@ internal fun PermissionService<*>.checkType(permissionType: KClass<out Permissio
return this as PermissionService<Permission>
}
@ExperimentalPermission
internal object AllPermitPermissionService : PermissionService<PermissionImpl> {
private val all = ConcurrentHashMap<PermissionId, PermissionImpl>()
override val permissionType: KClass<PermissionImpl> get() = PermissionImpl::class
@ -65,10 +63,8 @@ internal object AllPermitPermissionService : PermissionService<PermissionImpl> {
}
@Suppress("DEPRECATION")
@OptIn(ExperimentalPermission::class)
private val RootPermissionImpl = PermissionImpl(PermissionId("*", "*"), "The root permission").also { it.parent = it }
@ExperimentalPermission
internal object AllDenyPermissionService : PermissionService<PermissionImpl> {
private val all = ConcurrentHashMap<PermissionId, PermissionImpl>()
override val permissionType: KClass<PermissionImpl>
@ -101,11 +97,9 @@ internal object AllDenyPermissionService : PermissionService<PermissionImpl> {
}
}
@ExperimentalPermission
internal object BuiltInPermissionService : AbstractConcurrentPermissionService<PermissionImpl>(),
PermissionService<PermissionImpl> {
@ExperimentalPermission
override val permissionType: KClass<PermissionImpl>
get() = PermissionImpl::class
override val permissions: ConcurrentHashMap<PermissionId, PermissionImpl> = ConcurrentHashMap()
@ -122,7 +116,6 @@ internal object BuiltInPermissionService : AbstractConcurrentPermissionService<P
ConcurrentSaveData("PermissionService")
@Suppress("RedundantVisibilityModifier")
@ExperimentalPermission
internal class ConcurrentSaveData private constructor(
public override val saveName: String,
@Suppress("UNUSED_PARAMETER") primaryConstructorMark: Any?,
@ -145,7 +138,6 @@ internal object BuiltInPermissionService : AbstractConcurrentPermissionService<P
* [Permission] 的简单实现
*/
@Serializable
@ExperimentalPermission
internal data class PermissionImpl @Deprecated("Only for Root") constructor(
override val id: PermissionId,
override val description: String,

View File

@ -13,9 +13,7 @@ package net.mamoe.mirai.console.internal.permission
import net.mamoe.mirai.console.permission.AbstractPermitteeId
import net.mamoe.mirai.console.permission.AbstractPermitteeId.*
import net.mamoe.mirai.console.permission.ExperimentalPermission
@OptIn(ExperimentalPermission::class)
internal fun parseFromStringImpl(string: String): AbstractPermitteeId {
val str = string.trim { it.isWhitespace() }.toLowerCase()
if (str == "console") return Console

View File

@ -16,9 +16,7 @@ import net.mamoe.mirai.console.MiraiConsole
import net.mamoe.mirai.console.data.runCatchingLog
import net.mamoe.mirai.console.extension.ScopedComponentStorage
import net.mamoe.mirai.console.internal.data.mkdir
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.PermissionService
import net.mamoe.mirai.console.permission.PermissionService.Companion.allocatePermissionIdForPlugin
import net.mamoe.mirai.console.plugin.Plugin
@ -50,7 +48,6 @@ internal abstract class JvmPluginInternal(
@Suppress("LeakingThis")
internal val componentStorage: ScopedComponentStorage = ScopedComponentStorage(this)
@OptIn(ExperimentalPermission::class)
final override val parentPermission: Permission by lazy {
PermissionService.INSTANCE.register(
PermissionService.INSTANCE.allocatePermissionIdForPlugin(name, "*"),
@ -64,11 +61,6 @@ internal abstract class JvmPluginInternal(
final override fun getResourceAsStream(path: String): InputStream? =
resourceContainerDelegate.getResourceAsStream(path)
@OptIn(ExperimentalPermission::class)
override fun permissionId(id: String): PermissionId {
return PermissionId(description.name, id)
}
// region JvmPlugin
final override val logger: MiraiLogger by lazy {
JarPluginLoaderImpl.logger.runCatchingLog {

View File

@ -25,14 +25,26 @@ import kotlin.reflect.KClass
* [PermissionServiceProvider]
*/
public interface PermissionService<P : Permission> {
@ExperimentalPermission
/**
* [P] 的类型
*/
public val permissionType: KClass<P>
/**
* [RootPermission] 的实现
*/
public val rootPermission: P
///////////////////////////////////////////////////////////////////////////
/**
* 获取一个已经 [注册][register] 了的 [P]
*/
public operator fun get(id: PermissionId): P?
/**
* 获取所有已注册的指令列表. 应保证线程安全.
*/
public fun getRegisteredPermissions(): Sequence<P>
/**

View File

@ -15,6 +15,7 @@ import net.mamoe.mirai.console.data.AutoSavePluginDataHolder
import net.mamoe.mirai.console.data.PluginConfig
import net.mamoe.mirai.console.data.PluginData
import net.mamoe.mirai.console.internal.plugin.JvmPluginInternal
import net.mamoe.mirai.console.permission.PermissionId
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
import net.mamoe.mirai.utils.minutesToMillis
import net.mamoe.mirai.utils.secondsToMillis
@ -36,6 +37,8 @@ public abstract class AbstractJvmPlugin @JvmOverloads constructor(
public final override val loader: JarPluginLoader get() = super<JvmPluginInternal>.loader
public final override fun permissionId(id: String): PermissionId = PermissionId(description.id, id)
/**
* 重载 [PluginData]
*

View File

@ -19,7 +19,6 @@ package net.mamoe.mirai.console.plugin.jvm
import kotlinx.coroutines.CoroutineScope
import net.mamoe.mirai.console.extension.ScopedComponentStorage
import net.mamoe.mirai.console.permission.ExperimentalPermission
import net.mamoe.mirai.console.permission.PermissionIdNamespace
import net.mamoe.mirai.console.plugin.Plugin
import net.mamoe.mirai.console.plugin.PluginFileExtensions
@ -38,7 +37,6 @@ import net.mamoe.mirai.utils.MiraiLogger
* @see JvmPlugin 支持文件系统扩展
* @see ResourceContainer 支持资源获取 ( Jar 中的资源文件)
*/
@OptIn(ExperimentalPermission::class)
public interface JvmPlugin : Plugin, CoroutineScope,
PluginFileExtensions, ResourceContainer, PermissionIdNamespace {

View File

@ -7,18 +7,9 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
/*
* Copyright 2019-2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
object Versions {
const val core = "1.2.3"
const val console = "1.0-M4-dev-7"
const val console = "1.0-M4-dev-8"
const val consoleGraphical = "0.0.7"
const val consoleTerminal = "0.1.0"
const val consolePure = console