mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-14 04:10:50 +08:00
Add recallIn
This commit is contained in:
parent
2a7e9fb617
commit
c4791b0a5f
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.message
|
package net.mamoe.mirai.message
|
||||||
|
|
||||||
|
import kotlinx.coroutines.Deferred
|
||||||
import net.mamoe.kjbb.JvmBlockingBridge
|
import net.mamoe.kjbb.JvmBlockingBridge
|
||||||
import net.mamoe.mirai.Bot
|
import net.mamoe.mirai.Bot
|
||||||
import net.mamoe.mirai.IMirai
|
import net.mamoe.mirai.IMirai
|
||||||
@ -20,6 +21,7 @@ import net.mamoe.mirai.message.MessageReceipt.Companion.quote
|
|||||||
import net.mamoe.mirai.message.MessageReceipt.Companion.quoteReply
|
import net.mamoe.mirai.message.MessageReceipt.Companion.quoteReply
|
||||||
import net.mamoe.mirai.message.data.*
|
import net.mamoe.mirai.message.data.*
|
||||||
import net.mamoe.mirai.message.data.MessageSource.Key.quote
|
import net.mamoe.mirai.message.data.MessageSource.Key.quote
|
||||||
|
import net.mamoe.mirai.message.data.MessageSource.Key.recallIn
|
||||||
import net.mamoe.mirai.utils.MiraiInternalApi
|
import net.mamoe.mirai.utils.MiraiInternalApi
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,26 +58,37 @@ public open class MessageReceipt<out C : Contact> @MiraiInternalApi constructor(
|
|||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
/**
|
/**
|
||||||
* 撤回这条消息. [recallMessage] 或 [recallIn] 只能被调用一次.
|
* 撤回这条消息.
|
||||||
*
|
*
|
||||||
* @see IMirai.recallMessage
|
* @see IMirai.recallMessage
|
||||||
* @throws IllegalStateException 当此消息已经被撤回或正计划撤回时
|
|
||||||
*/
|
*/
|
||||||
@JvmBlockingBridge
|
@JvmBlockingBridge
|
||||||
|
@JvmStatic
|
||||||
public suspend inline fun MessageReceipt<*>.recall() {
|
public suspend inline fun MessageReceipt<*>.recall() {
|
||||||
return Mirai.recallMessage(target.bot, source)
|
return Mirai.recallMessage(target.bot, source)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 引用这条消息.
|
* 在一段时间后撤回这条消息.
|
||||||
* @see MessageChain.quote 引用一条消息
|
*
|
||||||
|
* @see IMirai.recallMessage
|
||||||
*/
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
@Suppress("DeferredIsResult")
|
||||||
|
public fun MessageReceipt<*>.recallIn(millis: Long): Deferred<Unit> = this.source.recallIn(millis)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 引用这条消息.
|
||||||
|
* @see MessageSource.quote 引用一条消息
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
public inline fun MessageReceipt<*>.quote(): QuoteReply = this.source.quote()
|
public inline fun MessageReceipt<*>.quote(): QuoteReply = this.source.quote()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 引用这条消息并回复.
|
* 引用这条消息并回复.
|
||||||
* @see MessageChain.quote 引用一条消息
|
* @see MessageSource.quote 引用一条消息
|
||||||
*/
|
*/
|
||||||
|
@JvmStatic
|
||||||
@JvmBlockingBridge
|
@JvmBlockingBridge
|
||||||
public suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: Message): MessageReceipt<C> {
|
public suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: Message): MessageReceipt<C> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@ -84,9 +97,10 @@ public open class MessageReceipt<out C : Contact> @MiraiInternalApi constructor(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 引用这条消息并回复.
|
* 引用这条消息并回复.
|
||||||
* @see MessageChain.quote 引用一条消息
|
* @see MessageSource.quote 引用一条消息
|
||||||
*/
|
*/
|
||||||
@JvmBlockingBridge
|
@JvmBlockingBridge
|
||||||
|
@JvmStatic
|
||||||
public suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: String): MessageReceipt<C> {
|
public suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: String): MessageReceipt<C> {
|
||||||
return this.quoteReply(PlainText(message))
|
return this.quoteReply(PlainText(message))
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.message.data
|
package net.mamoe.mirai.message.data
|
||||||
|
|
||||||
|
import kotlinx.coroutines.Deferred
|
||||||
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import net.mamoe.kjbb.JvmBlockingBridge
|
import net.mamoe.kjbb.JvmBlockingBridge
|
||||||
import net.mamoe.mirai.Bot
|
import net.mamoe.mirai.Bot
|
||||||
@ -191,6 +194,29 @@ public sealed class MessageSource : Message, MessageMetadata, ConstrainSingle {
|
|||||||
@JvmBlockingBridge
|
@JvmBlockingBridge
|
||||||
public suspend inline fun MessageChain.recall(): Unit = this.source.recall()
|
public suspend inline fun MessageChain.recall(): Unit = this.source.recall()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在一段时间后撤回这条消息.
|
||||||
|
*
|
||||||
|
* @see IMirai.recallMessage
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
@Suppress("DeferredIsResult")
|
||||||
|
public fun MessageChain.recallIn(millis: Long): Deferred<Unit> = this.source.recallIn(millis)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在一段时间后撤回这条消息.
|
||||||
|
*
|
||||||
|
* @see IMirai.recallMessage
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
@Suppress("DeferredIsResult")
|
||||||
|
public fun MessageSource.recallIn(millis: Long): Deferred<Unit> {
|
||||||
|
return bot.async {
|
||||||
|
delay(millis)
|
||||||
|
Mirai.recallMessage(bot, this@recallIn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否是发送给群, 或从群接收的消息的消息源
|
* 判断是否是发送给群, 或从群接收的消息的消息源
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user