diff --git a/mirai-core-api/src/commonMain/kotlin/BotFactory.kt b/mirai-core-api/src/commonMain/kotlin/BotFactory.kt index af8806cc3..62a581470 100644 --- a/mirai-core-api/src/commonMain/kotlin/BotFactory.kt +++ b/mirai-core-api/src/commonMain/kotlin/BotFactory.kt @@ -20,27 +20,99 @@ import net.mamoe.mirai.utils.PlannedRemoval * @see IMirai.BotFactory */ public interface BotFactory { + /** + * 相当于 Kotlin lambda `BotConfiguration.() -> Unit` 和 Java `Consumer` + * + * @see newBot + */ + public fun interface BotConfigurationLambda { + public operator fun BotConfiguration.invoke() + } + + /////////////////////////////////////////////////////////////////////////// + // Plain Password + /////////////////////////////////////////////////////////////////////////// + /** * 使用指定的 [配置][configuration] 构造 [Bot] 实例 */ public fun newBot(qq: Long, password: String, configuration: BotConfiguration): Bot + /** + * 使用指定的 [配置][configuration] 构造 [Bot] 实例 + * + * Kotlin: + * ``` + * newBot(123, "") { + * // this: BotConfiguration + * fileBasedDeviceInfo() + * } + * ``` + * + * Java: + * ```java + * newBot(123, "", configuration -> { + * configuration.fileBasedDeviceInfo() + * }) + * ``` + */ + public fun newBot( + qq: Long, + password: String, + configuration: BotConfigurationLambda /* = BotConfiguration.() -> Unit */ + ): Bot = newBot(qq, password, configuration.run { BotConfiguration().apply { invoke() } }) + /** * 使用 [默认配置][BotConfiguration.Default] 构造 [Bot] 实例 */ public fun newBot(qq: Long, password: String): Bot = newBot(qq, password, BotConfiguration.Default) + /////////////////////////////////////////////////////////////////////////// + // MD5 Password + /////////////////////////////////////////////////////////////////////////// + /** * 使用指定的 [配置][configuration] 构造 [Bot] 实例 + * + * @param passwordMd5 16 bytes */ public fun newBot(qq: Long, passwordMd5: ByteArray, configuration: BotConfiguration): Bot + /** + * 使用指定的 [配置][configuration] 构造 [Bot] 实例 + * + * Kotlin: + * ``` + * newBot(123, password) { + * // this: BotConfiguration + * fileBasedDeviceInfo() + * } + * ``` + * + * Java: + * ```java + * newBot(123, password, configuration -> { + * configuration.fileBasedDeviceInfo() + * }) + * ``` + * + * @param passwordMd5 16 bytes + */ + public fun newBot( + qq: Long, + passwordMd5: ByteArray, + configuration: BotConfigurationLambda /* = BotConfiguration.() -> Unit */ + ): Bot = newBot(qq, passwordMd5, configuration.run { BotConfiguration().apply { invoke() } }) + /** * 使用 [默认配置][BotConfiguration.Default] 构造 [Bot] 实例 + * + * @param passwordMd5 16 bytes */ public fun newBot(qq: Long, passwordMd5: ByteArray): Bot = newBot(qq, passwordMd5, BotConfiguration.Default) + @Suppress("UNUSED_PARAMETER") @PlannedRemoval("2.0-M2") @Deprecated( @@ -83,14 +155,22 @@ public interface BotFactory { /** * 使用指定的 [配置][configuration] 构造 [Bot] 实例 */ +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "DeprecatedCallableAddReplaceWith") +@kotlin.internal.LowPriorityInOverloadResolution // resolves to member function +@Deprecated("Prefer member function") @JvmSynthetic +@PlannedRemoval("2.0-RC") public inline fun BotFactory.newBot(qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot = this.newBot(qq, password, BotConfiguration().apply(configuration)) /** * 使用指定的 [配置][configuration] 构造 [Bot] 实例 */ +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "DeprecatedCallableAddReplaceWith") +@kotlin.internal.LowPriorityInOverloadResolution // resolves to member function +@Deprecated("Prefer member function") @JvmSynthetic +@PlannedRemoval("2.0-RC") public inline fun BotFactory.newBot(qq: Long, password: ByteArray, configuration: (BotConfiguration.() -> Unit)): Bot = this.newBot(qq, password, BotConfiguration().apply(configuration))