CommandSender

interface CommandSender : CoroutineScope, Permittee

指令发送者.

只有 CommandSender 才能 执行指令

获得指令发送者

实现 CommandSender

在任何时候都不要实现 CommandSender (包括使用委托). 必须使用上述扩展获取 CommandSender 实例.

除了以下情况:

子类型

所有 CommandSender 都应继承 AbstractCommandSender.

AbstractCommandSender 是密封类, 一级子类为:

二级子类, 当指令由插件 主动执行 时, 插件应使用 toCommandSenderasCommandSender, 因此,

三级子类, 当真实收到由用户执行的指令时:

类型关系如图. 箭头指向的是父类.

                   CoroutineScope

|
+----------> CommandSender <---------+---------------------+---------------------------------------------------+
| ↑ | | |
| | | | |
SystemCommandSender <-------+ | UserCommandSender GroupAwareCommandSender CommandSenderOnMessage
↑ | | ↑ ↑ ↑
PluginCustomCommandSender | | | | |
↑ | | | | |
| +-------------+ AbstractCommandSender | | |
| | ↑ | | |
| | | sealed | | |
| | +---------------+-------------+ | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | | }
| ConsoleCommandSender | AbstractUserCommandSender | | }
| | ↑ | | } 一级子类
AbstractPluginCustomCommandSender -------+ | | | }
| | | }
| | |
| | |
| sealed | |
| | |
+----------------------+ | |
| | | |
| +------+------------+---------------+ |
| | | |
| | | | }
FriendCommandSender MemberCommandSender TempCommandSender | } 二级子类
↑ ↑ ↑ | }
| | | |
| | | | }
FriendCommandSenderOnMessage MemberCommandSenderOnMessage TempCommandSenderOnMessage | } 三级子类
| | | | }
| | | |
+-----------------------------+----------------------------+---------------------+

Scoping: MessageScope

在处理多个消息对象时, 可通过 MessageScope 简化操作.

查看 MessageScope 以获取更多信息.

See also

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract suspend fun sendMessage(message: String): MessageReceipt<Contact>?
abstract suspend fun sendMessage(message: Message): MessageReceipt<Contact>?

立刻发送一条消息.

Properties

Link copied to clipboard
abstract val bot: Bot?

与这个 CommandSender 相关的 Bot. 当通过控制台执行时为 null.

Link copied to clipboard
abstract val coroutineContext: CoroutineContext
Link copied to clipboard
abstract val name: String
Link copied to clipboard
abstract val permitteeId: PermitteeId
Link copied to clipboard
abstract val subject: Contact?

与这个 CommandSender 相关的 Contact.

Link copied to clipboard
abstract val user: User?

指令原始发送.

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Extensions

Link copied to clipboard
suspend fun CommandSender.add(    account: Long,     password: String,     passwordKind: AutoLoginConfig.Account.PasswordKind = PLAIN)
Link copied to clipboard
fun CommandSender.asMessageScope(): MessageScope
Link copied to clipboard
suspend fun CommandSender.cancel(target: PermitteeId, permission: Permission)
Link copied to clipboard
suspend fun CommandSender.cancelAll(target: PermitteeId, permission: Permission)
Link copied to clipboard
suspend fun CommandSender.clear()
Link copied to clipboard
inline suspend fun CommandSender.executeCommand(message: String, checkPermission: Boolean = true): CommandExecuteResult

解析并执行一个指令

Link copied to clipboard
inline fun <R> CommandSender.fold(    ifIsSystem: SystemCommandSender.() -> R,     ifIsUser: UserCommandSender.() -> R,     otherwise: CommandSender.() -> R = { error("CommandSender ${this::class.qualifiedName} is not supported") }): R

折叠 CommandSender 的可能性.

Link copied to clipboard
fun CommandSender.getBotOrNull(): Bot?

尝试获取 Bot.

Link copied to clipboard
fun CommandSender.getGroupOrNull(): Group?

尝试获取 Group.

Link copied to clipboard
suspend fun CommandSender.handle()
suspend fun CommandSender.handle()
suspend fun CommandSender.handle()
suspend fun CommandSender.handle(id: Long)
suspend fun CommandSender.handle(    id: Long,     password: String? = null,     protocol: BotConfiguration.MiraiProtocol? = null)
Link copied to clipboard
fun CommandSender.isConsole(): Boolean

thisConsoleCommandSender 时返回 true

Link copied to clipboard
fun CommandSender.isNotConsole(): Boolean

this 不为 ConsoleCommandSender 时返回 true

Link copied to clipboard
fun CommandSender.isNotUser(): Boolean

this 不为 UserCommandSender, 即为 SystemCommandSender 时返回 true

Link copied to clipboard
fun CommandSender.isSystem(): Boolean

thisSystemCommandSender 时返回 true

Link copied to clipboard
fun CommandSender.isUser(): Boolean

thisUserCommandSender 时返回 true

Link copied to clipboard
suspend fun CommandSender.list()
Link copied to clipboard
suspend fun CommandSender.listPermissions()
Link copied to clipboard
suspend fun CommandSender.permit(target: PermitteeId, permission: Permission)
Link copied to clipboard
suspend fun CommandSender.permittedPermissions(target: PermitteeId, all: Boolean = true)
Link copied to clipboard
suspend fun CommandSender.remove(account: Long)
Link copied to clipboard
suspend fun CommandSender.removeConfig(account: Long, configKey: AutoLoginConfig.Account.ConfigurationKey)
Link copied to clipboard
fun CommandSender?.scopeWith(vararg others: Contact?): MessageScope
fun CommandSender?.scopeWith(vararg others: CommandSender?): MessageScope
fun CommandSender?.scopeWith(vararg others: MessageScope?): MessageScope
fun CommandSender?.scopeWith(other: Contact?): MessageScope
fun CommandSender?.scopeWith(other: CommandSender?): MessageScope
fun CommandSender?.scopeWith(other: MessageScope?): MessageScope
inline fun <R> CommandSender?.scopeWith(vararg others: Contact?, action: MessageScope.() -> R): R
inline fun <R> CommandSender?.scopeWith(vararg others: CommandSender?, action: MessageScope.() -> R): R
inline fun <R> CommandSender?.scopeWith(vararg others: MessageScope?, action: MessageScope.() -> R): R
inline fun CommandSender.scopeWith(): MessageScope
inline fun <R> CommandSender.scopeWith(action: MessageScope.() -> R): R
Link copied to clipboard
inline suspend fun CommandSender.sendAnsiMessage(capacity: Int = 16, builder: AnsiMessageBuilder.() -> Unit): MessageReceipt<Contact>?
inline suspend fun CommandSender.sendAnsiMessage(message: String): MessageReceipt<Contact>?

CommandSender 发送一条带有 ANSI 控制符的信息

Link copied to clipboard
suspend fun CommandSender.setConfig(    account: Long,     configKey: AutoLoginConfig.Account.ConfigurationKey,     value: String)