mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-07 16:40:43 +08:00
Add getMiraiImpl
to replace direct calls of MiraiImpl.INSTANCE
This commit is contained in:
parent
91a9e63877
commit
a59d7208cb
@ -63,6 +63,8 @@ import kotlin.io.use
|
|||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
internal fun getMiraiImpl() = Mirai as MiraiImpl
|
||||||
|
|
||||||
@OptIn(LowLevelApi::class)
|
@OptIn(LowLevelApi::class)
|
||||||
// not object for ServiceLoader.
|
// not object for ServiceLoader.
|
||||||
internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
||||||
@ -823,7 +825,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
return jsonText?.let { json.decodeFromString(GroupHonorListData.serializer(), it) }
|
return jsonText?.let { json.decodeFromString(GroupHonorListData.serializer(), it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal suspend fun uploadMessageHighway(
|
internal open suspend fun uploadMessageHighway(
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
sendMessageHandler: SendMessageHandler<*>,
|
sendMessageHandler: SendMessageHandler<*>,
|
||||||
message: Collection<ForwardMessage.INode>,
|
message: Collection<ForwardMessage.INode>,
|
||||||
|
@ -12,6 +12,7 @@ package net.mamoe.mirai.internal.contact
|
|||||||
import net.mamoe.mirai.contact.AnonymousMember
|
import net.mamoe.mirai.contact.AnonymousMember
|
||||||
import net.mamoe.mirai.data.MemberInfo
|
import net.mamoe.mirai.data.MemberInfo
|
||||||
import net.mamoe.mirai.internal.MiraiImpl
|
import net.mamoe.mirai.internal.MiraiImpl
|
||||||
|
import net.mamoe.mirai.internal.getMiraiImpl
|
||||||
import net.mamoe.mirai.message.data.Image
|
import net.mamoe.mirai.message.data.Image
|
||||||
import net.mamoe.mirai.utils.ExternalResource
|
import net.mamoe.mirai.utils.ExternalResource
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
@ -24,7 +25,7 @@ internal class AnonymousMemberImpl(
|
|||||||
) : AnonymousMember, AbstractMember(group, coroutineContext, memberInfo) {
|
) : AnonymousMember, AbstractMember(group, coroutineContext, memberInfo) {
|
||||||
override suspend fun mute(durationSeconds: Int) {
|
override suspend fun mute(durationSeconds: Int) {
|
||||||
checkBotPermissionHigherThanThis("mute")
|
checkBotPermissionHigherThanThis("mute")
|
||||||
MiraiImpl.muteAnonymousMember(bot, anonymousId, nameCard, group.uin, durationSeconds)
|
getMiraiImpl().muteAnonymousMember(bot, anonymousId, nameCard, group.uin, durationSeconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String = "AnonymousMember($nameCard, $anonymousId)"
|
override fun toString(): String = "AnonymousMember($nameCard, $anonymousId)"
|
||||||
|
@ -16,6 +16,7 @@ import net.mamoe.mirai.contact.*
|
|||||||
import net.mamoe.mirai.event.nextEventOrNull
|
import net.mamoe.mirai.event.nextEventOrNull
|
||||||
import net.mamoe.mirai.internal.MiraiImpl
|
import net.mamoe.mirai.internal.MiraiImpl
|
||||||
import net.mamoe.mirai.internal.asQQAndroidBot
|
import net.mamoe.mirai.internal.asQQAndroidBot
|
||||||
|
import net.mamoe.mirai.internal.getMiraiImpl
|
||||||
import net.mamoe.mirai.internal.message.*
|
import net.mamoe.mirai.internal.message.*
|
||||||
import net.mamoe.mirai.internal.message.LightMessageRefiner.refineLight
|
import net.mamoe.mirai.internal.message.LightMessageRefiner.refineLight
|
||||||
import net.mamoe.mirai.internal.network.Packet
|
import net.mamoe.mirai.internal.network.Packet
|
||||||
@ -233,7 +234,7 @@ internal abstract class SendMessageHandler<C : Contact> {
|
|||||||
open suspend fun uploadLongMessageHighway(
|
open suspend fun uploadLongMessageHighway(
|
||||||
chain: MessageChain,
|
chain: MessageChain,
|
||||||
): String = with(contact) {
|
): String = with(contact) {
|
||||||
return MiraiImpl.uploadMessageHighway(
|
return getMiraiImpl().uploadMessageHighway(
|
||||||
bot, this@SendMessageHandler,
|
bot, this@SendMessageHandler,
|
||||||
listOf(
|
listOf(
|
||||||
ForwardMessage.Node(
|
ForwardMessage.Node(
|
||||||
@ -275,7 +276,7 @@ internal suspend fun <C : Contact> SendMessageHandler<C>.transformSpecialMessage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val resId = MiraiImpl.uploadMessageHighway(
|
val resId = getMiraiImpl().uploadMessageHighway(
|
||||||
bot = contact.bot,
|
bot = contact.bot,
|
||||||
sendMessageHandler = this,
|
sendMessageHandler = this,
|
||||||
message = forward.nodeList,
|
message = forward.nodeList,
|
||||||
|
@ -16,6 +16,7 @@ import net.mamoe.mirai.Bot
|
|||||||
import net.mamoe.mirai.internal.AbstractTestWithMiraiImpl
|
import net.mamoe.mirai.internal.AbstractTestWithMiraiImpl
|
||||||
import net.mamoe.mirai.internal.MiraiImpl
|
import net.mamoe.mirai.internal.MiraiImpl
|
||||||
import net.mamoe.mirai.internal.MockBot
|
import net.mamoe.mirai.internal.MockBot
|
||||||
|
import net.mamoe.mirai.internal.getMiraiImpl
|
||||||
import net.mamoe.mirai.internal.message.DeepMessageRefiner.refineDeep
|
import net.mamoe.mirai.internal.message.DeepMessageRefiner.refineDeep
|
||||||
import net.mamoe.mirai.internal.message.LightMessageRefiner.refineLight
|
import net.mamoe.mirai.internal.message.LightMessageRefiner.refineLight
|
||||||
import net.mamoe.mirai.internal.message.OfflineMessageSourceImplData
|
import net.mamoe.mirai.internal.message.OfflineMessageSourceImplData
|
||||||
@ -267,7 +268,7 @@ internal class MessageRefineTest : AbstractTestWithMiraiImpl() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test nested forward refinement`() = runBlockingUnit {
|
fun `test nested forward refinement`() = runBlockingUnit {
|
||||||
val redefined = MiraiImpl.run { testCases.nestedForward.toForwardMessageNodes(bot) }
|
val redefined = getMiraiImpl().run { testCases.nestedForward.toForwardMessageNodes(bot) }
|
||||||
assertNodesEquals(
|
assertNodesEquals(
|
||||||
listOf(
|
listOf(
|
||||||
ForwardMessage.Node(
|
ForwardMessage.Node(
|
||||||
|
Loading…
Reference in New Issue
Block a user