mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
1.0-RC Code review
This commit is contained in:
parent
75be7fec02
commit
d2dffef44c
@ -47,7 +47,7 @@ public annotation class ConsoleFrontEndImplementation
|
|||||||
/**
|
/**
|
||||||
* 实现 [MiraiConsole] 的接口
|
* 实现 [MiraiConsole] 的接口
|
||||||
*
|
*
|
||||||
* **注意**: 随着 Console 的更新, 在版本号 `x.y.z` 的 `y` 修改时此接口可能就会变动. 意味着前端实现着需要跟随 Console 更新.
|
* **注意**: 随着 Console 的更新, 在版本号 `x.y.z` 的 `y` 修改时此接口可能就会发生 ABI 变动. 意味着前端实现着需要跟随 Console 更新.
|
||||||
*
|
*
|
||||||
* @see MiraiConsoleImplementation.start 启动
|
* @see MiraiConsoleImplementation.start 启动
|
||||||
*/
|
*/
|
||||||
|
@ -7,9 +7,12 @@
|
|||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("unused")
|
||||||
|
|
||||||
package net.mamoe.mirai.console.command
|
package net.mamoe.mirai.console.command
|
||||||
|
|
||||||
import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission
|
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
|
||||||
|
import net.mamoe.mirai.console.internal.command.findOrCreateCommandPermission
|
||||||
import net.mamoe.mirai.console.permission.Permission
|
import net.mamoe.mirai.console.permission.Permission
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,14 +29,17 @@ public abstract class AbstractCommand
|
|||||||
public final override val secondaryNames: Array<out String>,
|
public final override val secondaryNames: Array<out String>,
|
||||||
public override val description: String = "<no description available>",
|
public override val description: String = "<no description available>",
|
||||||
parentPermission: Permission = owner.parentPermission,
|
parentPermission: Permission = owner.parentPermission,
|
||||||
/** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */
|
|
||||||
public override val prefixOptional: Boolean = false,
|
|
||||||
) : Command {
|
) : Command {
|
||||||
|
|
||||||
|
@ExperimentalCommandDescriptors
|
||||||
|
override val prefixOptional: Boolean
|
||||||
|
get() = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Command.checkCommandName(primaryName)
|
Command.checkCommandName(primaryName)
|
||||||
secondaryNames.forEach(Command.Companion::checkCommandName)
|
secondaryNames.forEach(Command.Companion::checkCommandName)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override val usage: String get() = description
|
public override val usage: String get() = description
|
||||||
public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) }
|
public override val permission: Permission by lazy { findOrCreateCommandPermission(parentPermission) }
|
||||||
}
|
}
|
@ -77,6 +77,9 @@ public interface Command {
|
|||||||
* 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选.
|
* 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选.
|
||||||
*
|
*
|
||||||
* 会影响聊天语境中的解析.
|
* 会影响聊天语境中的解析.
|
||||||
|
*
|
||||||
|
* #### 实验性 API
|
||||||
|
* 由于指令解析允许被扩展, 此属性可能不适用所有解析器, 因此还未决定是否保留.
|
||||||
*/
|
*/
|
||||||
@ExperimentalCommandDescriptors
|
@ExperimentalCommandDescriptors
|
||||||
@ConsoleExperimentalApi
|
@ConsoleExperimentalApi
|
||||||
|
@ -21,6 +21,8 @@ import kotlin.contracts.contract
|
|||||||
/**
|
/**
|
||||||
* 指令的执行返回
|
* 指令的执行返回
|
||||||
*
|
*
|
||||||
|
* 注意: 现阶段
|
||||||
|
*
|
||||||
* @see CommandExecuteStatus
|
* @see CommandExecuteStatus
|
||||||
*/
|
*/
|
||||||
@ConsoleExperimentalApi("Not yet implemented")
|
@ConsoleExperimentalApi("Not yet implemented")
|
||||||
@ -144,12 +146,14 @@ public sealed class CommandExecuteResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalCommandDescriptors
|
||||||
@Suppress("RemoveRedundantQualifierName")
|
@Suppress("RemoveRedundantQualifierName")
|
||||||
public typealias CommandExecuteStatus = CommandExecuteResult.CommandExecuteStatus
|
public typealias CommandExecuteStatus = CommandExecuteResult.CommandExecuteStatus
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当 [this] 为 [CommandExecuteResult.Success] 时返回 `true`
|
* 当 [this] 为 [CommandExecuteResult.Success] 时返回 `true`
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalCommandDescriptors
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public fun CommandExecuteResult.isSuccess(): Boolean {
|
public fun CommandExecuteResult.isSuccess(): Boolean {
|
||||||
contract {
|
contract {
|
||||||
@ -162,6 +166,7 @@ public fun CommandExecuteResult.isSuccess(): Boolean {
|
|||||||
/**
|
/**
|
||||||
* 当 [this] 为 [CommandExecuteResult.IllegalArgument] 时返回 `true`
|
* 当 [this] 为 [CommandExecuteResult.IllegalArgument] 时返回 `true`
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalCommandDescriptors
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public fun CommandExecuteResult.isIllegalArgument(): Boolean {
|
public fun CommandExecuteResult.isIllegalArgument(): Boolean {
|
||||||
contract {
|
contract {
|
||||||
@ -174,6 +179,7 @@ public fun CommandExecuteResult.isIllegalArgument(): Boolean {
|
|||||||
/**
|
/**
|
||||||
* 当 [this] 为 [CommandExecuteResult.ExecutionFailed] 时返回 `true`
|
* 当 [this] 为 [CommandExecuteResult.ExecutionFailed] 时返回 `true`
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalCommandDescriptors
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public fun CommandExecuteResult.isExecutionException(): Boolean {
|
public fun CommandExecuteResult.isExecutionException(): Boolean {
|
||||||
contract {
|
contract {
|
||||||
@ -186,6 +192,7 @@ public fun CommandExecuteResult.isExecutionException(): Boolean {
|
|||||||
/**
|
/**
|
||||||
* 当 [this] 为 [CommandExecuteResult.PermissionDenied] 时返回 `true`
|
* 当 [this] 为 [CommandExecuteResult.PermissionDenied] 时返回 `true`
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalCommandDescriptors
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public fun CommandExecuteResult.isPermissionDenied(): Boolean {
|
public fun CommandExecuteResult.isPermissionDenied(): Boolean {
|
||||||
contract {
|
contract {
|
||||||
@ -198,6 +205,7 @@ public fun CommandExecuteResult.isPermissionDenied(): Boolean {
|
|||||||
/**
|
/**
|
||||||
* 当 [this] 为 [CommandExecuteResult.UnresolvedCall] 时返回 `true`
|
* 当 [this] 为 [CommandExecuteResult.UnresolvedCall] 时返回 `true`
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalCommandDescriptors
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public fun CommandExecuteResult.isCommandNotFound(): Boolean {
|
public fun CommandExecuteResult.isCommandNotFound(): Boolean {
|
||||||
contract {
|
contract {
|
||||||
@ -210,6 +218,7 @@ public fun CommandExecuteResult.isCommandNotFound(): Boolean {
|
|||||||
/**
|
/**
|
||||||
* 当 [this] 为 [CommandExecuteResult.ExecutionFailed], [CommandExecuteResult.IllegalArgument] 或 [CommandExecuteResult.UnresolvedCall] 时返回 `true`
|
* 当 [this] 为 [CommandExecuteResult.ExecutionFailed], [CommandExecuteResult.IllegalArgument] 或 [CommandExecuteResult.UnresolvedCall] 时返回 `true`
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalCommandDescriptors
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public fun CommandExecuteResult.isFailure(): Boolean {
|
public fun CommandExecuteResult.isFailure(): Boolean {
|
||||||
contract {
|
contract {
|
||||||
|
@ -11,10 +11,8 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.command
|
package net.mamoe.mirai.console.command
|
||||||
|
|
||||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.executeCommand
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在 [CommandManager.executeCommand] 中, [Command.onCommand] 抛出异常时包装的异常.
|
* 在 [CommandManager.executeCommand] 中抛出异常时包装的异常.
|
||||||
*/
|
*/
|
||||||
public class CommandExecutionException(
|
public class CommandExecutionException(
|
||||||
/**
|
/**
|
||||||
@ -29,7 +27,7 @@ public class CommandExecutionException(
|
|||||||
* 匹配到的指令名
|
* 匹配到的指令名
|
||||||
*/
|
*/
|
||||||
public val name: String,
|
public val name: String,
|
||||||
cause: Throwable
|
cause: Throwable,
|
||||||
) : RuntimeException(
|
) : RuntimeException(
|
||||||
"Exception while executing command '${command.primaryName}'",
|
"Exception while executing command '${command.primaryName}'",
|
||||||
cause
|
cause
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.command
|
package net.mamoe.mirai.console.command
|
||||||
|
|
||||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregisterAllCommands
|
|
||||||
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
||||||
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.PERMISSION_NAME
|
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.PERMISSION_NAME
|
||||||
import net.mamoe.mirai.console.permission.Permission
|
import net.mamoe.mirai.console.permission.Permission
|
||||||
@ -34,11 +33,13 @@ public interface CommandOwner : PermissionIdNamespace {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 代表控制台所有者. 所有的 mirai-console 内建的指令都属于 [ConsoleCommandOwner].
|
* 代表控制台所有者. 所有的 mirai-console 内建的指令都属于 [ConsoleCommandOwner].
|
||||||
|
*
|
||||||
|
* 插件注册指令时不应该使用 [ConsoleCommandOwner].
|
||||||
*/
|
*/
|
||||||
internal object ConsoleCommandOwner : CommandOwner {
|
public object ConsoleCommandOwner : CommandOwner {
|
||||||
override val parentPermission: Permission get() = BuiltInCommands.parentPermission
|
public override val parentPermission: Permission get() = BuiltInCommands.parentPermission
|
||||||
|
|
||||||
override fun permissionId(
|
public override fun permissionId(
|
||||||
@ResolveContext(PERMISSION_NAME) name: String,
|
@ResolveContext(PERMISSION_NAME) name: String,
|
||||||
): PermissionId = PermissionId("console", name)
|
): PermissionId = PermissionId("console", name)
|
||||||
}
|
}
|
@ -9,8 +9,6 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.command
|
package net.mamoe.mirai.console.command
|
||||||
|
|
||||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.executeCommand
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在 [CommandManager.executeCommand] 中, [CommandSender] 未拥有 [Command.permission] 所要求的权限时抛出的异常.
|
* 在 [CommandManager.executeCommand] 中, [CommandSender] 未拥有 [Command.permission] 所要求的权限时抛出的异常.
|
||||||
*
|
*
|
||||||
@ -24,7 +22,7 @@ public class CommandPermissionDeniedException(
|
|||||||
/**
|
/**
|
||||||
* 执行过程发生异常的指令
|
* 执行过程发生异常的指令
|
||||||
*/
|
*/
|
||||||
public val command: Command
|
public val command: Command,
|
||||||
) : RuntimeException("Permission denied while executing command '${command.primaryName}'") {
|
) : RuntimeException("Permission denied while executing command '${command.primaryName}'") {
|
||||||
public override fun toString(): String =
|
public override fun toString(): String =
|
||||||
"CommandPermissionDeniedException(command=$command)"
|
"CommandPermissionDeniedException(command=$command)"
|
||||||
|
@ -87,9 +87,8 @@ public abstract class CompositeCommand(
|
|||||||
@ResolveContext(COMMAND_NAME) vararg secondaryNames: String,
|
@ResolveContext(COMMAND_NAME) vararg secondaryNames: String,
|
||||||
description: String = "no description available",
|
description: String = "no description available",
|
||||||
parentPermission: Permission = owner.parentPermission,
|
parentPermission: Permission = owner.parentPermission,
|
||||||
prefixOptional: Boolean = false,
|
|
||||||
overrideContext: CommandArgumentContext = EmptyCommandArgumentContext,
|
overrideContext: CommandArgumentContext = EmptyCommandArgumentContext,
|
||||||
) : Command, AbstractCommand(owner, primaryName, secondaryNames = secondaryNames, description, parentPermission, prefixOptional),
|
) : Command, AbstractCommand(owner, primaryName, secondaryNames = secondaryNames, description, parentPermission),
|
||||||
CommandArgumentContextAware {
|
CommandArgumentContextAware {
|
||||||
|
|
||||||
private val reflector by lazy { CommandReflector(this, CompositeCommandSubCommandAnnotationResolver) }
|
private val reflector by lazy { CommandReflector(this, CompositeCommandSubCommandAnnotationResolver) }
|
||||||
|
@ -15,7 +15,7 @@ import net.mamoe.mirai.console.command.descriptor.*
|
|||||||
import net.mamoe.mirai.console.command.java.JRawCommand
|
import net.mamoe.mirai.console.command.java.JRawCommand
|
||||||
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
||||||
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME
|
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME
|
||||||
import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission
|
import net.mamoe.mirai.console.internal.command.findOrCreateCommandPermission
|
||||||
import net.mamoe.mirai.console.internal.data.typeOf0
|
import net.mamoe.mirai.console.internal.data.typeOf0
|
||||||
import net.mamoe.mirai.console.permission.Permission
|
import net.mamoe.mirai.console.permission.Permission
|
||||||
import net.mamoe.mirai.message.data.Message
|
import net.mamoe.mirai.message.data.Message
|
||||||
@ -53,7 +53,7 @@ public abstract class RawCommand(
|
|||||||
@OptIn(ExperimentalCommandDescriptors::class)
|
@OptIn(ExperimentalCommandDescriptors::class)
|
||||||
public override val prefixOptional: Boolean = false,
|
public override val prefixOptional: Boolean = false,
|
||||||
) : Command {
|
) : Command {
|
||||||
public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) }
|
public override val permission: Permission by lazy { findOrCreateCommandPermission(parentPermission) }
|
||||||
|
|
||||||
@ExperimentalCommandDescriptors
|
@ExperimentalCommandDescriptors
|
||||||
override val overloads: List<CommandSignature> = listOf(
|
override val overloads: List<CommandSignature> = listOf(
|
||||||
|
@ -58,9 +58,8 @@ public abstract class SimpleCommand(
|
|||||||
@ResolveContext(COMMAND_NAME) vararg secondaryNames: String,
|
@ResolveContext(COMMAND_NAME) vararg secondaryNames: String,
|
||||||
description: String = "no description available",
|
description: String = "no description available",
|
||||||
parentPermission: Permission = owner.parentPermission,
|
parentPermission: Permission = owner.parentPermission,
|
||||||
prefixOptional: Boolean = false,
|
|
||||||
overrideContext: CommandArgumentContext = EmptyCommandArgumentContext,
|
overrideContext: CommandArgumentContext = EmptyCommandArgumentContext,
|
||||||
) : Command, AbstractCommand(owner, primaryName, secondaryNames = secondaryNames, description, parentPermission, prefixOptional),
|
) : Command, AbstractCommand(owner, primaryName, secondaryNames = secondaryNames, description, parentPermission),
|
||||||
CommandArgumentContextAware {
|
CommandArgumentContextAware {
|
||||||
|
|
||||||
private val reflector by lazy { CommandReflector(this, SimpleCommandSubCommandAnnotationResolver) }
|
private val reflector by lazy { CommandReflector(this, SimpleCommandSubCommandAnnotationResolver) }
|
||||||
|
@ -16,7 +16,7 @@ import net.mamoe.mirai.console.command.CommandOwner
|
|||||||
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
|
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
|
||||||
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
||||||
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME
|
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME
|
||||||
import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission
|
import net.mamoe.mirai.console.internal.command.findOrCreateCommandPermission
|
||||||
import net.mamoe.mirai.console.permission.Permission
|
import net.mamoe.mirai.console.permission.Permission
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,7 +65,7 @@ public abstract class JRawCommand
|
|||||||
protected set
|
protected set
|
||||||
|
|
||||||
/** 指令权限 */
|
/** 指令权限 */
|
||||||
public final override var permission: Permission = createOrFindCommandPermission(parentPermission)
|
public final override var permission: Permission = findOrCreateCommandPermission(parentPermission)
|
||||||
protected set
|
protected set
|
||||||
|
|
||||||
/** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */
|
/** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */
|
||||||
|
@ -23,6 +23,9 @@ import kotlin.reflect.KProperty
|
|||||||
/**
|
/**
|
||||||
* [PluginData] 的默认实现. 支持使用 `by value()` 等委托方法创建 [Value] 并跟踪其改动.
|
* [PluginData] 的默认实现. 支持使用 `by value()` 等委托方法创建 [Value] 并跟踪其改动.
|
||||||
*
|
*
|
||||||
|
* ### 实现注意
|
||||||
|
* 此类型处于实验性阶段. 使用其中定义的属性和函数是安全的, 但将来可能会新增成员抽象函数.
|
||||||
|
*
|
||||||
* @see PluginData
|
* @see PluginData
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractPluginData : PluginData, PluginDataImpl() {
|
public abstract class AbstractPluginData : PluginData, PluginDataImpl() {
|
||||||
|
@ -23,10 +23,4 @@ import kotlinx.coroutines.Job
|
|||||||
* @see PluginConfig
|
* @see PluginConfig
|
||||||
* @see AutoSavePluginData
|
* @see AutoSavePluginData
|
||||||
*/
|
*/
|
||||||
public open class AutoSavePluginConfig : AutoSavePluginData, PluginConfig {
|
public open class AutoSavePluginConfig public constructor(saveName: String) : AutoSavePluginData(saveName), PluginConfig
|
||||||
@Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginConfig(\"把我改成保存名称\")"))
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
|
||||||
public constructor() : super()
|
|
||||||
|
|
||||||
public constructor(saveName: String) : super(saveName)
|
|
||||||
}
|
|
@ -18,7 +18,6 @@ import net.mamoe.mirai.console.internal.data.qualifiedNameOrTip
|
|||||||
import net.mamoe.mirai.console.internal.plugin.updateWhen
|
import net.mamoe.mirai.console.internal.plugin.updateWhen
|
||||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||||
import net.mamoe.mirai.utils.*
|
import net.mamoe.mirai.utils.*
|
||||||
import kotlin.reflect.full.findAnnotation
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 链接自动保存的 [PluginData].
|
* 链接自动保存的 [PluginData].
|
||||||
@ -46,14 +45,6 @@ public open class AutoSavePluginData private constructor(
|
|||||||
_saveName = saveName
|
_saveName = saveName
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginData(\"把我改成保存名称\")"))
|
|
||||||
public constructor() : this(null) {
|
|
||||||
val clazz = this::class
|
|
||||||
_saveName = clazz.findAnnotation<ValueName>()?.value
|
|
||||||
?: clazz.qualifiedName
|
|
||||||
?: throw IllegalArgumentException("Cannot find a serial name for ${this::class}")
|
|
||||||
}
|
|
||||||
|
|
||||||
@ConsoleExperimentalApi
|
@ConsoleExperimentalApi
|
||||||
override fun onInit(owner: PluginDataHolder, storage: PluginDataStorage) {
|
override fun onInit(owner: PluginDataHolder, storage: PluginDataStorage) {
|
||||||
check(owner is AutoSavePluginDataHolder) { "owner must be AutoSavePluginDataHolder for AutoSavePluginData" }
|
check(owner is AutoSavePluginDataHolder) { "owner must be AutoSavePluginDataHolder for AutoSavePluginData" }
|
||||||
|
@ -98,13 +98,16 @@ import kotlin.reflect.KType
|
|||||||
* ```
|
* ```
|
||||||
* // MyPluginData.nestedMap: MutableMap<Long, List<Long>> by value()
|
* // MyPluginData.nestedMap: MutableMap<Long, List<Long>> by value()
|
||||||
* val newList = MyPluginData.map.getOrPut(1, ::mutableListOf)
|
* val newList = MyPluginData.map.getOrPut(1, ::mutableListOf)
|
||||||
* newList.add(1) // 不会添加到 MyPluginData.nestedMap 中, 因为 `mutableListOf` 创建的 MutableList 被非引用地添加进了 MyPluginData.nestedMap
|
* newList.add(1) // 不会添加到 MyPluginData.nestedMap 中, 因为 `mutableListOf` 创建的 MutableList 被非引用 (浅拷贝) 地添加进了 MyPluginData.nestedMap
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* 一个解决方案是对 [SerializerAwareValue] 做映射或相关修改. 如 [PluginDataExtensions].
|
* 一个解决方案是对 [SerializerAwareValue] 做映射或相关修改. 如 [PluginDataExtensions].
|
||||||
*
|
*
|
||||||
* 要查看详细的解释,请查看 [docs/PluginData.md](https://github.com/mamoe/mirai-console/blob/master/docs/PluginData.md)
|
* 要查看详细的解释,请查看 [docs/PluginData.md](https://github.com/mamoe/mirai-console/blob/master/docs/PluginData.md)
|
||||||
*
|
*
|
||||||
|
* ## 实现注意
|
||||||
|
* 此类型处于实验性阶段. 使用其中定义的属性和函数是安全的, 但将来可能会新增成员抽象函数.
|
||||||
|
*
|
||||||
* @see AbstractJvmPlugin.reloadPluginData 通过 [JvmPlugin] 获取指定 [PluginData] 实例.
|
* @see AbstractJvmPlugin.reloadPluginData 通过 [JvmPlugin] 获取指定 [PluginData] 实例.
|
||||||
* @see PluginDataStorage [PluginData] 存储仓库
|
* @see PluginDataStorage [PluginData] 存储仓库
|
||||||
* @see PluginDataExtensions 相关 [SerializerAwareValue] 映射函数
|
* @see PluginDataExtensions 相关 [SerializerAwareValue] 映射函数
|
||||||
|
@ -35,4 +35,9 @@ import kotlinx.serialization.SerialInfo
|
|||||||
@SerialInfo
|
@SerialInfo
|
||||||
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
public annotation class ValueDescription(val value: String)
|
public annotation class ValueDescription(
|
||||||
|
/**
|
||||||
|
* 将会被 [String.trimIndent] 处理.
|
||||||
|
*/
|
||||||
|
val value: String,
|
||||||
|
)
|
@ -37,10 +37,4 @@ import net.mamoe.mirai.console.data.PluginData
|
|||||||
* @see JAutoSavePluginData
|
* @see JAutoSavePluginData
|
||||||
* @see PluginConfig
|
* @see PluginConfig
|
||||||
*/
|
*/
|
||||||
public abstract class JAutoSavePluginConfig : AutoSavePluginConfig, PluginConfig {
|
public abstract class JAutoSavePluginConfig public constructor(saveName: String) : AutoSavePluginConfig(saveName), PluginConfig
|
||||||
@Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("JAutoSavePluginConfig(\"把我改成保存名称\")"))
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
|
||||||
public constructor() : super()
|
|
||||||
|
|
||||||
public constructor(saveName: String) : super(saveName)
|
|
||||||
}
|
|
@ -66,12 +66,7 @@ import kotlin.reflect.full.createType
|
|||||||
*
|
*
|
||||||
* @see PluginData
|
* @see PluginData
|
||||||
*/
|
*/
|
||||||
public abstract class JAutoSavePluginData : AutoSavePluginData, PluginConfig {
|
public abstract class JAutoSavePluginData public constructor(saveName: String) : AutoSavePluginData(saveName), PluginConfig {
|
||||||
@Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("JAutoSavePluginData(\"把我改成保存名称\")"))
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
|
||||||
public constructor() : super()
|
|
||||||
|
|
||||||
public constructor(saveName: String) : super(saveName)
|
|
||||||
|
|
||||||
//// region JPluginData_value_primitives CODEGEN ////
|
//// region JPluginData_value_primitives CODEGEN ////
|
||||||
|
|
||||||
|
@ -50,7 +50,8 @@ public interface InstanceExtensionPoint<T : InstanceExtension<*>> : ExtensionPoi
|
|||||||
public interface FunctionExtensionPoint<T : FunctionExtension> : ExtensionPoint<T>
|
public interface FunctionExtensionPoint<T : FunctionExtension> : ExtensionPoint<T>
|
||||||
|
|
||||||
|
|
||||||
public abstract class AbstractInstanceExtensionPoint<E : InstanceExtension<T>, T>(
|
public abstract class AbstractInstanceExtensionPoint<E : InstanceExtension<T>, T>
|
||||||
|
@ConsoleExperimentalApi constructor(
|
||||||
extensionType: KClass<E>,
|
extensionType: KClass<E>,
|
||||||
/**
|
/**
|
||||||
* 内建的实现列表.
|
* 内建的实现列表.
|
||||||
@ -59,7 +60,8 @@ public abstract class AbstractInstanceExtensionPoint<E : InstanceExtension<T>, T
|
|||||||
public vararg val builtinImplementations: E,
|
public vararg val builtinImplementations: E,
|
||||||
) : AbstractExtensionPoint<E>(extensionType)
|
) : AbstractExtensionPoint<E>(extensionType)
|
||||||
|
|
||||||
public abstract class AbstractSingletonExtensionPoint<E : SingletonExtension<T>, T>(
|
public abstract class AbstractSingletonExtensionPoint<E : SingletonExtension<T>, T>
|
||||||
|
@ConsoleExperimentalApi constructor(
|
||||||
extensionType: KClass<E>,
|
extensionType: KClass<E>,
|
||||||
/**
|
/**
|
||||||
* 内建的实现.
|
* 内建的实现.
|
||||||
|
@ -30,6 +30,6 @@ public interface CommandCallParserProvider : InstanceExtension<CommandCallParser
|
|||||||
public class CommandCallParserProviderImpl(override val instance: CommandCallParser) : CommandCallParserProvider
|
public class CommandCallParserProviderImpl(override val instance: CommandCallParser) : CommandCallParserProvider
|
||||||
|
|
||||||
@ExperimentalCommandDescriptors
|
@ExperimentalCommandDescriptors
|
||||||
public class CommandCallParserProviderImplLazy(instanceCalculator: () -> CommandCallParser) : CommandCallParserProvider {
|
public class CommandCallParserProviderImplLazy(initializer: () -> CommandCallParser) : CommandCallParserProvider {
|
||||||
override val instance: CommandCallParser by lazy(instanceCalculator)
|
override val instance: CommandCallParser by lazy(initializer)
|
||||||
}
|
}
|
@ -26,6 +26,6 @@ public interface CommandCallResolverProvider : InstanceExtension<CommandCallReso
|
|||||||
public class CommandCallResolverProviderImpl(override val instance: CommandCallResolver) : CommandCallResolverProvider
|
public class CommandCallResolverProviderImpl(override val instance: CommandCallResolver) : CommandCallResolverProvider
|
||||||
|
|
||||||
@ExperimentalCommandDescriptors
|
@ExperimentalCommandDescriptors
|
||||||
public class CommandCallResolverProviderImplLazy(instanceCalculator: () -> CommandCallResolver) : CommandCallResolverProvider {
|
public class CommandCallResolverProviderImplLazy(initializer: () -> CommandCallResolver) : CommandCallResolverProvider {
|
||||||
override val instance: CommandCallResolver by lazy(instanceCalculator)
|
override val instance: CommandCallResolver by lazy(initializer)
|
||||||
}
|
}
|
@ -24,10 +24,10 @@ public fun interface PostStartupExtension : FunctionExtension {
|
|||||||
/**
|
/**
|
||||||
* 将在 Console 主线程执行.
|
* 将在 Console 主线程执行.
|
||||||
*
|
*
|
||||||
* @throws Exception 所有抛出的 [Exception] 都会被捕获并包装为 [ExtensionException] 抛出, 并停止 [MiraiConsole]
|
|
||||||
*
|
|
||||||
* #### 内部实现细节
|
* #### 内部实现细节
|
||||||
* 在 [MiraiConsoleImplementationBridge.doStart] 所有 [MiraiConsoleImplementationBridge.phase] 执行完成后顺序调用.
|
* 在 [MiraiConsoleImplementationBridge.doStart] 所有 [MiraiConsoleImplementationBridge.phase] 执行完成后顺序调用.
|
||||||
|
*
|
||||||
|
* @throws Exception 所有抛出的 [Exception] 都会被捕获并包装为 [ExtensionException] 抛出, 并停止 [MiraiConsole]
|
||||||
*/
|
*/
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
public operator fun invoke()
|
public operator fun invoke()
|
||||||
|
@ -28,13 +28,16 @@ import kotlin.reflect.KClass
|
|||||||
* 如有多个 [SingletonExtensionSelector] 注册, 将会停止服务器.
|
* 如有多个 [SingletonExtensionSelector] 注册, 将会停止服务器.
|
||||||
*/
|
*/
|
||||||
public interface SingletonExtensionSelector : FunctionExtension {
|
public interface SingletonExtensionSelector : FunctionExtension {
|
||||||
|
/**
|
||||||
|
* 表示一个插件注册的 [Extension]
|
||||||
|
*/
|
||||||
public data class Registry<T : Extension>(
|
public data class Registry<T : Extension>(
|
||||||
val plugin: Plugin?,
|
val plugin: Plugin?,
|
||||||
val extension: T,
|
val extension: T,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null 表示使用 builtin
|
* @return `null` 表示使用 Console 内置的 [SingletonExtensionSelector]
|
||||||
*/
|
*/
|
||||||
public fun <T : Extension> selectSingleton(
|
public fun <T : Extension> selectSingleton(
|
||||||
extensionType: KClass<T>,
|
extensionType: KClass<T>,
|
||||||
|
@ -226,6 +226,9 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
|||||||
@DslMarker
|
@DslMarker
|
||||||
internal annotation class ILoveOmaeKumikoForever
|
internal annotation class ILoveOmaeKumikoForever
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表示一个初始化阶段, 无实际作用.
|
||||||
|
*/
|
||||||
@ILoveOmaeKumikoForever
|
@ILoveOmaeKumikoForever
|
||||||
private inline fun phase(block: () -> Unit) {
|
private inline fun phase(block: () -> Unit) {
|
||||||
contract {
|
contract {
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.console.internal.command
|
package net.mamoe.mirai.console.internal.command
|
||||||
|
|
||||||
import net.mamoe.mirai.console.command.*
|
import net.mamoe.mirai.console.command.*
|
||||||
@ -149,7 +158,7 @@ internal class CommandReflector(
|
|||||||
append(" ")
|
append(" ")
|
||||||
}
|
}
|
||||||
append(subcommand.valueParameters.joinToString(" ") { it.render() })
|
append(subcommand.valueParameters.joinToString(" ") { it.render() })
|
||||||
annotationResolver.getDescription(command, subcommand.originFunction).let { description ->
|
annotationResolver.getDescription(command, subcommand.originFunction)?.let { description ->
|
||||||
append(" ")
|
append(" ")
|
||||||
append(description)
|
append(description)
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ internal fun Group.fuzzySearchMember(
|
|||||||
disambiguationRate: Double = 0.1,
|
disambiguationRate: Double = 0.1,
|
||||||
): List<Pair<Member, Double>> {
|
): List<Pair<Member, Double>> {
|
||||||
val candidates = (this.members + botAsMember)
|
val candidates = (this.members + botAsMember)
|
||||||
|
.asSequence()
|
||||||
.associateWith { it.nameCard.fuzzyMatchWith(nameCardTarget) }
|
.associateWith { it.nameCard.fuzzyMatchWith(nameCardTarget) }
|
||||||
.filter { it.value >= minRate }
|
.filter { it.value >= minRate }
|
||||||
.toList()
|
.toList()
|
||||||
@ -79,7 +80,7 @@ internal fun Group.fuzzySearchMember(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Command.createOrFindCommandPermission(parent: Permission): Permission {
|
internal fun Command.findOrCreateCommandPermission(parent: Permission): Permission {
|
||||||
val id = owner.permissionId("command.$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)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.console.internal.data.builtins
|
package net.mamoe.mirai.console.internal.data.builtins
|
||||||
|
|
||||||
import net.mamoe.mirai.console.data.AutoSavePluginConfig
|
import net.mamoe.mirai.console.data.AutoSavePluginConfig
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.console.internal.extension
|
package net.mamoe.mirai.console.internal.extension
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020 Karlatemp. All rights reserved.
|
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||||
* @author Karlatemp <karlatemp@vip.qq.com> <https://github.com/Karlatemp>
|
|
||||||
*
|
|
||||||
* LuckPerms-Mirai/mirai-console.mirai-console.main/ExportManagerImpl.kt
|
|
||||||
*
|
*
|
||||||
|
* 此源代码的使用受 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.
|
* 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/Karlatemp/LuckPerms-Mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.console.internal.plugin
|
package net.mamoe.mirai.console.internal.plugin
|
||||||
|
@ -43,11 +43,10 @@ internal class JavaPluginSchedulerImpl internal constructor(parentCoroutineConte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <R> delayed(delayMillis: Long, runnable: Callable<R>): CompletableFuture<Void?> {
|
override fun <R> delayed(delayMillis: Long, callable: Callable<R>): CompletableFuture<R> {
|
||||||
return future {
|
return future {
|
||||||
delay(delayMillis)
|
delay(delayMillis)
|
||||||
withContext(Dispatchers.IO) { runnable.call() }
|
withContext(Dispatchers.IO) { callable.call() }
|
||||||
null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public interface PermissionIdNamespace {
|
|||||||
/**
|
/**
|
||||||
* 创建一个此命名空间下的 [PermitteeId].
|
* 创建一个此命名空间下的 [PermitteeId].
|
||||||
*
|
*
|
||||||
* 在指令初始化时, 会申请对应权限. 此时 [name] 为 "command.$primaryName` 其中 [primaryName][Command.primaryName].
|
* 在指令初始化时, 会申请对应权限. 此时 [name] 为 `command.$primaryName` 其中 [primaryName][Command.primaryName].
|
||||||
*/
|
*/
|
||||||
public fun permissionId(@ResolveContext(PERMISSION_NAME) name: String): PermissionId
|
public fun permissionId(@ResolveContext(PERMISSION_NAME) name: String): PermissionId
|
||||||
}
|
}
|
@ -35,7 +35,7 @@ import kotlin.DeprecationLevel.ERROR
|
|||||||
*/
|
*/
|
||||||
public interface Plugin : CommandOwner {
|
public interface Plugin : CommandOwner {
|
||||||
/**
|
/**
|
||||||
* 判断此插件是否已启用
|
* 当插件已启用时返回 `true`, 否则表示插件未启用.
|
||||||
*
|
*
|
||||||
* @see PluginManager.enablePlugin 启用一个插件
|
* @see PluginManager.enablePlugin 启用一个插件
|
||||||
* @see PluginManager.disablePlugin 禁用一个插件
|
* @see PluginManager.disablePlugin 禁用一个插件
|
||||||
|
@ -140,16 +140,28 @@ public interface PluginManager {
|
|||||||
get() = this.loader as PluginLoader<P, PluginDescription>
|
get() = this.loader as PluginLoader<P, PluginDescription>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see getPluginDescription
|
||||||
|
*/
|
||||||
@get:JvmSynthetic
|
@get:JvmSynthetic
|
||||||
public inline val Plugin.description: PluginDescription
|
public inline val Plugin.description: PluginDescription
|
||||||
get() = getPluginDescription(this)
|
get() = getPluginDescription(this)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see disablePlugin
|
||||||
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public inline fun Plugin.disable(): Unit = disablePlugin(this)
|
public inline fun Plugin.disable(): Unit = disablePlugin(this)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see enablePlugin
|
||||||
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public inline fun Plugin.enable(): Unit = enablePlugin(this)
|
public inline fun Plugin.enable(): Unit = enablePlugin(this)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see loadPlugin
|
||||||
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public inline fun Plugin.load(): Unit = loadPlugin(this)
|
public inline fun Plugin.load(): Unit = loadPlugin(this)
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import java.util.concurrent.Callable
|
|||||||
import java.util.concurrent.CompletableFuture
|
import java.util.concurrent.CompletableFuture
|
||||||
import java.util.concurrent.Future
|
import java.util.concurrent.Future
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,9 +49,9 @@ public interface JavaPluginScheduler : CoroutineScope {
|
|||||||
/**
|
/**
|
||||||
* 新增一个 Delayed Task (延迟任务)
|
* 新增一个 Delayed Task (延迟任务)
|
||||||
*
|
*
|
||||||
* 在延迟 [delayMillis] 后执行 [runnable]
|
* 在延迟 [delayMillis] 后执行 [callable]
|
||||||
*/
|
*/
|
||||||
public fun <R> delayed(delayMillis: Long, runnable: Callable<R>): CompletableFuture<Void?>
|
public fun <R> delayed(delayMillis: Long, callable: Callable<R>): CompletableFuture<R>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步执行一个任务, 最终返回 [Future], 与 Java 使用方法无异, 但效率更高且可以在插件关闭时停止
|
* 异步执行一个任务, 最终返回 [Future], 与 Java 使用方法无异, 但效率更高且可以在插件关闭时停止
|
||||||
@ -68,7 +69,8 @@ public interface JavaPluginScheduler : CoroutineScope {
|
|||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmName("create")
|
@JvmName("create")
|
||||||
public operator fun invoke(parentCoroutineContext: CoroutineContext): JavaPluginScheduler =
|
@JvmOverloads
|
||||||
|
public operator fun invoke(parentCoroutineContext: CoroutineContext = EmptyCoroutineContext): JavaPluginScheduler =
|
||||||
JavaPluginSchedulerImpl(parentCoroutineContext)
|
JavaPluginSchedulerImpl(parentCoroutineContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ import net.mamoe.mirai.console.MiraiConsole
|
|||||||
import net.mamoe.mirai.console.internal.util.ConsoleInputImpl
|
import net.mamoe.mirai.console.internal.util.ConsoleInputImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Console 输入. 由于 console 接管了 [stdin][System. in], [readLine] 等操作需要在这里进行.
|
* Console 输入. 由于 console 接管了 [标准输入][System. in], [readLine] 等操作需要在这里进行.
|
||||||
*/
|
*/
|
||||||
public interface ConsoleInput {
|
public interface ConsoleInput {
|
||||||
/**
|
/**
|
||||||
|
@ -72,6 +72,7 @@ import kotlin.internal.LowPriorityInOverloadResolution
|
|||||||
* val duration = Random.nextInt(1, 15)
|
* val duration = Random.nextInt(1, 15)
|
||||||
* target.mute(duration)
|
* target.mute(duration)
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* // 不使用 MessageScope, 无用的样板代码
|
* // 不使用 MessageScope, 无用的样板代码
|
||||||
* val thisGroup = this.getGroupOrNull()
|
* val thisGroup = this.getGroupOrNull()
|
||||||
* val message = "${this.name} 禁言 ${target.nameCardOrNick} $duration 秒"
|
* val message = "${this.name} 禁言 ${target.nameCardOrNick} $duration 秒"
|
||||||
@ -80,12 +81,14 @@ import kotlin.internal.LowPriorityInOverloadResolution
|
|||||||
* }
|
* }
|
||||||
* sendMessage(message)
|
* sendMessage(message)
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* // 使用 MessageScope, 清晰逻辑
|
* // 使用 MessageScope, 清晰逻辑
|
||||||
* // 表示至少发送给 `this`, 当 `this` 的真实发信对象与 `target.group` 不同时, 还额外发送给 `target.group`
|
* // 表示至少发送给 `this`, 当 `this` 的真实发信对象与 `target.group` 不同时, 还额外发送给 `target.group`
|
||||||
* this.scopeWith(target.group) {
|
* this.scopeWith(target.group) {
|
||||||
* sendMessage("${name} 禁言了 ${target.nameCardOrNick} $duration 秒")
|
* sendMessage("${name} 禁言了 ${target.nameCardOrNick} $duration 秒")
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* // 同样地, 可以扩展用法, 同时私聊指令执行者:
|
* // 同样地, 可以扩展用法, 同时私聊指令执行者:
|
||||||
* // this.scopeWith(
|
* // this.scopeWith(
|
||||||
* // target,
|
* // target,
|
||||||
@ -132,6 +135,8 @@ public inline operator fun <R, MS : MessageScope> MS.invoke(action: MS.() -> R):
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* 实现提示: 以下所有代码都通过 codegen 模块中 net.mamoe.mirai.console.codegen.MessageScopeCodegen 生成. 请不要手动修改它们.
|
* 实现提示: 以下所有代码都通过 codegen 模块中 net.mamoe.mirai.console.codegen.MessageScopeCodegen 生成. 请不要手动修改它们.
|
||||||
|
*
|
||||||
|
* 建议阅读 [MessageScope] 的文档.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//// region MessageScopeBuilders CODEGEN ////
|
//// region MessageScopeBuilders CODEGEN ////
|
||||||
|
@ -77,6 +77,7 @@ internal class TestCommand {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testRegister() {
|
fun testRegister() {
|
||||||
|
error(TestCompositeCommand.usage)
|
||||||
try {
|
try {
|
||||||
unregisterAllCommands(ConsoleCommandOwner) // builtins
|
unregisterAllCommands(ConsoleCommandOwner) // builtins
|
||||||
unregisterCommand(TestSimpleCommand)
|
unregisterCommand(TestSimpleCommand)
|
||||||
|
Loading…
Reference in New Issue
Block a user