Commit 3c25c3df authored by Him188's avatar Him188

Simplify calls

parent 9047fd0d
...@@ -152,6 +152,7 @@ internal abstract class QQAndroidBotBase constructor( ...@@ -152,6 +152,7 @@ internal abstract class QQAndroidBotBase constructor(
getGroup(source.groupId).checkBotPermissionOperator() getGroup(source.groupId).checkBotPermissionOperator()
} }
println(source._miraiContentToString())
source.ensureSequenceIdAvailable() source.ensureSequenceIdAvailable()
network.run { network.run {
......
...@@ -38,7 +38,7 @@ internal class MessageSourceFromServer( ...@@ -38,7 +38,7 @@ internal class MessageSourceFromServer(
override val id: Long override val id: Long
get() = (delegate.origSeqs?.firstOrNull() get() = (delegate.origSeqs?.firstOrNull()
?: error("cannot find sequenceId from ImMsgBody.SourceMsg")).toLong().shl(32) or ?: error("cannot find sequenceId from ImMsgBody.SourceMsg")).toLong().shl(32) or
(delegate.pbReserve.loadAs(SourceMsg.ResvAttr.serializer()).origUids!!.toInt()).toLong().and(0xFFFFFFFF) delegate.pbReserve.loadAs(SourceMsg.ResvAttr.serializer()).origUids!!.and(0xFFFFFFFF)
override val toUin: Long get() = delegate.toUin override val toUin: Long get() = delegate.toUin
......
...@@ -9,17 +9,12 @@ ...@@ -9,17 +9,12 @@
package net.mamoe.mirai.message package net.mamoe.mirai.message
import kotlinx.coroutines.Job
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.Member import net.mamoe.mirai.contact.Member
import net.mamoe.mirai.contact.MemberPermission import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.event.Event import net.mamoe.mirai.event.Event
import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.message.data.MessageSource
import net.mamoe.mirai.recall
import net.mamoe.mirai.recallIn
import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.getValue import net.mamoe.mirai.utils.getValue
import net.mamoe.mirai.utils.unsafeWeakRef import net.mamoe.mirai.utils.unsafeWeakRef
...@@ -41,14 +36,6 @@ class GroupMessage( ...@@ -41,14 +36,6 @@ class GroupMessage(
inline fun Long.member(): Member = group[this] inline fun Long.member(): Member = group[this]
@MiraiExperimentalAPI
suspend inline fun MessageChain.recall() = bot.recall(this)
suspend inline fun MessageSource.recall() = bot.recall(this)
inline fun MessageSource.recallIn(delay: Long): Job = bot.recallIn(this, delay)
@MiraiExperimentalAPI
inline fun MessageChain.recallIn(delay: Long): Job = bot.recallIn(this, delay)
override fun toString(): String = override fun toString(): String =
"GroupMessage(group=${group.id}, senderName=$senderName, sender=${sender.id}, permission=${permission.name}, message=$message)" "GroupMessage(group=${group.id}, senderName=$senderName, sender=${sender.id}, permission=${permission.name}, message=$message)"
} }
\ No newline at end of file
...@@ -22,7 +22,11 @@ import net.mamoe.mirai.event.events.BotEvent ...@@ -22,7 +22,11 @@ import net.mamoe.mirai.event.events.BotEvent
import net.mamoe.mirai.event.subscribingGet import net.mamoe.mirai.event.subscribingGet
import net.mamoe.mirai.event.subscribingGetOrNull import net.mamoe.mirai.event.subscribingGetOrNull
import net.mamoe.mirai.message.data.* import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.recall
import net.mamoe.mirai.recallIn
import net.mamoe.mirai.utils.* import net.mamoe.mirai.utils.*
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.jvm.JvmName import kotlin.jvm.JvmName
/** /**
...@@ -95,6 +99,26 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot ...@@ -95,6 +99,26 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot
suspend inline fun MessageChain.reply(): MessageReceipt<TSubject> = reply(this) suspend inline fun MessageChain.reply(): MessageReceipt<TSubject> = reply(this)
// endregion // endregion
// region 撤回
suspend inline fun MessageChain.recall() = bot.recall(this)
suspend inline fun MessageSource.recall() = bot.recall(this)
suspend inline fun QuoteReply.recall() = bot.recall(this.source)
inline fun MessageChain.recallIn(
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
) = bot.recallIn(this, millis, coroutineContext)
inline fun MessageSource.recallIn(
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
) = bot.recallIn(this, millis, coroutineContext)
inline fun QuoteReply.recallIn(
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
) = bot.recallIn(this.source, millis, coroutineContext)
// endregion
// region 上传图片 // region 上传图片
suspend inline fun ExternalImage.upload(): Image = this.upload(subject) suspend inline fun ExternalImage.upload(): Image = this.upload(subject)
// endregion // endregion
...@@ -113,7 +137,8 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot ...@@ -113,7 +137,8 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot
* 对于好友消息事件, 这个方法将会给好友 ([subject]) 发送消息 * 对于好友消息事件, 这个方法将会给好友 ([subject]) 发送消息
* 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息 * 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息
*/ */
suspend inline fun quoteReply(message: MessageChain): MessageReceipt<TSubject> = reply(this.message.quote() + message) suspend inline fun quoteReply(message: MessageChain): MessageReceipt<TSubject> =
reply(this.message.quote() + message)
suspend inline fun quoteReply(message: Message): MessageReceipt<TSubject> = reply(this.message.quote() + message) suspend inline fun quoteReply(message: Message): MessageReceipt<TSubject> = reply(this.message.quote() + message)
suspend inline fun quoteReply(plain: String): MessageReceipt<TSubject> = reply(this.message.quote() + plain) suspend inline fun quoteReply(plain: String): MessageReceipt<TSubject> = reply(this.message.quote() + plain)
...@@ -141,7 +166,8 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot ...@@ -141,7 +166,8 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot
*/ */
fun QQ.at(): At = At(this as? Member ?: error("`QQ.at` can only be used in GroupMessage")) fun QQ.at(): At = At(this as? Member ?: error("`QQ.at` can only be used in GroupMessage"))
fun At.member(): Member = (this@MessagePacketBase as? GroupMessage)?.group?.get(this.target) ?: error("`At.member` can only be used in GroupMessage") fun At.member(): Member = (this@MessagePacketBase as? GroupMessage)?.group?.get(this.target)
?: error("`At.member` can only be used in GroupMessage")
// endregion // endregion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment