From 00f33120ec4f4ec5955867d45500271f2930aa86 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 25 Nov 2019 14:03:19 +0800 Subject: [PATCH] Add easier shortcuts --- .../commonMain/kotlin/net.mamoe.mirai/BotHelper.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt index 98ef59a7f..127e89d75 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt @@ -84,6 +84,18 @@ suspend inline fun Bot.login(): LoginResult = this.network.login(BotConfiguratio */ suspend inline fun Bot.alsoLogin(): Bot = apply { login().requireSuccess() } +/** + * 使用在默认配置基础上修改的配置进行登录, 返回 [this] + */ +@UseExperimental(ExperimentalContracts::class) +suspend inline fun Bot.alsoLogin(noinline configuration: BotConfiguration.() -> Unit): Bot { + contract { + callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) + } + this.network.login(BotConfiguration().apply(configuration)).requireSuccess() + return this +} + /** * 使用默认的配置 ([BotConfiguration.Default]) 登录, 返回 [this] */