Add missing opt-in annotations

This commit is contained in:
Him188 2020-09-09 22:00:25 +08:00
parent d3e3db9662
commit 703c4feae1
9 changed files with 25 additions and 9 deletions

View File

@ -55,6 +55,7 @@ public interface Command {
/**
* 指令权限
*/
@ExperimentalPermission
public val permission: Permission
/**
@ -100,6 +101,7 @@ 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,

View File

@ -24,12 +24,14 @@ import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
*
* @see JvmPlugin 是一个 [CommandOwner]
*/
@OptIn(ExperimentalPermission::class)
public interface CommandOwner : PermissionIdNamespace {
/**
* [PermissionIdNamespace] 拥有的指令都默认将 [basePermission] 作为父权限.
*
* TODO document
*/
@ExperimentalPermission
public val basePermission: PermissionId
}
@ -37,6 +39,7 @@ public interface CommandOwner : PermissionIdNamespace {
* 代表控制台所有者. 所有的 mirai-console 内建的指令都属于 [ConsoleCommandOwner].
*/
internal object ConsoleCommandOwner : CommandOwner {
@ExperimentalPermission
override val basePermission: PermissionId get() = BasePermission.id
@ExperimentalPermission

View File

@ -82,7 +82,7 @@ import kotlin.annotation.AnnotationTarget.FUNCTION
* @see buildCommandArgumentContext
*/
@ConsoleExperimentalAPI
public abstract class CompositeCommand(
public abstract class CompositeCommand @OptIn(ExperimentalPermission::class) constructor(
owner: CommandOwner,
vararg names: String,
description: String = "no description available",

View File

@ -31,7 +31,7 @@ import net.mamoe.mirai.message.data.MessageChain
* @see SimpleCommand 简单指令
* @see CompositeCommand 复合指令
*/
public abstract class RawCommand(
public abstract class RawCommand @OptIn(ExperimentalPermission::class) constructor(
/**
* 指令拥有者.
* @see CommandOwner

View File

@ -22,6 +22,7 @@ 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.PermissionId
import net.mamoe.mirai.message.data.MessageChain
@ -48,7 +49,7 @@ import net.mamoe.mirai.message.data.MessageChain
* @see JSimpleCommand Java 实现
* @see [CommandManager.executeCommand]
*/
public abstract class SimpleCommand(
public abstract class SimpleCommand @OptIn(ExperimentalPermission::class) constructor(
owner: CommandOwner,
vararg names: String,
description: String = "no description available",

View File

@ -69,7 +69,8 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalAPI
* @see buildCommandArgumentContext
*/
@ConsoleExperimentalAPI
public abstract class JCompositeCommand @JvmOverloads constructor(
public abstract class JCompositeCommand @OptIn(ExperimentalPermission::class)
@JvmOverloads constructor(
owner: CommandOwner,
vararg names: String,
parentPermission: PermissionId = owner.basePermission,

View File

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

View File

@ -14,6 +14,7 @@ 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
import net.mamoe.mirai.console.permission.PermissionId
@ -40,13 +41,15 @@ import net.mamoe.mirai.console.permission.PermissionId
* @see SimpleCommand
* @see [CommandManager.executeCommand]
*/
public abstract class JSimpleCommand(
public abstract class JSimpleCommand @OptIn(ExperimentalPermission::class) constructor(
owner: CommandOwner,
vararg names: String,
basePermission: PermissionId,
) : SimpleCommand(owner, *names, basePermission = basePermission) {
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

@ -44,7 +44,8 @@ internal object SimpleCommandSubCommandAnnotationResolver :
baseCommand.names
}
internal abstract class AbstractReflectionCommand @JvmOverloads constructor(
internal abstract class AbstractReflectionCommand @OptIn(ExperimentalPermission::class)
@JvmOverloads constructor(
owner: CommandOwner,
names: Array<out String>,
description: String = "<no description available>",
@ -117,13 +118,13 @@ internal abstract class AbstractReflectionCommand @JvmOverloads constructor(
}
}
internal class DefaultSubCommandDescriptor(
internal class DefaultSubCommandDescriptor @OptIn(ExperimentalPermission::class) constructor(
val description: String,
val permission: Permission,
val onCommand: suspend (sender: CommandSender, rawArgs: MessageChain) -> Unit
)
internal inner class SubCommandDescriptor(
internal inner class SubCommandDescriptor @OptIn(ExperimentalPermission::class) constructor(
val names: Array<out String>,
val params: Array<CommandParameter<*>>,
val description: String,
@ -132,6 +133,8 @@ internal abstract class AbstractReflectionCommand @JvmOverloads constructor(
val context: CommandArgumentContext
) {
val usage: String = createUsage(this@AbstractReflectionCommand)
@OptIn(ExperimentalPermission::class)
internal suspend fun parseAndExecute(
sender: CommandSender,
argsWithSubCommandNameNotRemoved: MessageChain,