Review MessageReceipt:

- Remove constructor parameter botAsMember
- Add extensions
This commit is contained in:
Him188 2020-12-16 19:31:05 +08:00
parent e7632f05d6
commit 51c9bf5d2b
4 changed files with 21 additions and 20 deletions

View File

@ -12,6 +12,7 @@
package net.mamoe.mirai.message package net.mamoe.mirai.message
import net.mamoe.kjbb.JvmBlockingBridge import net.mamoe.kjbb.JvmBlockingBridge
import net.mamoe.mirai.Bot
import net.mamoe.mirai.IMirai import net.mamoe.mirai.IMirai
import net.mamoe.mirai.Mirai import net.mamoe.mirai.Mirai
import net.mamoe.mirai.contact.* 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.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.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.MiraiInternalApi
/** /**
* 发送消息后得到的回执. 可用于撤回, 引用回复等. * 发送消息后得到的回执. 可用于撤回, 引用回复等.
@ -38,7 +39,7 @@ import net.mamoe.mirai.utils.MiraiExperimentalApi
* @see MessageReceipt.sourceIds ids * @see MessageReceipt.sourceIds ids
* @see MessageReceipt.sourceTime 源时间 * @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] * 发送目标, [Group] [Friend] [Member]
*/ */
public val target: C, 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] * 获取源消息 [MessageSource.ids]
*
* @see MessageSource.ids
*/ */
public inline val MessageReceipt<*>.sourceIds: IntArray public inline val MessageReceipt<*>.sourceIds: IntArray
get() = this.source.ids get() = this.source.ids
/** /**
* 获取源消息 [MessageSource.internalIds] * 获取源消息 [MessageSource.internalIds]
*
* @see MessageSource.ids
*/ */
public inline val MessageReceipt<*>.sourceInternalIds: IntArray public inline val MessageReceipt<*>.sourceInternalIds: IntArray
get() = this.source.internalIds get() = this.source.internalIds
/** /**
* 获取源消息 [MessageSource.time] * 获取源消息 [MessageSource.time]
*
* @see MessageSource.time
*/ */
public inline val MessageReceipt<*>.sourceTime: Int public inline val MessageReceipt<*>.sourceTime: Int
get() = this.source.time get() = this.source.time
/**
* 获取源消息 [MessageSource.originalMessage]
*/
public inline val MessageReceipt<*>.sourceMessage: MessageChain
get() = this.source.originalMessage

View File

@ -98,8 +98,8 @@ internal class FriendImpl(
require(message.isContentNotEmpty()) { "message is empty" } require(message.isContentNotEmpty()) { "message is empty" }
return sendMessageImpl( return sendMessageImpl(
message, message,
friendReceiptConstructor = { MessageReceipt(it, this, null) }, friendReceiptConstructor = { MessageReceipt(it, this) },
tReceiptConstructor = { MessageReceipt(it, this, null) } tReceiptConstructor = { MessageReceipt(it, this) }
).also { ).also {
logMessageSent(message) logMessageSent(message)
} }

View File

@ -356,7 +356,7 @@ internal class GroupImpl(
bot.network.logger.warning(e) bot.network.logger.warning(e)
} }
MessageReceipt(source, this@GroupImpl, botAsMember) MessageReceipt(source, this@GroupImpl)
} }
result.fold( result.fold(

View File

@ -69,8 +69,8 @@ internal class MemberImpl constructor(
return (asFriend?.sendMessageImpl( return (asFriend?.sendMessageImpl(
message, message,
friendReceiptConstructor = { MessageReceipt(it, asFriend, null) }, friendReceiptConstructor = { MessageReceipt(it, asFriend) },
tReceiptConstructor = { MessageReceipt(it, this, null) } tReceiptConstructor = { MessageReceipt(it, this) }
) ?: sendMessageImpl(message)).also { logMessageSent(message) } ) ?: sendMessageImpl(message)).also { logMessageSent(message) }
} }
@ -100,7 +100,7 @@ internal class MemberImpl constructor(
"Send temp message failed: $it" "Send temp message failed: $it"
} }
} }
MessageReceipt(source, this@MemberImpl, null) MessageReceipt(source, this@MemberImpl)
} }
result.fold( result.fold(