mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Fix build
This commit is contained in:
parent
9f8ce56f15
commit
91d2b0b7d2
@ -15,6 +15,7 @@ import kotlinx.io.charsets.Charset
|
|||||||
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.command.ConsoleCommandOwner
|
import net.mamoe.mirai.console.command.ConsoleCommandOwner
|
||||||
|
import net.mamoe.mirai.console.command.ConsoleCommandSender
|
||||||
import net.mamoe.mirai.console.plugin.PluginLoader
|
import net.mamoe.mirai.console.plugin.PluginLoader
|
||||||
import net.mamoe.mirai.console.plugin.center.CuiPluginCenter
|
import net.mamoe.mirai.console.plugin.center.CuiPluginCenter
|
||||||
import net.mamoe.mirai.console.plugin.center.PluginCenter
|
import net.mamoe.mirai.console.plugin.center.PluginCenter
|
||||||
@ -93,61 +94,42 @@ internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mira
|
|||||||
internal object MiraiConsoleInternal : CoroutineScope, IMiraiConsole, MiraiConsole {
|
internal object MiraiConsoleInternal : CoroutineScope, IMiraiConsole, MiraiConsole {
|
||||||
override val pluginCenter: PluginCenter get() = CuiPluginCenter
|
override val pluginCenter: PluginCenter get() = CuiPluginCenter
|
||||||
|
|
||||||
private val instance: IMiraiConsole
|
private val instance: IMiraiConsole get() = MiraiConsoleInitializer.instance
|
||||||
get() = MiraiConsoleInitializer.instance
|
override val buildDate: Date get() = MiraiConsoleBuildConstants.buildDate
|
||||||
|
|
||||||
/**
|
|
||||||
* `mirai-console` build 号
|
|
||||||
*
|
|
||||||
* UTC+8 时间
|
|
||||||
*/
|
|
||||||
override val buildDate: Date
|
|
||||||
get() = MiraiConsoleBuildConstants.buildDate
|
|
||||||
|
|
||||||
/**
|
|
||||||
* `mirai-console` 版本
|
|
||||||
*/
|
|
||||||
override val version: String get() = MiraiConsoleBuildConstants.version
|
override val version: String get() = MiraiConsoleBuildConstants.version
|
||||||
|
|
||||||
/**
|
|
||||||
* Console 运行路径
|
|
||||||
*/
|
|
||||||
override val rootDir: File get() = instance.rootDir
|
override val rootDir: File get() = instance.rootDir
|
||||||
|
|
||||||
/**
|
|
||||||
* Console 前端接口
|
|
||||||
*/
|
|
||||||
override val frontEnd: MiraiConsoleFrontEnd get() = instance.frontEnd
|
override val frontEnd: MiraiConsoleFrontEnd get() = instance.frontEnd
|
||||||
|
|
||||||
/**
|
|
||||||
* 与前端交互所使用的 Logger
|
|
||||||
*/
|
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
override val mainLogger: MiraiLogger
|
override val mainLogger: MiraiLogger
|
||||||
get() = instance.mainLogger
|
get() = instance.mainLogger
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext get() = instance.coroutineContext
|
override val coroutineContext: CoroutineContext get() = instance.coroutineContext
|
||||||
|
|
||||||
override val builtInPluginLoaders: List<PluginLoader<*, *>> get() = instance.builtInPluginLoaders
|
override val builtInPluginLoaders: List<PluginLoader<*, *>> get() = instance.builtInPluginLoaders
|
||||||
|
override val consoleCommandOwner: ConsoleCommandOwner get() = instance.consoleCommandOwner
|
||||||
override val consoleCommandOwner: ConsoleCommandOwner
|
override val consoleCommandSender: ConsoleCommandSender get() = instance.consoleCommandSender
|
||||||
get() = instance.consoleCommandOwner
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
DefaultLogger = { identity -> this.newLogger(identity) }
|
DefaultLogger = { identity -> this.newLogger(identity) }
|
||||||
this.coroutineContext[Job]!!.invokeOnCompletion {
|
|
||||||
Bot.botInstances.forEach { kotlin.runCatching { it.close() }.exceptionOrNull()?.let(mainLogger::error) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
override fun newLogger(identity: String?): MiraiLogger = frontEnd.loggerFor(identity)
|
override fun newLogger(identity: String?): MiraiLogger = frontEnd.loggerFor(identity)
|
||||||
|
|
||||||
internal fun initialize() {
|
internal fun initialize() {
|
||||||
|
if (coroutineContext[Job] == null) {
|
||||||
|
throw IllegalMiraiConsoleImplementationError("The coroutineContext given to MiraiConsole must have a Job in it.")
|
||||||
|
}
|
||||||
|
this.coroutineContext[Job]!!.invokeOnCompletion {
|
||||||
|
Bot.botInstances.forEach { kotlin.runCatching { it.close() }.exceptionOrNull()?.let(mainLogger::error) }
|
||||||
|
}
|
||||||
// Only for initialize
|
// Only for initialize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class IllegalMiraiConsoleImplementationError(
|
||||||
|
override val message: String?
|
||||||
|
) : Error()
|
||||||
|
|
||||||
|
|
||||||
// 前端使用
|
// 前端使用
|
||||||
internal interface IMiraiConsole : CoroutineScope {
|
internal interface IMiraiConsole : CoroutineScope {
|
||||||
@ -173,6 +155,9 @@ internal interface IMiraiConsole : CoroutineScope {
|
|||||||
|
|
||||||
@Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION")
|
@Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION")
|
||||||
internal val consoleCommandOwner: ConsoleCommandOwner
|
internal val consoleCommandOwner: ConsoleCommandOwner
|
||||||
|
|
||||||
|
@Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION")
|
||||||
|
internal val consoleCommandSender: ConsoleCommandSender
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,13 +22,6 @@ import net.mamoe.mirai.utils.MiraiLogger
|
|||||||
interface MiraiConsoleFrontEnd {
|
interface MiraiConsoleFrontEnd {
|
||||||
fun loggerFor(identity: String?): MiraiLogger
|
fun loggerFor(identity: String?): MiraiLogger
|
||||||
|
|
||||||
/**
|
|
||||||
* 让 UI 层准备接受新增的一个BOT
|
|
||||||
*/
|
|
||||||
fun prePushBot(
|
|
||||||
identity: Long
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 让 UI 层接受一个新的bot
|
* 让 UI 层接受一个新的bot
|
||||||
* */
|
* */
|
||||||
@ -41,18 +34,8 @@ interface MiraiConsoleFrontEnd {
|
|||||||
*/
|
*/
|
||||||
suspend fun requestInput(hint: String): String
|
suspend fun requestInput(hint: String): String
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 让 UI 层更新 bot 管理员的数据
|
|
||||||
*/
|
|
||||||
fun pushBotAdminStatus(
|
|
||||||
identity: Long,
|
|
||||||
admins: List<Long>
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 由 UI 层创建一个 [LoginSolver]
|
* 由 UI 层创建一个 [LoginSolver]
|
||||||
*/
|
*/
|
||||||
fun createLoginSolver(): LoginSolver
|
fun createLoginSolver(): LoginSolver
|
||||||
|
|
||||||
}
|
}
|
@ -33,22 +33,20 @@ object JarPluginLoader : AbstractFilePluginLoader<JvmPlugin, JvmPluginDescriptio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
val settingStorage: SettingStorage = TODO()
|
val settingStorage: SettingStorage by lazy { TODO() }
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext by lazy {
|
override val coroutineContext: CoroutineContext by lazy {
|
||||||
MiraiConsole.coroutineContext + SupervisorJob(
|
MiraiConsole.coroutineContext + SupervisorJob(
|
||||||
MiraiConsole.coroutineContext[Job]
|
MiraiConsole.coroutineContext[Job]
|
||||||
) + CoroutineExceptionHandler { _, throwable ->
|
) + CoroutineExceptionHandler { _, throwable ->
|
||||||
logger.error("Unhandled Jar plugin exception: ${throwable.message}", throwable)
|
logger.error("Unhandled Jar plugin exception: ${throwable.message}", throwable)
|
||||||
|
}.also { init() }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private val supervisor: Job = coroutineContext[Job]!!
|
|
||||||
|
|
||||||
private val classLoader: PluginsLoader =
|
private val classLoader: PluginsLoader by lazy { PluginsLoader(this.javaClass.classLoader) }
|
||||||
PluginsLoader(this.javaClass.classLoader)
|
|
||||||
|
|
||||||
init {
|
private fun init() { // delayed
|
||||||
supervisor.invokeOnCompletion {
|
coroutineContext[Job]!!.invokeOnCompletion {
|
||||||
classLoader.clear()
|
classLoader.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user