From bf83b206e245b12c02ab9a7ea61def7d73d8966a Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 18 Nov 2020 15:26:37 +0800 Subject: [PATCH] Log PermissionService loaded from plugin on init --- .../src/extensions/PermissionServiceProvider.kt | 14 +++++++++++++- .../internal/MiraiConsoleImplementationBridge.kt | 10 ++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/backend/mirai-console/src/extensions/PermissionServiceProvider.kt b/backend/mirai-console/src/extensions/PermissionServiceProvider.kt index d47043993..afc0e7a2d 100644 --- a/backend/mirai-console/src/extensions/PermissionServiceProvider.kt +++ b/backend/mirai-console/src/extensions/PermissionServiceProvider.kt @@ -11,8 +11,11 @@ package net.mamoe.mirai.console.extensions import net.mamoe.mirai.console.extension.AbstractSingletonExtensionPoint import net.mamoe.mirai.console.extension.SingletonExtension +import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.permission.PermissionService +import net.mamoe.mirai.console.plugin.Plugin +import net.mamoe.mirai.console.util.ConsoleExperimentalApi /** * [权限服务][PermissionService] 提供器. @@ -21,7 +24,16 @@ import net.mamoe.mirai.console.permission.PermissionService */ public interface PermissionServiceProvider : SingletonExtension> { public companion object ExtensionPoint : - AbstractSingletonExtensionPoint>(PermissionServiceProvider::class, BuiltInPermissionService) + AbstractSingletonExtensionPoint>(PermissionServiceProvider::class, BuiltInPermissionService) { + @ConsoleExperimentalApi + public val providerPlugin: Plugin? by lazy { + GlobalComponentStorage.run { + val instance = PermissionService.INSTANCE + if (instance is BuiltInPermissionService) return@lazy null + PermissionServiceProvider.getExtensions().find { it.extension === instance }?.plugin + } + } + } } /** diff --git a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt index be186c14b..1e6e4c0d7 100644 --- a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt @@ -43,6 +43,7 @@ import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl import net.mamoe.mirai.console.internal.util.autoHexToBytes +import net.mamoe.mirai.console.internal.util.runIgnoreException import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.permission.PermissionService.Companion.permit @@ -51,6 +52,7 @@ import net.mamoe.mirai.console.plugin.PluginManager import net.mamoe.mirai.console.plugin.center.PluginCenter import net.mamoe.mirai.console.plugin.jvm.AbstractJvmPlugin import net.mamoe.mirai.console.plugin.loader.PluginLoader +import net.mamoe.mirai.console.plugin.name import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.console.util.ConsoleInput import net.mamoe.mirai.console.util.SemVersion @@ -186,22 +188,22 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI phase `load PermissionService`@{ mainLogger.verbose { "Loading PermissionService..." } - PermissionServiceProvider.selectedInstance // init - PermissionService.INSTANCE.let { ps -> if (ps is BuiltInPermissionService) { ConsoleDataScope.addAndReloadConfig(ps.config) mainLogger.verbose { "Reloaded PermissionService settings." } + } else { + mainLogger.info { "Loaded PermissionService from plugin ${PermissionServiceProvider.providerPlugin?.name}" } } } - ConsoleCommandSender.permit(RootPermission) + runIgnoreException { ConsoleCommandSender.permit(RootPermission) } } phase `prepare commands`@{ mainLogger.verbose { "Loading built-in commands..." } BuiltInCommands.registerAll() - mainLogger.verbose { "Prepared built-in commands: ${BuiltInCommands.all.joinToString { it.primaryName }}" } + mainLogger.info { "Prepared built-in commands: ${BuiltInCommands.all.joinToString { it.primaryName }}" } CommandManager // CommandManagerImpl.commandListener // start }