mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-12 05:50:27 +08:00
Update to mirai-core 2.0-M1-dev-3
This commit is contained in:
parent
fb4f51f19e
commit
cbbd6eb083
@ -20,8 +20,8 @@ kotlin {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileAndTestRuntime(`mirai-core`)
|
||||
compileAndTestRuntime(`kotlin-stdlib`)
|
||||
compileAndTestRuntime(`mirai-core-api`)
|
||||
compileAndTestRuntime(`mirai-core-utils`)
|
||||
compileAndTestRuntime(`kotlin-stdlib-jdk8`)
|
||||
|
||||
compileAndTestRuntime(`kotlinx-atomicfu`)
|
||||
@ -35,7 +35,7 @@ dependencies {
|
||||
smartImplementation(`caller-finder`)
|
||||
smartApi(`kotlinx-coroutines-jdk8`)
|
||||
|
||||
testApi(`mirai-core-qqandroid`)
|
||||
testApi(`mirai-core`)
|
||||
testApi(`kotlin-stdlib-jdk8`)
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ package net.mamoe.mirai.console
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.BotFactory
|
||||
import net.mamoe.mirai.console.MiraiConsole.INSTANCE
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start
|
||||
import net.mamoe.mirai.console.extensions.BotConfigurationAlterer
|
||||
@ -30,7 +31,6 @@ import net.mamoe.mirai.console.util.ConsoleInternalApi
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScopeContext
|
||||
import net.mamoe.mirai.console.util.SemVersion
|
||||
import net.mamoe.mirai.utils.BotConfiguration
|
||||
import net.mamoe.mirai.utils.DefaultLogger
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
@ -142,7 +142,7 @@ public interface MiraiConsole : CoroutineScope {
|
||||
fileBasedDeviceInfo()
|
||||
redirectNetworkLogToDirectory()
|
||||
this.botLoggerSupplier = {
|
||||
DefaultLogger("Bot.${it.id}")
|
||||
MiraiLogger.create("Bot.${it.id}")
|
||||
}
|
||||
parentCoroutineContext = MiraiConsole.childScopeContext("Bot $id")
|
||||
|
||||
@ -157,8 +157,8 @@ public interface MiraiConsole : CoroutineScope {
|
||||
}
|
||||
|
||||
return when (password) {
|
||||
is ByteArray -> Bot(id, password, config)
|
||||
is String -> Bot(id, password, config)
|
||||
is ByteArray -> BotFactory.newBot(id, password, config)
|
||||
is String -> BotFactory.newBot(id, password, config)
|
||||
else -> throw IllegalArgumentException("Bad password type: `${password.javaClass.name}`. Require ByteArray or String")
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
package net.mamoe.mirai.console
|
||||
|
||||
import net.mamoe.mirai.console.util.SemVersion
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||
|
||||
|
||||
/**
|
||||
@ -41,7 +41,7 @@ public interface MiraiConsoleFrontEndDescription {
|
||||
*
|
||||
* 返回 `null` 表示禁止 [MiraiConsole] 后端检查版本兼容性.
|
||||
*/
|
||||
@MiraiExperimentalAPI
|
||||
@MiraiExperimentalApi
|
||||
public val compatibleBackendVersion: SemVersion? get() = null
|
||||
|
||||
/**
|
||||
|
@ -33,6 +33,7 @@ import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScopeContext
|
||||
import net.mamoe.mirai.console.util.MessageScope
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.event.events.*
|
||||
import net.mamoe.mirai.message.*
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.message.data.PlainText
|
||||
|
@ -19,8 +19,6 @@ import net.mamoe.mirai.console.permission.AbstractPermitteeId
|
||||
import net.mamoe.mirai.console.permission.PermissionId
|
||||
import net.mamoe.mirai.console.permission.PermitteeId
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.getFriendOrNull
|
||||
import net.mamoe.mirai.getGroupOrNull
|
||||
import net.mamoe.mirai.message.data.*
|
||||
|
||||
|
||||
@ -167,7 +165,7 @@ public object ExistingFriendValueArgumentParser : InternalCommandValueArgumentPa
|
||||
public override fun parse(raw: MessageContent, sender: CommandSender): Friend {
|
||||
if (raw is At) {
|
||||
checkArgument(sender is MemberCommandSender)
|
||||
return sender.inferBotOrFail().getFriendOrNull(raw.target)
|
||||
return sender.inferBotOrFail().getFriend(raw.target)
|
||||
?: illegalArgument("At 的对象 ${raw.target} 非 Bot 好友")
|
||||
} else {
|
||||
illegalArgument("无法解析 $raw 为好友")
|
||||
@ -329,7 +327,7 @@ public object ExistingMemberValueArgumentParser : InternalCommandValueArgumentPa
|
||||
if (raw.target == bot.id) {
|
||||
return group.botAsMember
|
||||
}
|
||||
group[raw.target]
|
||||
group[raw.target] ?: illegalArgument("无法找到群员 ${raw.target}")
|
||||
} else {
|
||||
parse(raw.content, sender)
|
||||
}
|
||||
@ -374,20 +372,20 @@ internal abstract class InternalCommandValueArgumentParserExtensions<T : Any> :
|
||||
protected fun String.findBotOrFail(): Bot =
|
||||
Bot.getInstanceOrNull(this.parseToLongOrFail()) ?: illegalArgument("无法找到 Bot: $this")
|
||||
|
||||
protected fun Bot.findGroupOrFail(id: Long): Group = getGroupOrNull(id) ?: illegalArgument("无法找到群: $this")
|
||||
protected fun Bot.findGroupOrFail(id: Long): Group = getGroup(id) ?: illegalArgument("无法找到群: $this")
|
||||
|
||||
protected fun Bot.findGroupOrFail(id: String): Group =
|
||||
getGroupOrNull(id.parseToLongOrFail()) ?: illegalArgument("无法找到群: $this")
|
||||
getGroup(id.parseToLongOrFail()) ?: illegalArgument("无法找到群: $this")
|
||||
|
||||
protected fun Bot.findFriendOrFail(id: String): Friend =
|
||||
getFriendOrNull(id.parseToLongOrFail()) ?: illegalArgument("无法找到好友: $this")
|
||||
getFriend(id.parseToLongOrFail()) ?: illegalArgument("无法找到好友: $this")
|
||||
|
||||
protected fun Bot.findMemberOrFail(id: String): Friend =
|
||||
getFriendOrNull(id.parseToLongOrFail()) ?: illegalArgument("无法找到群员: $this")
|
||||
getFriend(id.parseToLongOrFail()) ?: illegalArgument("无法找到群员: $this")
|
||||
|
||||
protected fun Group.findMemberOrFail(idOrCard: String): Member {
|
||||
if (idOrCard == "\$") return members.randomOrNull() ?: illegalArgument("当前语境下无法推断随机群员")
|
||||
idOrCard.toLongOrNull()?.let { getOrNull(it) }?.let { return it }
|
||||
idOrCard.toLongOrNull()?.let { get(it) }?.let { return it }
|
||||
this.members.singleOrNull { it.nameCardOrNick.contains(idOrCard) }?.let { return it }
|
||||
this.members.singleOrNull { it.nameCardOrNick.contains(idOrCard, ignoreCase = true) }?.let { return it }
|
||||
|
||||
@ -410,7 +408,7 @@ internal abstract class InternalCommandValueArgumentParserExtensions<T : Any> :
|
||||
|
||||
protected fun CommandSender.inferBotOrFail(): Bot =
|
||||
(this as? UserCommandSender)?.bot
|
||||
?: Bot.botInstancesSequence.singleOrNull()
|
||||
?: Bot.instancesSequence.singleOrNull()
|
||||
?: illegalArgument("当前语境下无法推断目标 Bot, 因为目前有多个 Bot 在线.")
|
||||
|
||||
protected fun CommandSender.inferGroupOrFail(): Group =
|
||||
|
@ -39,11 +39,9 @@ public open class AutoSavePluginData private constructor(
|
||||
public final override val saveName: String
|
||||
get() = _saveName
|
||||
|
||||
private lateinit var _saveName: String
|
||||
private var _saveName: String = saveName
|
||||
|
||||
public constructor(saveName: String) : this(null) {
|
||||
_saveName = saveName
|
||||
}
|
||||
public constructor(saveName: String) : this(null)
|
||||
|
||||
@ConsoleExperimentalApi
|
||||
override fun onInit(owner: PluginDataHolder, storage: PluginDataStorage) {
|
||||
@ -103,7 +101,7 @@ public open class AutoSavePluginData private constructor(
|
||||
|
||||
private val updaterBlock: suspend CoroutineScope.() -> Unit = l@{
|
||||
if (::storage_.isInitialized) {
|
||||
currentFirstStartTime_.updateWhen({ it == MAGIC_NUMBER_CFST_INIT }, { currentTimeMillis })
|
||||
currentFirstStartTime_.updateWhen({ it == MAGIC_NUMBER_CFST_INIT }, { currentTimeMillis() })
|
||||
try {
|
||||
delay(autoSaveIntervalMillis_.first.coerceAtLeast(1000)) // for safety
|
||||
} catch (e: CancellationException) {
|
||||
@ -117,7 +115,7 @@ public open class AutoSavePluginData private constructor(
|
||||
}
|
||||
} else {
|
||||
if (currentFirstStartTime_.updateWhen(
|
||||
{ it != MAGIC_NUMBER_CFST_INIT && currentTimeMillis - it >= autoSaveIntervalMillis_.last },
|
||||
{ it != MAGIC_NUMBER_CFST_INIT && currentTimeMillis() - it >= autoSaveIntervalMillis_.last },
|
||||
{ MAGIC_NUMBER_CFST_INIT })
|
||||
) {
|
||||
withContext(owner_.coroutineContext) {
|
||||
@ -146,7 +144,7 @@ public open class AutoSavePluginData private constructor(
|
||||
}
|
||||
|
||||
internal val debuggingLogger1 by lazy {
|
||||
DefaultLogger("console.debug").withSwitch(false)
|
||||
MiraiLogger.create("console.debug").withSwitch(false)
|
||||
}
|
||||
|
||||
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
|
||||
|
@ -96,7 +96,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
||||
override val loggerController: LoggerController by instance::loggerController
|
||||
|
||||
init {
|
||||
DefaultLogger = this::createLogger
|
||||
MiraiLogger.setDefaultLoggerCreator(this::createLogger)
|
||||
}
|
||||
|
||||
|
||||
@ -134,7 +134,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
||||
}
|
||||
|
||||
MiraiConsole.job.invokeOnCompletion {
|
||||
Bot.botInstances.forEach { kotlin.runCatching { it.close() }.exceptionOrNull()?.let(mainLogger::error) }
|
||||
Bot.instances.forEach { kotlin.runCatching { it.close() }.exceptionOrNull()?.let(mainLogger::error) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,14 +56,13 @@ val experimentalAnnotations = arrayOf(
|
||||
"kotlin.io.path.ExperimentalPathApi",
|
||||
"io.ktor.util.KtorExperimentalAPI",
|
||||
|
||||
"net.mamoe.mirai.utils.MiraiInternalAPI",
|
||||
"net.mamoe.mirai.utils.MiraiExperimentalAPI",
|
||||
"net.mamoe.mirai.utils.MiraiInternalApi",
|
||||
"net.mamoe.mirai.utils.MiraiExperimentalApi",
|
||||
"net.mamoe.mirai.console.ConsoleFrontEndImplementation",
|
||||
"net.mamoe.mirai.console.util.ConsoleExperimentalApi",
|
||||
"net.mamoe.mirai.console.util.ConsoleInternalApi"
|
||||
)
|
||||
|
||||
|
||||
fun Project.configureJvmTarget() {
|
||||
tasks.withType(KotlinJvmCompile::class.java) {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
|
@ -9,22 +9,24 @@
|
||||
|
||||
@file:Suppress("MemberVisibilityCanBePrivate", "ObjectPropertyName", "unused")
|
||||
|
||||
import org.gradle.api.attributes.Attribute
|
||||
|
||||
object Versions {
|
||||
const val core = "1.3.3"
|
||||
const val core = "2.0-M1-dev-3"
|
||||
const val console = "1.1.0"
|
||||
const val consoleGraphical = "0.0.7"
|
||||
const val consoleTerminal = console
|
||||
|
||||
const val kotlinCompiler = "1.4.20"
|
||||
const val kotlinStdlib = "1.4.20"
|
||||
const val kotlinCompiler = "1.4.21"
|
||||
const val kotlinStdlib = "1.4.21"
|
||||
|
||||
const val kotlinIntellijPlugin = "1.4.20-release-IJ2020.2-1" // keep to newest as kotlinCompiler
|
||||
const val intellij = "2020.2.1" // don't update easily unless you want your disk space -= 500MB
|
||||
const val kotlinIntellijPlugin = "203-1.4.21-release-IJ5981.133" // keep to newest as kotlinCompiler
|
||||
const val intellij = "2020.3" // don't update easily unless you want your disk space -= 500MB
|
||||
|
||||
|
||||
const val coroutines = "1.4.0"
|
||||
const val serialization = "1.0.1"
|
||||
const val ktor = "1.4.1"
|
||||
const val ktor = "1.4.3"
|
||||
const val atomicFU = "0.14.4"
|
||||
|
||||
const val androidGradle = "3.6.2"
|
||||
@ -56,9 +58,9 @@ const val `kotlinx-serialization-protobuf` = "org.jetbrains.kotlinx:kotlinx-seri
|
||||
|
||||
const val `kotlinx-atomicfu` = "org.jetbrains.kotlinx:atomicfu:${Versions.atomicFU}"
|
||||
|
||||
const val `mirai-core` = "net.mamoe:mirai-core:${Versions.core}"
|
||||
const val `mirai-core-qqandroid` = "net.mamoe:mirai-core-qqandroid:${Versions.core}"
|
||||
const val `mirai-core-api` = "net.mamoe:mirai-core-api:${Versions.core}"
|
||||
const val `mirai-core` = "net.mamoe:mirai-core:${Versions.core}"
|
||||
const val `mirai-core-utils` = "net.mamoe:mirai-core-utils:${Versions.core}"
|
||||
|
||||
const val yamlkt = "net.mamoe.yamlkt:yamlkt:${Versions.yamlkt}"
|
||||
|
||||
@ -66,3 +68,6 @@ const val `jetbrains-annotations` = "org.jetbrains:annotations:19.0.0"
|
||||
|
||||
|
||||
const val `caller-finder` = "io.github.karlatemp:caller:1.0.1"
|
||||
|
||||
|
||||
val ATTRIBUTE_MIRAI_TARGET_PLATFORM: Attribute<String> = Attribute.of("mirai.target.platform", String::class.java)
|
@ -6,41 +6,15 @@ plugins {
|
||||
id("com.jfrog.bintray")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
target.compilations.all {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs = freeCompilerArgs + "-Xjvm-default=all"
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
|
||||
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
|
||||
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
|
||||
languageSettings.progressiveMode = true
|
||||
languageSettings.useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiInternalAPI")
|
||||
languageSettings.useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiExperimentalAPI")
|
||||
languageSettings.useExperimentalAnnotation("net.mamoe.mirai.console.util.ConsoleExperimentalApi")
|
||||
languageSettings.useExperimentalAnnotation("net.mamoe.mirai.console.ConsoleFrontEndImplementation")
|
||||
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
|
||||
languageSettings.useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference")
|
||||
languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jline:jline:3.15.0")
|
||||
implementation("org.fusesource.jansi:jansi:1.18")
|
||||
|
||||
compileAndTestRuntime(project(":mirai-console"))
|
||||
compileAndTestRuntime("net.mamoe:mirai-core:${Versions.core}")
|
||||
compileAndTestRuntime(kotlin("stdlib-jdk8", Versions.kotlinStdlib)) // embedded by core
|
||||
compileAndTestRuntime(`mirai-core-api`)
|
||||
compileAndTestRuntime(kotlin("stdlib-jdk8", Versions.kotlinStdlib)) // must specify `compileOnly` explicitly
|
||||
|
||||
testApi("net.mamoe:mirai-core-qqandroid:${Versions.core}")
|
||||
testApi(`mirai-core`)
|
||||
testApi(project(":mirai-console"))
|
||||
}
|
||||
|
||||
|
@ -26,14 +26,14 @@ import net.mamoe.mirai.console.util.ConsoleInternalApi
|
||||
import net.mamoe.mirai.console.util.cast
|
||||
import net.mamoe.mirai.console.util.requestInput
|
||||
import net.mamoe.mirai.console.util.safeCast
|
||||
import net.mamoe.mirai.utils.DefaultLogger
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import net.mamoe.mirai.utils.warning
|
||||
import org.jline.reader.EndOfFileException
|
||||
import org.jline.reader.UserInterruptException
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
|
||||
val consoleLogger by lazy { DefaultLogger("console") }
|
||||
val consoleLogger by lazy { MiraiLogger.create("console") }
|
||||
|
||||
@OptIn(ConsoleInternalApi::class, ConsoleTerminalExperimentalApi::class, ExperimentalCommandDescriptors::class)
|
||||
internal fun startupConsoleThread() {
|
||||
|
@ -31,12 +31,12 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
import net.mamoe.mirai.console.util.ConsoleInternalApi
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.utils.DefaultLogger
|
||||
import net.mamoe.mirai.utils.minutesToMillis
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import java.io.FileDescriptor
|
||||
import java.io.FileOutputStream
|
||||
import java.io.PrintStream
|
||||
import kotlin.system.exitProcess
|
||||
import kotlin.time.minutes
|
||||
|
||||
/**
|
||||
* mirai-console-terminal CLI 入口点
|
||||
@ -159,7 +159,7 @@ object MiraiConsoleTerminalLoader {
|
||||
internal object ConsoleDataHolder : AutoSavePluginDataHolder,
|
||||
CoroutineScope by MiraiConsole.childScope("ConsoleDataHolder") {
|
||||
@ConsoleExperimentalApi
|
||||
override val autoSaveIntervalMillis: LongRange = 1.minutesToMillis..10.minutesToMillis
|
||||
override val autoSaveIntervalMillis: LongRange = 1.minutes.toLongMilliseconds()..10.minutes.toLongMilliseconds()
|
||||
|
||||
@ConsoleExperimentalApi
|
||||
override val dataHolderName: String
|
||||
@ -170,7 +170,7 @@ internal fun overrideSTD() {
|
||||
System.setOut(
|
||||
PrintStream(
|
||||
BufferedOutputStream(
|
||||
logger = DefaultLogger("stdout").run { ({ line: String? -> info(line) }) }
|
||||
logger = MiraiLogger.create("stdout").run { ({ line: String? -> info(line) }) }
|
||||
),
|
||||
false,
|
||||
"UTF-8"
|
||||
@ -179,7 +179,7 @@ internal fun overrideSTD() {
|
||||
System.setErr(
|
||||
PrintStream(
|
||||
BufferedOutputStream(
|
||||
logger = DefaultLogger("stderr").run { ({ line: String? -> warning(line) }) }
|
||||
logger = MiraiLogger.create("stderr").run { ({ line: String? -> warning(line) }) }
|
||||
),
|
||||
false,
|
||||
"UTF-8"
|
||||
|
@ -10,6 +10,6 @@
|
||||
package net.mamoe.mirai.console.gradle
|
||||
|
||||
internal object VersionConstants {
|
||||
const val CONSOLE_VERSION = "1.1.0" // value is written here automatically during build
|
||||
const val CORE_VERSION = "1.3.3" // value is written here automatically during build
|
||||
const val CONSOLE_VERSION = "2.0-M1" // value is written here automatically during build
|
||||
const val CORE_VERSION = "2.0-M1-dev-3" // value is written here automatically during build
|
||||
}
|
@ -23,7 +23,7 @@ intellij {
|
||||
updateSinceUntilBuild = false
|
||||
|
||||
setPlugins(
|
||||
"org.jetbrains.kotlin:${Versions.kotlinIntellijPlugin}@eap",
|
||||
"org.jetbrains.kotlin:${Versions.kotlinIntellijPlugin}", // @eap
|
||||
"java"
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user