mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Remove chat context commandListener from backend
This commit is contained in:
parent
bb64c3b999
commit
38f8773b98
@ -29,7 +29,6 @@ import net.mamoe.mirai.console.extensions.PermissionServiceProvider
|
||||
import net.mamoe.mirai.console.extensions.PostStartupExtension
|
||||
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector
|
||||
import net.mamoe.mirai.console.internal.command.CommandConfig
|
||||
import net.mamoe.mirai.console.internal.command.CommandManagerImpl
|
||||
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig
|
||||
import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope
|
||||
import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig
|
||||
@ -201,7 +200,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
||||
BuiltInCommands.registerAll()
|
||||
mainLogger.verbose { "Prepared built-in commands: ${BuiltInCommands.all.joinToString { it.primaryName }}" }
|
||||
CommandManager
|
||||
CommandManagerImpl.commandListener // start
|
||||
// CommandManagerImpl.commandListener // start
|
||||
}
|
||||
|
||||
phase `enable plugins`@{
|
||||
|
@ -28,6 +28,7 @@ import net.mamoe.mirai.console.internal.util.ifNull
|
||||
import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.event.Listener
|
||||
import net.mamoe.mirai.event.Listener.ConcurrencyKind.CONCURRENT
|
||||
import net.mamoe.mirai.event.subscribeAlways
|
||||
import net.mamoe.mirai.message.MessageEvent
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
@ -67,35 +68,48 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons
|
||||
return optionalPrefixCommandMap[commandName.toLowerCase()]
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated since 1.0.0, to be extended by plugin.")
|
||||
internal val commandListener: Listener<MessageEvent> by lazy {
|
||||
subscribeAlways(
|
||||
coroutineContext = CoroutineExceptionHandler { _, throwable ->
|
||||
logger.error(throwable)
|
||||
},
|
||||
concurrency = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority = Listener.EventPriority.HIGH
|
||||
concurrency = CONCURRENT,
|
||||
priority = Listener.EventPriority.NORMAL
|
||||
) {
|
||||
val sender = this.toCommandSender()
|
||||
|
||||
fun isDebugging(command: Command?): Boolean {
|
||||
if (command?.prefixOptional == false || message.content.startsWith(CommandManager.commandPrefix)) {
|
||||
if (MiraiConsoleImplementationBridge.loggerController.shouldLog("console.debug", SimpleLogger.LogPriority.DEBUG)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
when (val result = executeCommand(sender, message)) {
|
||||
is CommandExecuteResult.PermissionDenied -> {
|
||||
if (!result.command.prefixOptional || message.content.startsWith(CommandManager.commandPrefix)) {
|
||||
if (MiraiConsoleImplementationBridge.loggerController.shouldLog("console.debug", SimpleLogger.LogPriority.DEBUG)) {
|
||||
sender.sendMessage("权限不足")
|
||||
}
|
||||
intercept()
|
||||
if (isDebugging(result.command)) {
|
||||
sender.sendMessage("权限不足. ${CommandManager.commandPrefix}${result.command.primaryName} 需要权限 ${result.command.permission.id}.")
|
||||
// intercept()
|
||||
}
|
||||
}
|
||||
is CommandExecuteResult.IllegalArgument -> {
|
||||
result.exception.message?.let { sender.sendMessage(it) }
|
||||
intercept()
|
||||
// intercept()
|
||||
}
|
||||
is CommandExecuteResult.Success -> {
|
||||
intercept()
|
||||
// intercept()
|
||||
}
|
||||
is CommandExecuteResult.ExecutionFailed -> {
|
||||
sender.catchExecutionException(result.exception)
|
||||
intercept()
|
||||
// intercept()
|
||||
}
|
||||
is CommandExecuteResult.Intercepted -> {
|
||||
if (isDebugging(result.command)) {
|
||||
sender.sendMessage("指令执行被拦截, 原因: ${result.reason}")
|
||||
}
|
||||
}
|
||||
is CommandExecuteResult.UnmatchedSignature,
|
||||
is CommandExecuteResult.UnresolvedCommand,
|
||||
|
Loading…
Reference in New Issue
Block a user