mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Introduce general supertypes for Extension
This commit is contained in:
parent
f657590328
commit
d1db5a69f2
@ -18,8 +18,8 @@ import kotlinx.coroutines.Job
|
|||||||
import net.mamoe.mirai.Bot
|
import net.mamoe.mirai.Bot
|
||||||
import net.mamoe.mirai.console.MiraiConsole.INSTANCE
|
import net.mamoe.mirai.console.MiraiConsole.INSTANCE
|
||||||
import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start
|
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.BotConfigurationAlterer
|
||||||
import net.mamoe.mirai.console.extensions.foldExtensions
|
|
||||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||||
import net.mamoe.mirai.console.plugin.PluginLoader
|
import net.mamoe.mirai.console.plugin.PluginLoader
|
||||||
import net.mamoe.mirai.console.plugin.PluginManager
|
import net.mamoe.mirai.console.plugin.PluginManager
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
@file:Suppress("unused", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@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.internal.data.kClassQualifiedNameOrTip
|
||||||
import net.mamoe.mirai.console.plugin.Plugin
|
import net.mamoe.mirai.console.plugin.Plugin
|
@ -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<T> : Extension {
|
||||||
|
public val instance: T
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为一些实例注册的 [Extension].
|
||||||
|
*
|
||||||
|
* @see PluginLoaderProvider
|
||||||
|
*/
|
||||||
|
@ConsoleExperimentalAPI
|
||||||
|
public interface InstanceExtension<T> : Extension {
|
||||||
|
public val instance: T
|
||||||
|
}
|
@ -3,6 +3,8 @@
|
|||||||
package net.mamoe.mirai.console.extensions
|
package net.mamoe.mirai.console.extensions
|
||||||
|
|
||||||
import net.mamoe.mirai.console.MiraiConsole
|
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.console.util.ConsoleExperimentalAPI
|
||||||
import net.mamoe.mirai.utils.BotConfiguration
|
import net.mamoe.mirai.utils.BotConfiguration
|
||||||
|
|
||||||
@ -12,7 +14,7 @@ import net.mamoe.mirai.utils.BotConfiguration
|
|||||||
* @see MiraiConsole.addBot
|
* @see MiraiConsole.addBot
|
||||||
*/
|
*/
|
||||||
@ConsoleExperimentalAPI
|
@ConsoleExperimentalAPI
|
||||||
public interface BotConfigurationAlterer {
|
public interface BotConfigurationAlterer : FunctionExtension {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改 [configuration], 返回修改完成的 [BotConfiguration]
|
* 修改 [configuration], 返回修改完成的 [BotConfiguration]
|
||||||
|
@ -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<KClass<*>, List<*>> = mutableMapOf()
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
@JvmStatic
|
|
||||||
@Synchronized
|
|
||||||
fun <T : Any> getService(clazz: KClass<T>): List<T> {
|
|
||||||
instances[clazz]?.let { return it as List<T> }
|
|
||||||
PluginServiceHelper.loadAllServicesFromMemoryAndPluginClassLoaders(clazz).let {
|
|
||||||
instances[clazz] = it
|
|
||||||
return it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <reified T : Any> getService(): List<T> = getService(T::class)
|
|
||||||
}
|
|
@ -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<PermissionService> {
|
||||||
|
public companion object ExtensionPoint :
|
||||||
|
AbstractExtensionPoint<PermissionServiceProvider>(PermissionServiceProvider::class)
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package net.mamoe.mirai.console.extensions
|
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
|
import net.mamoe.mirai.console.plugin.PluginLoader
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提供扩展 [PluginLoader]
|
* 提供扩展 [PluginLoader]
|
||||||
*/
|
*/
|
||||||
public interface PluginLoaderProvider {
|
public interface PluginLoaderProvider : InstanceExtension<PluginLoader<*, *>> {
|
||||||
public val instance: PluginLoader<*, *>
|
|
||||||
|
|
||||||
public companion object ExtensionPoint : AbstractExtensionPoint<PluginLoaderProvider>(PluginLoaderProvider::class)
|
public companion object ExtensionPoint : AbstractExtensionPoint<PluginLoaderProvider>(PluginLoaderProvider::class)
|
||||||
}
|
}
|
@ -15,8 +15,8 @@ import kotlinx.atomicfu.locks.withLock
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import net.mamoe.mirai.console.MiraiConsole
|
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.PluginLoaderProvider
|
||||||
import net.mamoe.mirai.console.extensions.useExtensions
|
|
||||||
import net.mamoe.mirai.console.internal.data.cast
|
import net.mamoe.mirai.console.internal.data.cast
|
||||||
import net.mamoe.mirai.console.internal.data.mkdir
|
import net.mamoe.mirai.console.internal.data.mkdir
|
||||||
import net.mamoe.mirai.console.plugin.*
|
import net.mamoe.mirai.console.plugin.*
|
||||||
|
@ -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
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
object Versions {
|
object Versions {
|
||||||
const val core = "1.2.2"
|
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 consoleGraphical = "0.0.7"
|
||||||
const val consoleTerminal = "0.1.0"
|
const val consoleTerminal = "0.1.0"
|
||||||
const val consolePure = console
|
const val consolePure = console
|
||||||
|
Loading…
Reference in New Issue
Block a user