mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Extract AbstractCommand
This commit is contained in:
parent
56a7098627
commit
78ebdf038d
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.command
|
||||
|
||||
import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission
|
||||
import net.mamoe.mirai.console.permission.Permission
|
||||
|
||||
/**
|
||||
* [Command] 的基础实现
|
||||
*
|
||||
* @see SimpleCommand
|
||||
* @see CompositeCommand
|
||||
* @see RawCommand
|
||||
*/
|
||||
public abstract class AbstractCommand
|
||||
@JvmOverloads constructor(
|
||||
public final override val owner: CommandOwner,
|
||||
public final override val primaryName: String,
|
||||
public final override val secondaryNames: Array<out String>,
|
||||
public override val description: String = "<no description available>",
|
||||
parentPermission: Permission = owner.parentPermission,
|
||||
/** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */
|
||||
public override val prefixOptional: Boolean = false,
|
||||
) : Command {
|
||||
init {
|
||||
Command.checkCommandName(primaryName)
|
||||
secondaryNames.forEach(Command.Companion::checkCommandName)
|
||||
}
|
||||
|
||||
public override val usage: String get() = description
|
||||
public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) }
|
||||
}
|
@ -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.compiler.common.ResolveContext
|
||||
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME
|
||||
import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission
|
||||
import net.mamoe.mirai.console.permission.Permission
|
||||
import net.mamoe.mirai.console.permission.PermissionId
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
@ -125,28 +124,3 @@ public interface Command {
|
||||
public suspend inline fun Command.onCommand(sender: CommandSender, args: MessageChain): Unit =
|
||||
sender.onCommand(args)
|
||||
|
||||
/**
|
||||
* [Command] 的基础实现
|
||||
*
|
||||
* @see SimpleCommand
|
||||
* @see CompositeCommand
|
||||
* @see RawCommand
|
||||
*/
|
||||
public abstract class AbstractCommand
|
||||
@JvmOverloads constructor(
|
||||
public final override val owner: CommandOwner,
|
||||
public final override val primaryName: String,
|
||||
public final override val secondaryNames: Array<out String>,
|
||||
public override val description: String = "<no description available>",
|
||||
parentPermission: Permission = owner.parentPermission,
|
||||
/** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */
|
||||
public override val prefixOptional: Boolean = false,
|
||||
) : Command {
|
||||
init {
|
||||
Command.checkCommandName(primaryName)
|
||||
secondaryNames.forEach(Command::checkCommandName)
|
||||
}
|
||||
|
||||
public override val usage: String get() = description
|
||||
public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) }
|
||||
}
|
Loading…
Reference in New Issue
Block a user