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