mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-03 05:33:53 +08:00
Review MessageReceipt:
- Remove constructor parameter botAsMember - Add extensions
This commit is contained in:
parent
e7632f05d6
commit
51c9bf5d2b
@ -12,6 +12,7 @@
|
||||
package net.mamoe.mirai.message
|
||||
|
||||
import net.mamoe.kjbb.JvmBlockingBridge
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.IMirai
|
||||
import net.mamoe.mirai.Mirai
|
||||
import net.mamoe.mirai.contact.*
|
||||
@ -19,7 +20,7 @@ import net.mamoe.mirai.message.MessageReceipt.Companion.quote
|
||||
import net.mamoe.mirai.message.MessageReceipt.Companion.quoteReply
|
||||
import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.message.data.MessageSource.Key.quote
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||
import net.mamoe.mirai.utils.MiraiInternalApi
|
||||
|
||||
/**
|
||||
* 发送消息后得到的回执. 可用于撤回, 引用回复等.
|
||||
@ -38,7 +39,7 @@ import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||
* @see MessageReceipt.sourceIds 源 ids
|
||||
* @see MessageReceipt.sourceTime 源时间
|
||||
*/
|
||||
public open class MessageReceipt<out C : Contact> @MiraiExperimentalApi("The constructor is subject to change.") constructor(
|
||||
public open class MessageReceipt<out C : Contact> @MiraiInternalApi constructor(
|
||||
/**
|
||||
* 指代发送出去的消息.
|
||||
*/
|
||||
@ -47,12 +48,6 @@ public open class MessageReceipt<out C : Contact> @MiraiExperimentalApi("The con
|
||||
* 发送目标, 为 [Group] 或 [Friend] 或 [Member]
|
||||
*/
|
||||
public val target: C,
|
||||
|
||||
/**
|
||||
* @see Group.botAsMember
|
||||
*/
|
||||
@MiraiExperimentalApi("This is subject to change.")
|
||||
public val botAsMember: Member?
|
||||
) {
|
||||
/**
|
||||
* 是否为发送给群的消息的回执
|
||||
@ -98,26 +93,32 @@ public open class MessageReceipt<out C : Contact> @MiraiExperimentalApi("The con
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关 [Bot]
|
||||
*/
|
||||
public inline val MessageReceipt<*>.bot: Bot
|
||||
get() = target.bot
|
||||
|
||||
/**
|
||||
* 获取源消息 [MessageSource.ids]
|
||||
*
|
||||
* @see MessageSource.ids
|
||||
*/
|
||||
public inline val MessageReceipt<*>.sourceIds: IntArray
|
||||
get() = this.source.ids
|
||||
|
||||
/**
|
||||
* 获取源消息 [MessageSource.internalIds]
|
||||
*
|
||||
* @see MessageSource.ids
|
||||
*/
|
||||
public inline val MessageReceipt<*>.sourceInternalIds: IntArray
|
||||
get() = this.source.internalIds
|
||||
|
||||
/**
|
||||
* 获取源消息 [MessageSource.time]
|
||||
*
|
||||
* @see MessageSource.time
|
||||
*/
|
||||
public inline val MessageReceipt<*>.sourceTime: Int
|
||||
get() = this.source.time
|
||||
|
||||
/**
|
||||
* 获取源消息 [MessageSource.originalMessage]
|
||||
*/
|
||||
public inline val MessageReceipt<*>.sourceMessage: MessageChain
|
||||
get() = this.source.originalMessage
|
||||
|
@ -98,8 +98,8 @@ internal class FriendImpl(
|
||||
require(message.isContentNotEmpty()) { "message is empty" }
|
||||
return sendMessageImpl(
|
||||
message,
|
||||
friendReceiptConstructor = { MessageReceipt(it, this, null) },
|
||||
tReceiptConstructor = { MessageReceipt(it, this, null) }
|
||||
friendReceiptConstructor = { MessageReceipt(it, this) },
|
||||
tReceiptConstructor = { MessageReceipt(it, this) }
|
||||
).also {
|
||||
logMessageSent(message)
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ internal class GroupImpl(
|
||||
bot.network.logger.warning(e)
|
||||
}
|
||||
|
||||
MessageReceipt(source, this@GroupImpl, botAsMember)
|
||||
MessageReceipt(source, this@GroupImpl)
|
||||
}
|
||||
|
||||
result.fold(
|
||||
|
@ -69,8 +69,8 @@ internal class MemberImpl constructor(
|
||||
|
||||
return (asFriend?.sendMessageImpl(
|
||||
message,
|
||||
friendReceiptConstructor = { MessageReceipt(it, asFriend, null) },
|
||||
tReceiptConstructor = { MessageReceipt(it, this, null) }
|
||||
friendReceiptConstructor = { MessageReceipt(it, asFriend) },
|
||||
tReceiptConstructor = { MessageReceipt(it, this) }
|
||||
) ?: sendMessageImpl(message)).also { logMessageSent(message) }
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ internal class MemberImpl constructor(
|
||||
"Send temp message failed: $it"
|
||||
}
|
||||
}
|
||||
MessageReceipt(source, this@MemberImpl, null)
|
||||
MessageReceipt(source, this@MemberImpl)
|
||||
}
|
||||
|
||||
result.fold(
|
||||
|
Loading…
Reference in New Issue
Block a user