mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-29 17:20:11 +08:00
parent
0baaf9d587
commit
57eb716e31
@ -64,7 +64,9 @@ public abstract interface class net/mamoe/mirai/BotFactory$BotConfigurationLambd
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class net/mamoe/mirai/BotFactory$INSTANCE : net/mamoe/mirai/BotFactory {
|
public final class net/mamoe/mirai/BotFactory$INSTANCE : net/mamoe/mirai/BotFactory {
|
||||||
|
public final synthetic fun newBot (JLjava/lang/String;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/Bot;
|
||||||
public fun newBot (JLjava/lang/String;Lnet/mamoe/mirai/utils/BotConfiguration;)Lnet/mamoe/mirai/Bot;
|
public fun newBot (JLjava/lang/String;Lnet/mamoe/mirai/utils/BotConfiguration;)Lnet/mamoe/mirai/Bot;
|
||||||
|
public final synthetic fun newBot (J[BLkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/Bot;
|
||||||
public fun newBot (J[BLnet/mamoe/mirai/utils/BotConfiguration;)Lnet/mamoe/mirai/Bot;
|
public fun newBot (J[BLnet/mamoe/mirai/utils/BotConfiguration;)Lnet/mamoe/mirai/Bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,9 @@ public abstract interface class net/mamoe/mirai/BotFactory$BotConfigurationLambd
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class net/mamoe/mirai/BotFactory$INSTANCE : net/mamoe/mirai/BotFactory {
|
public final class net/mamoe/mirai/BotFactory$INSTANCE : net/mamoe/mirai/BotFactory {
|
||||||
|
public final synthetic fun newBot (JLjava/lang/String;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/Bot;
|
||||||
public fun newBot (JLjava/lang/String;Lnet/mamoe/mirai/utils/BotConfiguration;)Lnet/mamoe/mirai/Bot;
|
public fun newBot (JLjava/lang/String;Lnet/mamoe/mirai/utils/BotConfiguration;)Lnet/mamoe/mirai/Bot;
|
||||||
|
public final synthetic fun newBot (J[BLkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/Bot;
|
||||||
public fun newBot (J[BLnet/mamoe/mirai/utils/BotConfiguration;)Lnet/mamoe/mirai/Bot;
|
public fun newBot (J[BLnet/mamoe/mirai/utils/BotConfiguration;)Lnet/mamoe/mirai/Bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,5 +118,46 @@ public interface BotFactory {
|
|||||||
override fun newBot(qq: Long, passwordMd5: ByteArray, configuration: BotConfiguration): Bot {
|
override fun newBot(qq: Long, passwordMd5: ByteArray, configuration: BotConfiguration): Bot {
|
||||||
return Mirai.BotFactory.newBot(qq, passwordMd5, configuration)
|
return Mirai.BotFactory.newBot(qq, passwordMd5, configuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* newBot(123, "") {
|
||||||
|
* // this: BotConfiguration
|
||||||
|
* fileBasedDeviceInfo()
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @since 2.7
|
||||||
|
*/
|
||||||
|
@JvmSynthetic
|
||||||
|
public inline fun newBot(
|
||||||
|
qq: Long,
|
||||||
|
password: String,
|
||||||
|
configuration: BotConfiguration.() -> Unit /* = BotConfiguration.() -> Unit */
|
||||||
|
): Bot = newBot(qq, password, configuration.run { BotConfiguration().apply(configuration) })
|
||||||
|
|
||||||
|
// implementation notes: this is inline for `inheritCoroutineContext()`
|
||||||
|
// see https://github.com/mamoe/mirai/commit/0dbb448cad1ed4773d48ccb8c0b497841bc9fa4c#r50249446
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* newBot(123, password) {
|
||||||
|
* // this: BotConfiguration
|
||||||
|
* fileBasedDeviceInfo()
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @since 2.7
|
||||||
|
*/
|
||||||
|
@JvmSynthetic
|
||||||
|
public inline fun newBot(
|
||||||
|
qq: Long,
|
||||||
|
passwordMd5: ByteArray,
|
||||||
|
configuration: BotConfiguration.() -> Unit /* = BotConfiguration.() -> Unit */
|
||||||
|
): Bot = newBot(qq, passwordMd5, configuration.run { BotConfiguration().apply(configuration) })
|
||||||
}
|
}
|
||||||
}
|
}
|
26
mirai-core/src/jvmTest/kotlin/BotFactoryTest.kt
Normal file
26
mirai-core/src/jvmTest/kotlin/BotFactoryTest.kt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2021 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.internal
|
||||||
|
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import net.mamoe.mirai.BotFactory
|
||||||
|
import kotlin.test.Test
|
||||||
|
|
||||||
|
internal class BotFactoryTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `inlined newBot in Kotlin`() {
|
||||||
|
runBlocking {
|
||||||
|
BotFactory.newBot(123, "") {
|
||||||
|
inheritCoroutineContext()
|
||||||
|
}.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user