Migrate deprecated usages and cleanup code

This commit is contained in:
Him188 2022-04-13 13:07:04 +01:00
parent 8993de9a13
commit 4acd74974a
18 changed files with 141 additions and 87 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
@ -44,7 +44,7 @@ internal object IntegrationTestBootstrapContext {
@PublishedApi
internal fun main() {
// PRE CHECK
kotlin.run {
run {
if (!System.getenv("MIRAI_CONSOLE_INTEGRATION_TEST").orEmpty().toBoolean()) {
error("Don't launch IntegrationTestBootstrap directly. See /test/MiraiConsoleIntegrationTestBootstrap.kt")
}
@ -63,7 +63,10 @@ internal fun main() {
val testUnits: List<AbstractTestPoint> = readStringListFromEnv("IT_POINTS").asSequence()
.onEach { println("[MCIT] Loading test point: $it") }
.map { Class.forName(it) }
.map { it.kotlin.objectInstance ?: it.newInstance() }
.map {
@Suppress("DEPRECATION")
it.kotlin.objectInstance ?: it.newInstance()
}
.map { it.cast<AbstractTestPoint>() }
.toList()

View File

@ -43,7 +43,6 @@ import net.mamoe.mirai.console.permission.PermissionId
import net.mamoe.mirai.console.permission.PermissionService
import net.mamoe.mirai.console.permission.PermissionService.Companion.cancel
import net.mamoe.mirai.console.permission.PermissionService.Companion.findCorrespondingPermissionOrFail
import net.mamoe.mirai.console.permission.PermissionService.Companion.getPermittedPermissions
import net.mamoe.mirai.console.permission.PermissionService.Companion.hasPermission
import net.mamoe.mirai.console.permission.PermissionService.Companion.permit
import net.mamoe.mirai.console.permission.PermitteeId
@ -57,6 +56,7 @@ import net.mamoe.mirai.event.events.EventCancelledException
import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.MiraiLogger
import java.lang.management.ManagementFactory
import java.lang.management.MemoryMXBean
import java.lang.management.MemoryUsage
import java.time.ZoneId
import java.time.format.DateTimeFormatter
@ -346,7 +346,7 @@ public object BuiltInCommands {
}
sendAnsiMessage {
ansi(BG_BLACK).white()
permMapping.forEach { (pid, tree) ->
permMapping.forEach { (_, tree) ->
if (!tree.linked) {
render(0, tree, this)
}
@ -555,13 +555,13 @@ public object BuiltInCommands {
val objectPendingFinalizationCount: Int
}
internal val memoryUsageGet: MemoryUsageGet = kotlin.runCatching {
private val memoryUsageGet: MemoryUsageGet = kotlin.runCatching {
ByMemoryMXBean
}.getOrElse { ByRuntime }
internal object ByMemoryMXBean : MemoryUsageGet {
val memoryMXBean = ManagementFactory.getMemoryMXBean()
val MemoryUsage.m: MUsage
private val memoryMXBean: MemoryMXBean = ManagementFactory.getMemoryMXBean()
private val MemoryUsage.m: MUsage
get() = MUsage(
committed, init, used, max
)

View File

@ -12,8 +12,6 @@ package net.mamoe.mirai.console.extension
import net.mamoe.mirai.console.command.parse.SpaceSeparatedCommandCallParser
import net.mamoe.mirai.console.extensions.PermissionServiceProvider
import net.mamoe.mirai.console.extensions.PluginLoaderProvider
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector.ExtensionPoint.selectSingleton
import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
import net.mamoe.mirai.console.plugin.jvm.JvmPlugin.Companion.onLoad
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
@ -61,7 +59,7 @@ public interface FunctionExtension : Extension
/**
* 为某单例服务注册的 [Extension].
*
* 若同时有多个实例可用, 将会使用 [SingletonExtensionSelector.selectSingleton] 选择
* 若同时有多个实例可用, 将会使用 [net.mamoe.mirai.console.extensions.SingletonExtensionSelector.selectSingleton] 选择
*
* @see PermissionServiceProvider
*/

View File

@ -11,7 +11,6 @@
package net.mamoe.mirai.console.extension
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
import net.mamoe.mirai.utils.DeprecatedSinceMirai
import kotlin.reflect.KClass
@ -39,6 +38,7 @@ public abstract class AbstractExtensionPoint<T : Extension>(
/**
* 表示一个 [SingletonExtension] [ExtensionPoint]
*/
@Suppress("DEPRECATION")
@Deprecated("Please use InstanceExtensionPoint instead.", replaceWith = ReplaceWith("InstanceExtensionPoint"))
@DeprecatedSinceMirai(warningSince = "2.11")
public interface SingletonExtensionPoint<T : SingletonExtension<*>> : ExtensionPoint<T>
@ -80,7 +80,7 @@ public constructor(
/**
* 内建的实现列表.
*/
builtinImplementations: () -> E,
@Suppress("UNUSED_PARAMETER") builtinImplementations: () -> E,
) : this(extensionType)
/**
@ -95,7 +95,7 @@ public constructor(
)
@DeprecatedSinceMirai(errorSince = "2.11") // for removal
@ConsoleExperimentalApi // was experimental since 2.0
public constructor(extensionType: KClass<E>, vararg builtinImplementations: E) : this(
public constructor(extensionType: KClass<E>, @Suppress("UNUSED_PARAMETER") vararg builtinImplementations: E) : this(
extensionType,
)
}
@ -134,7 +134,7 @@ constructor(
)
/**
* [SingletonExtensionSelector] 选择后的实例.
* [net.mamoe.mirai.console.extensions.SingletonExtensionSelector] 选择后的实例.
*/
@ConsoleExperimentalApi
public open val selectedInstance: T

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
@ -18,6 +18,7 @@ import net.mamoe.mirai.console.internal.extension.AbstractConcurrentComponentSto
import net.mamoe.mirai.console.permission.PermissionService
import net.mamoe.mirai.console.plugin.Plugin
import net.mamoe.mirai.console.plugin.loader.PluginLoader
import net.mamoe.mirai.utils.DeprecatedSinceMirai
import kotlin.reflect.full.companionObjectInstance
/**
@ -57,6 +58,12 @@ public class PluginComponentStorage(
///////////////////////////////////////////////////////////////////////////
/** 注册一个 [SingletonExtensionSelector] */
@Suppress("DeprecatedCallableAddReplaceWith", "DEPRECATION")
@Deprecated(
"Order of extensions is now determined by its priority property since 2.11. SingletonExtensionSelector is not needed anymore. ",
level = DeprecationLevel.WARNING
)
@DeprecatedSinceMirai(warningSince = "2.11")
public fun contributeSingletonExtensionSelector(lazyInstance: () -> SingletonExtensionSelector): Unit =
contribute(SingletonExtensionSelector, plugin, lazyInstance)
@ -77,6 +84,9 @@ public class PluginComponentStorage(
///////////////////////////////////////////////////////////////////////////
/** 注册一个 [PermissionServiceProvider] */
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("Deprecated for removal. Please implement your own CommandCallResolverProvider, and use contributePermissionService(provider).")
@DeprecatedSinceMirai(warningSince = "2.11") // for removal.
@OverloadResolutionByLambdaReturnType
public fun contributePermissionService(lazyInstance: () -> PermissionService<*>): Unit =
contribute(PermissionServiceProvider, plugin, PermissionServiceProviderImplLazy(lazyInstance))
@ -90,6 +100,9 @@ public class PluginComponentStorage(
/////////////////////////////////////
/** 注册一个 [PluginLoaderProvider] */
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("Deprecated for removal. Please implement your own CommandCallResolverProvider, and use contributePluginLoader(provider).")
@DeprecatedSinceMirai(warningSince = "2.11") // for removal.
@OverloadResolutionByLambdaReturnType
public fun contributePluginLoader(lazyInstance: () -> PluginLoader<*, *>): Unit =
contribute(PluginLoaderProvider, plugin, PluginLoaderProviderImplLazy(lazyInstance))
@ -103,6 +116,9 @@ public class PluginComponentStorage(
/////////////////////////////////////
/** 注册一个 [CommandCallParserProvider] */
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("Deprecated for removal. Please implement your own CommandCallResolverProvider, and use contributeCommandCallParser(provider).")
@DeprecatedSinceMirai(warningSince = "2.11") // for removal.
@ExperimentalCommandDescriptors
@OverloadResolutionByLambdaReturnType
public fun contributeCommandCallParser(lazyInstance: () -> CommandCallParser): Unit =
@ -117,7 +133,10 @@ public class PluginComponentStorage(
/////////////////////////////////////
/** 注册一个 [CommandCallResolverProvider] */
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("Deprecated for removal. Please implement your own CommandCallResolverProvider, and use contributeCommandCallResolver(provider).")
@DeprecatedSinceMirai(warningSince = "2.11") // for removal.
@ExperimentalCommandDescriptors
@OverloadResolutionByLambdaReturnType
public fun contributeCommandCallResolver(lazyInstance: () -> CommandCallResolver): Unit =
@ -133,6 +152,9 @@ public class PluginComponentStorage(
/////////////////////////////////////
/** 注册一个 [CommandCallInterceptorProvider] */
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("Deprecated for removal. Please implement your own CommandCallResolverProvider, and use contributeCommandCallInterceptor(provider).")
@DeprecatedSinceMirai(warningSince = "2.11") // for removal.
@ExperimentalCommandDescriptors
@OverloadResolutionByLambdaReturnType
public fun contributeCommandCallInterceptor(lazyInstance: () -> CommandCallInterceptor): Unit =

View File

@ -7,6 +7,8 @@
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@file:Suppress("DEPRECATION")
package net.mamoe.mirai.console.internal.extension
import kotlinx.coroutines.runBlocking

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
@ -124,6 +124,7 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
var linkedLogger by lateinitMutableProperty { MiraiConsole.createLogger("JvmPlugin[" + file_.name + "]") }
val undefinedDependencies = mutableSetOf<String>()
@Suppress("UNUSED_PARAMETER")
private constructor(file: File, ctx: JvmPluginsLoadingCtx, unused: Unit) : super(
arrayOf(), ctx.sharedLibrariesLoader
) {

View File

@ -37,7 +37,6 @@ import org.eclipse.aether.resolution.DependencyRequest
import org.eclipse.aether.resolution.DependencyResult
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory
import org.eclipse.aether.spi.connector.transport.TransporterFactory
import org.eclipse.aether.spi.locator.ServiceLocator
import org.eclipse.aether.transfer.AbstractTransferListener
import org.eclipse.aether.transfer.TransferEvent
import org.eclipse.aether.transport.http.HttpTransporterFactory
@ -50,9 +49,9 @@ internal class JvmPluginDependencyDownloader(
) {
val repositories: MutableList<RemoteRepository>
val session: RepositorySystemSession
val locator: ServiceLocator
val locator: org.eclipse.aether.spi.locator.ServiceLocator
val repository: RepositorySystem
val dependencyFilter: DependencyFilter = DependencyFilter { node, parents ->
val dependencyFilter: DependencyFilter = DependencyFilter { node, _ ->
if (node == null || node.artifact == null) return@DependencyFilter true
val artGroup = node.artifact.groupId
@ -205,7 +204,7 @@ internal class JvmPluginDependencyDownloader(
logger.debug { "Remote server: " + config.repoLoc }
}
public fun resolveDependencies(deps: Collection<String>, vararg filters: DependencyFilter): DependencyResult {
fun resolveDependencies(deps: Collection<String>, vararg filters: DependencyFilter): DependencyResult {
val dependencies: MutableList<Dependency> = ArrayList()
for (library in deps) {

View File

@ -1,10 +1,10 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
* 此源代码的使用受 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
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@file:JvmMultifileClass
@ -143,6 +143,6 @@ internal val IGNORED_DEPENDENCIES_IN_SHADOW = arrayOf(
"net.mamoe:kotlin-jvm-blocking-bridge-common",
"net.mamoe:kotlin-jvm-blocking-bridge-metadata",
"net.mamoe:kotlin-jvm-blocking-bridge-jvm"
).map { it.toLowerCase() }
).map { it.lowercase() }
.map { MiraiConsoleExtension.ExcludedDependency(it.substringBefore(':'), it.substringAfterLast(':')) }
.toTypedArray()

View File

@ -23,6 +23,7 @@ import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.registering
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import java.io.File
import java.util.*
private val Project.selfAndParentProjects: Sequence<Project>
@ -80,7 +81,13 @@ internal data class PluginMetadata(
)
internal fun String.wrapNameWithPlatform(target: KotlinTarget, isSingleTarget: Boolean): String {
return if (isSingleTarget) this else "$this${target.name.capitalize()}"
return if (isSingleTarget) this else "$this${
target.name.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}"
}
private fun Project.registerPublishPluginTasks(target: KotlinTarget, isSingleTarget: Boolean) {

View File

@ -1,10 +1,10 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
* 此源代码的使用受 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
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@ -118,7 +118,7 @@ fun String.adjustToClassName(): String? {
if (this.isEmpty()) append('_')
append(char)
}
char.isLetter() -> append(char.toUpperCase())
char.isLetter() -> append(char.uppercase())
char == '-' -> append("_")
else -> append(char)
}

View File

@ -1,10 +1,10 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
* 此源代码的使用受 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
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.console.intellij.diagnostics
@ -32,7 +32,6 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.inspections.collections.isCalling
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.ValueArgument
import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
@ -118,7 +117,7 @@ class ContextualParametersChecker : CallChecker {
"插件 Id '$value' 无效. 插件 Id 必须同时包含 groupId 和插件名称. $syntax"
)
val lowercaseId = value.toLowerCase()
val lowercaseId = value.lowercase()
if (ID_REGEX.matchEntire(value) == null) {
return ILLEGAL_PLUGIN_DESCRIPTION.on(
@ -135,7 +134,7 @@ class ContextualParametersChecker : CallChecker {
fun checkPluginName(inspectionTarget: PsiElement, value: String): Diagnostic? {
if (value.isBlank()) return ILLEGAL_PLUGIN_DESCRIPTION.on(inspectionTarget, "插件名不能为空")
val lowercaseName = value.toLowerCase()
val lowercaseName = value.lowercase()
FORBIDDEN_ID_NAMES.firstOrNull { it == lowercaseName }?.let { illegal ->
return ILLEGAL_PLUGIN_DESCRIPTION.on(inspectionTarget, "'$illegal' 不允许作为插件名. 确保插件名不完全是这个名称")
}

View File

@ -12,8 +12,11 @@ package net.mamoe.mirai.internal.contact
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.withTimeoutOrNull
import net.mamoe.mirai.contact.*
import net.mamoe.mirai.event.nextEventOrNull
import net.mamoe.mirai.event.EventPriority
import net.mamoe.mirai.event.GlobalEventChannel
import net.mamoe.mirai.event.nextEvent
import net.mamoe.mirai.internal.asQQAndroidBot
import net.mamoe.mirai.internal.getMiraiImpl
import net.mamoe.mirai.internal.message.*
@ -393,8 +396,10 @@ internal class FriendSendMessageHandler(
fromAppId: Int
): OnlineMessageSource.Outgoing {
val receipt: SendPrivateMessageReceipt = nextEventOrNull(3000) {
it.bot === bot && it.fromAppId == fromAppId
val receipt: SendPrivateMessageReceipt = withTimeoutOrNull(3000) {
GlobalEventChannel.parentScope(this).nextEvent(EventPriority.MONITOR) {
it.bot === bot && it.fromAppId == fromAppId
}
} ?: SendPrivateMessageReceipt.EMPTY
return OnlineMessageSourceToFriendImpl(
@ -448,8 +453,10 @@ internal open class GroupSendMessageHandler(
fromAppId: Int,
): OnlineMessageSource.Outgoing {
val receipt: SendGroupMessageReceipt = nextEventOrNull(3000) {
it.bot === bot && it.fromAppId == fromAppId
val receipt: SendGroupMessageReceipt = withTimeoutOrNull(3000) {
GlobalEventChannel.parentScope(this).nextEvent(EventPriority.MONITOR) {
it.bot === bot && it.fromAppId == fromAppId
}
} ?: SendGroupMessageReceipt.EMPTY
return OnlineMessageSourceToGroupImpl(

View File

@ -1,24 +1,23 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
* 此源代码的使用受 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
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_OVERRIDE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
package net.mamoe.mirai.internal.message
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.*
import kotlinx.serialization.Serializable
import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.*
import net.mamoe.mirai.event.asyncFromEventOrNull
import net.mamoe.mirai.event.EventPriority
import net.mamoe.mirai.event.GlobalEventChannel
import net.mamoe.mirai.event.syncFromEvent
import net.mamoe.mirai.internal.contact.uin
import net.mamoe.mirai.internal.network.notice.group.GroupMessageProcessor.SendGroupMessageReceipt
import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody
@ -169,18 +168,23 @@ internal class OnlineMessageSourceToGroupImpl(
private val sequenceIdDeferred: Deferred<IntArray?> = providedSequenceIds?.let { CompletableDeferred(it) } ?: run {
val multi = mutableMapOf<Int, Int>()
coroutineScope.asyncFromEventOrNull<SendGroupMessageReceipt, IntArray>(
timeoutMillis = 3000L * this@OnlineMessageSourceToGroupImpl.internalIds.size
) {
if (it.bot !== this.bot) return@asyncFromEventOrNull null
if (it.messageRandom in this@OnlineMessageSourceToGroupImpl.internalIds) {
multi[it.messageRandom] = it.sequenceId
if (multi.size == this@OnlineMessageSourceToGroupImpl.internalIds.size) {
IntArray(multi.size) { index ->
multi[this@OnlineMessageSourceToGroupImpl.internalIds[index]]!!
coroutineScope.async {
withTimeoutOrNull(
timeMillis = 3000L * this@OnlineMessageSourceToGroupImpl.internalIds.size
) {
GlobalEventChannel.parentScope(this)
.syncFromEvent<SendGroupMessageReceipt, IntArray>(EventPriority.MONITOR) { receipt ->
if (receipt.bot !== bot) return@syncFromEvent null
if (receipt.messageRandom in this@OnlineMessageSourceToGroupImpl.internalIds) {
multi[receipt.messageRandom] = receipt.sequenceId
if (multi.size == this@OnlineMessageSourceToGroupImpl.internalIds.size) {
IntArray(multi.size) { index ->
multi[this@OnlineMessageSourceToGroupImpl.internalIds[index]]!!
}
} else null
} else null
}
} else null
} else null
}
}
}

View File

@ -9,8 +9,11 @@
package net.mamoe.mirai.internal.network.components
import kotlinx.coroutines.withTimeoutOrNull
import net.mamoe.mirai.event.EventPriority
import net.mamoe.mirai.event.events.BotOfflineEvent
import net.mamoe.mirai.event.nextEventOrNull
import net.mamoe.mirai.event.globalEventChannel
import net.mamoe.mirai.event.nextEvent
import net.mamoe.mirai.internal.network.component.ComponentKey
import net.mamoe.mirai.internal.network.handler.NetworkHandler
import net.mamoe.mirai.internal.network.protocol.packet.login.ConfigPushSvc
@ -30,7 +33,13 @@ internal class ConfigPushProcessorImpl(
private val logger: MiraiLogger,
) : ConfigPushProcessor {
override suspend fun syncConfigPush(network: NetworkHandler) {
if (nextEventOrNull<ConfigPushSvc.PushReq.PushReqResponse>(60_000) { it.bot == network.context.bot } == null) {
val resp = withTimeoutOrNull(60_000) {
globalEventChannel().nextEvent<ConfigPushSvc.PushReq.PushReqResponse>(
EventPriority.MONITOR
) { it.bot == network.context.bot }
}
if (resp == null) {
val bdhSyncer = network.context[BdhSessionSyncer]
if (!bdhSyncer.hasSession) {
val e = IllegalStateException("Timeout waiting for ConfigPush.")

View File

@ -1,10 +1,10 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
* 此源代码的使用受 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
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.internal.network.components
@ -12,6 +12,7 @@ package net.mamoe.mirai.internal.network.components
import kotlinx.coroutines.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import net.mamoe.mirai.event.globalEventChannel
import net.mamoe.mirai.event.nextEvent
import net.mamoe.mirai.internal.QQAndroidBot
import net.mamoe.mirai.internal.network.component.ComponentKey
@ -59,7 +60,7 @@ internal class MessageSvcSyncerImpl(
logger.info { "Syncing friend message history..." }
withTimeoutOrNull(30000) {
launch(CoroutineName("Syncing friend message history")) {
nextEvent<MessageSvcPbGetMsg.GetMsgSuccess> {
globalEventChannel().nextEvent<MessageSvcPbGetMsg.GetMsgSuccess> {
it.bot == this@MessageSvcSyncerImpl.bot
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
@ -24,10 +24,10 @@ internal class OptimizeByteArrayAsHexStringTransformerTest : AbstractTest() {
private inline fun <reified T> analyzeTransformAndRender(
value: T,
renderer: ValueDescToStringRenderer = ValueDescToStringRenderer()
): String? {
): String {
return ValueDescAnalyzer.analyze(value)
.transform(OptimizeByteArrayAsHexStringTransformer())
?.renderToString(renderer)
.renderToString(renderer)
}
@Test

View File

@ -1,10 +1,10 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 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.
* 此源代码的使用受 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
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.internal.message.data
@ -42,7 +42,7 @@ internal class MessageReceiptTest : AbstractTestWithMiraiImpl() {
private val bot = MockBot()
/**
* This test is very ugly but we cannot do anything else.
* This test is very ugly, but we cannot do anything else.
*/ // We need #1304
@Test
fun `refine ForwardMessageInternal for MessageReceipt`() = runBlockingUnit {
@ -56,17 +56,19 @@ internal class MessageReceiptTest : AbstractTestWithMiraiImpl() {
val handler = object : GroupSendMessageHandler(group) {
override val messageSvcSendMessage: (client: QQAndroidClient, contact: GroupImpl, message: MessageChain, fragmented: Boolean, sourceCallback: (Deferred<OnlineMessageSource.Outgoing>) -> Unit) -> List<OutgoingPacket> =
{ _, contact, message, fragmented, sourceCallback ->
{ _, _, message, _, sourceCallback ->
assertIs<ForwardMessageInternal>(message[ForwardMessageInternal])
assertSame(forward, message[ForwardMessageInternal]?.origin)
sourceCallback(CompletableDeferred(OnlineMessageSourceToGroupImpl(
group,
internalIds = intArrayOf(1),
sender = bot,
target = group,
time = currentTimeSeconds().toInt(),
sourceCallback(
CompletableDeferred(
OnlineMessageSourceToGroupImpl(
group,
internalIds = intArrayOf(1),
sender = bot,
target = group,
time = currentTimeSeconds().toInt(),
originalMessage = message //,
// sourceMessage = message
)))