From 14f4f4588d53eb23e6610e7e01c8ae7efba619e6 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 21 Feb 2020 20:29:48 +0800 Subject: [PATCH] Rename `delay` to `millis` --- .../kotlin/net.mamoe.mirai/contact/Group.kt | 12 +++---- .../net.mamoe.mirai/message/MessageReceipt.kt | 36 +++++++++++++++---- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt index 689611954..02c2d2c07 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt @@ -241,32 +241,32 @@ suspend inline fun Group.recall(message: MessageChain) = this.recall(message[Mes /** * 在一段时间后撤回这条消息. * - * @param delay 延迟的时间, 单位为毫秒 + * @param millis 延迟的时间, 单位为毫秒 * @param coroutineContext 额外的 [CoroutineContext] * @see recall */ fun Group.recallIn( message: MessageSource, - delay: Long, + millis: Long, coroutineContext: CoroutineContext = EmptyCoroutineContext ): Job = this.launch(coroutineContext + CoroutineName("MessageRecall")) { - kotlinx.coroutines.delay(delay) + kotlinx.coroutines.delay(millis) recall(message) } /** * 在一段时间后撤回这条消息. * - * @param delay 延迟的时间, 单位为毫秒 + * @param millis 延迟的时间, 单位为毫秒 * @param coroutineContext 额外的 [CoroutineContext] * @see recall */ fun Group.recallIn( message: MessageChain, - delay: Long, + millis: Long, coroutineContext: CoroutineContext = EmptyCoroutineContext ): Job = this.launch(coroutineContext + CoroutineName("MessageRecall")) { - kotlinx.coroutines.delay(delay) + kotlinx.coroutines.delay(millis) recall(message) } diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt index 3db21c6b2..6204e77c6 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt @@ -13,8 +13,7 @@ import kotlinx.atomicfu.atomic import kotlinx.coroutines.Job import net.mamoe.mirai.Bot import net.mamoe.mirai.contact.* -import net.mamoe.mirai.message.data.MessageChain -import net.mamoe.mirai.message.data.quote +import net.mamoe.mirai.message.data.* import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.getValue import net.mamoe.mirai.utils.unsafeWeakRef @@ -67,17 +66,17 @@ open class MessageReceipt( /** * 撤回这条消息. [recall] 或 [recallIn] 只能被调用一次. * - * @param delay 延迟时间, 单位为毫秒 + * @param millis 延迟时间, 单位为毫秒 * * @throws IllegalStateException 当此消息已经被撤回或正计划撤回时 */ @UseExperimental(MiraiExperimentalAPI::class) - fun recallIn(delay: Long): Job { + fun recallIn(millis: Long): Job { @Suppress("BooleanLiteralArgument") if (_isRecalled.compareAndSet(false, true)) { when (val contact = target) { is Group -> { - return contact.recallIn(originalMessage, delay) + return contact.recallIn(originalMessage, millis) } is QQ -> { TODO() @@ -94,10 +93,33 @@ open class MessageReceipt( * * @throws IllegalStateException 当此消息不是群消息时 */ - @UseExperimental(MiraiExperimentalAPI::class) + @MiraiExperimentalAPI("unstable") open fun quote(): MessageChain { val target = target check(target is Group) { "quote is only available for GroupMessage" } return this.originalMessage.quote(target.botAsMember) } -} \ No newline at end of file + + /** + * 引用这条消息并回复. 仅群消息能被引用 + * + * @see MessageChain.quote 引用一条消息 + * + * @throws IllegalStateException 当此消息不是群消息时 + */ + @MiraiExperimentalAPI("unstable") + suspend fun quoteReply(message: MessageChain) { + target.sendMessage(this.quote() + message) + } +} + +@MiraiExperimentalAPI("unstable") +suspend inline fun MessageReceipt.quoteReply(message: Message) { + return this.quoteReply(message.toChain()) +} + +@MiraiExperimentalAPI("unstable") +suspend inline fun MessageReceipt.quoteReply(message: String) { + return this.quoteReply(message.toMessage().toChain()) +} +