mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-01 10:36:04 +08:00
Prefer SystemCommandSender; fix SystemCommandSender error message rendering
This commit is contained in:
parent
9d33c05aad
commit
f48940a897
@ -362,6 +362,10 @@ public interface PluginCustomCommandSender : CommandSender, SystemCommandSender
|
||||
* 控制台指令执行者. 代表由控制台执行指令
|
||||
*
|
||||
* 控制台拥有一切指令的执行权限.
|
||||
*
|
||||
* 不建议在 [CompositeCommand] 中使用 [ConsoleCommandSender],
|
||||
* 使用 [SystemCommandSender] 以允许其他插件执行
|
||||
*
|
||||
*/
|
||||
public object ConsoleCommandSender : AbstractCommandSender(), SystemCommandSender {
|
||||
public const val NAME: String = "ConsoleCommandSender"
|
||||
|
@ -57,8 +57,8 @@ import kotlin.annotation.AnnotationTarget.FUNCTION
|
||||
* }
|
||||
*
|
||||
* @SubCommand
|
||||
* suspend fun ConsoleCommandSender.foo() {
|
||||
* // 使用 ConsoleCommandSender 作为接收者,表示指令只能由控制台执行。
|
||||
* suspend fun SystemCommandSender.foo() {
|
||||
* // 使用 SystemCommandSender 作为接收者,表示指令只能由系统(控制台或其他插件)执行。
|
||||
* // 当用户尝试在聊天环境执行时将会收到错误提示。
|
||||
* }
|
||||
*
|
||||
|
@ -173,6 +173,9 @@ internal fun CommandReceiverParameter<*>.renderAsName(): String {
|
||||
val classifier = this.type.classifier.cast<KClass<out CommandSender>>()
|
||||
return when {
|
||||
classifier.isSubclassOf(ConsoleCommandSender::class) -> "控制台"
|
||||
// 只有 classifier 明确为 SystemCommandSender 才有系统的意思
|
||||
// classifier 为子类时不满足 "系统" 的定义
|
||||
classifier == SystemCommandSender::class -> "系统"
|
||||
classifier.isSubclassOf(FriendCommandSenderOnMessage::class) -> "好友私聊"
|
||||
classifier.isSubclassOf(FriendCommandSender::class) -> "好友"
|
||||
classifier.isSubclassOf(MemberCommandSenderOnMessage::class) -> "群内发言"
|
||||
|
Loading…
Reference in New Issue
Block a user