diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt index 5af616e88..19707ba29 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt @@ -18,8 +18,8 @@ import kotlinx.coroutines.Job import net.mamoe.mirai.Bot import net.mamoe.mirai.console.MiraiConsole.INSTANCE import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start +import net.mamoe.mirai.console.extension.foldExtensions import net.mamoe.mirai.console.extensions.BotConfigurationAlterer -import net.mamoe.mirai.console.extensions.foldExtensions import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge import net.mamoe.mirai.console.plugin.PluginLoader import net.mamoe.mirai.console.plugin.PluginManager diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/AbstractExtensionPoint.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/AbstractExtensionPoint.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/AbstractExtensionPoint.kt rename to backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/AbstractExtensionPoint.kt index 5a5f41cf9..f6ddcc561 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/AbstractExtensionPoint.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/AbstractExtensionPoint.kt @@ -9,7 +9,7 @@ @file:Suppress("unused", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") -package net.mamoe.mirai.console.extensions +package net.mamoe.mirai.console.extension import net.mamoe.mirai.console.internal.data.kClassQualifiedNameOrTip import net.mamoe.mirai.console.plugin.Plugin diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/Extension.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/Extension.kt new file mode 100644 index 000000000..0c0250174 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/Extension.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.extension + +import net.mamoe.mirai.console.extensions.PermissionServiceProvider +import net.mamoe.mirai.console.extensions.PluginLoaderProvider +import net.mamoe.mirai.console.util.ConsoleExperimentalAPI + +@ConsoleExperimentalAPI +public interface Extension + +@ConsoleExperimentalAPI +public interface FunctionExtension : Extension + +/** + * 为某单例服务注册的 [Extension]. + * + * @see PermissionServiceProvider + */ +@ConsoleExperimentalAPI +public interface SingletonExtension : Extension { + public val instance: T +} + +/** + * 为一些实例注册的 [Extension]. + * + * @see PluginLoaderProvider + */ +@ConsoleExperimentalAPI +public interface InstanceExtension : Extension { + public val instance: T +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/BotConfigurationAlterer.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/BotConfigurationAlterer.kt index d48f6d9bf..69eda41c4 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/BotConfigurationAlterer.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/BotConfigurationAlterer.kt @@ -3,6 +3,8 @@ package net.mamoe.mirai.console.extensions import net.mamoe.mirai.console.MiraiConsole +import net.mamoe.mirai.console.extension.AbstractExtensionPoint +import net.mamoe.mirai.console.extension.FunctionExtension import net.mamoe.mirai.console.util.ConsoleExperimentalAPI import net.mamoe.mirai.utils.BotConfiguration @@ -12,7 +14,7 @@ import net.mamoe.mirai.utils.BotConfiguration * @see MiraiConsole.addBot */ @ConsoleExperimentalAPI -public interface BotConfigurationAlterer { +public interface BotConfigurationAlterer : FunctionExtension { /** * 修改 [configuration], 返回修改完成的 [BotConfiguration] diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/MiraiConsoleServices.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/MiraiConsoleServices.kt deleted file mode 100644 index af3f79bf5..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/MiraiConsoleServices.kt +++ /dev/null @@ -1,22 +0,0 @@ -package net.mamoe.mirai.console.extensions - -import net.mamoe.mirai.console.internal.util.PluginServiceHelper -import kotlin.reflect.KClass - -// not public now -internal object ServiceContainer { - private val instances: MutableMap, List<*>> = mutableMapOf() - - @Suppress("UNCHECKED_CAST") - @JvmStatic - @Synchronized - fun getService(clazz: KClass): List { - instances[clazz]?.let { return it as List } - PluginServiceHelper.loadAllServicesFromMemoryAndPluginClassLoaders(clazz).let { - instances[clazz] = it - return it - } - } - - inline fun getService(): List = getService(T::class) -} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PermissionServiceProvider.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PermissionServiceProvider.kt new file mode 100644 index 000000000..2d35375d8 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PermissionServiceProvider.kt @@ -0,0 +1,12 @@ +package net.mamoe.mirai.console.extensions + +import net.mamoe.mirai.console.extension.AbstractExtensionPoint +import net.mamoe.mirai.console.extension.SingletonExtension +import net.mamoe.mirai.console.permission.PermissionService +import net.mamoe.mirai.console.util.ConsoleExperimentalAPI + +@ConsoleExperimentalAPI +public interface PermissionServiceProvider : SingletonExtension { + public companion object ExtensionPoint : + AbstractExtensionPoint(PermissionServiceProvider::class) +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PluginLoaderProvider.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PluginLoaderProvider.kt index e0410f9ac..cf2271981 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PluginLoaderProvider.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PluginLoaderProvider.kt @@ -1,12 +1,12 @@ package net.mamoe.mirai.console.extensions +import net.mamoe.mirai.console.extension.AbstractExtensionPoint +import net.mamoe.mirai.console.extension.InstanceExtension import net.mamoe.mirai.console.plugin.PluginLoader /** * 提供扩展 [PluginLoader] */ -public interface PluginLoaderProvider { - public val instance: PluginLoader<*, *> - +public interface PluginLoaderProvider : InstanceExtension> { public companion object ExtensionPoint : AbstractExtensionPoint(PluginLoaderProvider::class) } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt index 03035b668..4bec6f753 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt @@ -15,8 +15,8 @@ import kotlinx.atomicfu.locks.withLock import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import net.mamoe.mirai.console.MiraiConsole +import net.mamoe.mirai.console.extension.useExtensions import net.mamoe.mirai.console.extensions.PluginLoaderProvider -import net.mamoe.mirai.console.extensions.useExtensions import net.mamoe.mirai.console.internal.data.cast import net.mamoe.mirai.console.internal.data.mkdir import net.mamoe.mirai.console.plugin.* diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt new file mode 100644 index 000000000..63b0b43f0 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.permission + +import net.mamoe.mirai.console.extensions.PermissionServiceProvider +import net.mamoe.mirai.console.util.ConsoleExperimentalAPI + +/** + * [PermissionServiceProvider] + */ +@ConsoleExperimentalAPI +public interface PermissionService \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 9034e5f2c..3970cc2a4 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -18,7 +18,7 @@ object Versions { const val core = "1.2.2" - const val console = "1.0-M4-dev-3" + const val console = "1.0-M4-dev-4" const val consoleGraphical = "0.0.7" const val consoleTerminal = "0.1.0" const val consolePure = console