From 93068d256dd521dcdcb91cd4dcefa79fa7707591 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 23 Nov 2019 22:58:21 +0800 Subject: [PATCH] Add alsoLogin() --- .../commonMain/kotlin/net.mamoe.mirai/BotHelper.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 21e7b549c..55f805da3 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt @@ -73,12 +73,17 @@ suspend inline fun Bot.login(noinline configuration: BotConfiguration.() -> Unit } /** - * 使用默认的配置 ([BotConfiguration.Default]) 登录 + * 使用默认的配置 ([BotConfiguration.Default]) 登录, 返回登录结果 */ suspend inline fun Bot.login(): LoginResult = this.network.login(BotConfiguration.Default) /** - * 使用默认的配置 ([BotConfiguration.Default]) 登录 + * 使用默认的配置 ([BotConfiguration.Default]) 登录, 返回 [this] + */ +suspend inline fun Bot.alsoLogin(): Bot = apply { login().requireSuccess() } + +/** + * 使用默认的配置 ([BotConfiguration.Default]) 登录, 返回 [this] */ @UseExperimental(ExperimentalContracts::class) suspend inline fun Bot.alsoLogin(lazyMessageWhenLoginFailed: (LoginResult) -> String): Bot { @@ -95,7 +100,7 @@ suspend inline fun Bot.alsoLogin(lazyMessageWhenLoginFailed: (LoginResult) -> St */ @UseExperimental(ExperimentalContracts::class) @JvmOverloads -suspend inline fun Bot.addFriend(id: UInt, noinline lazyMessage: () -> String = { "" }, noinline lazyRemark: () -> String = { "" }): AddFriendResult { +suspend inline fun Bot.addFriend(id: UInt, lazyMessage: () -> String = { "" }, noinline lazyRemark: () -> String = { "" }): AddFriendResult { contract { callsInPlace(lazyMessage, InvocationKind.AT_MOST_ONCE) }