Simplify calls

This commit is contained in:
Him188 2020-03-03 10:26:50 +08:00
parent 9047fd0d4c
commit 3c25c3df65
4 changed files with 30 additions and 16 deletions

View File

@ -152,6 +152,7 @@ internal abstract class QQAndroidBotBase constructor(
getGroup(source.groupId).checkBotPermissionOperator()
}
println(source._miraiContentToString())
source.ensureSequenceIdAvailable()
network.run {

View File

@ -38,7 +38,7 @@ internal class MessageSourceFromServer(
override val id: Long
get() = (delegate.origSeqs?.firstOrNull()
?: 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

View File

@ -9,17 +9,12 @@
package net.mamoe.mirai.message
import kotlinx.coroutines.Job
import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.Member
import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.event.Event
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.unsafeWeakRef
@ -41,14 +36,6 @@ class GroupMessage(
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 =
"GroupMessage(group=${group.id}, senderName=$senderName, sender=${sender.id}, permission=${permission.name}, message=$message)"
}

View File

@ -22,7 +22,11 @@ import net.mamoe.mirai.event.events.BotEvent
import net.mamoe.mirai.event.subscribingGet
import net.mamoe.mirai.event.subscribingGetOrNull
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.recall
import net.mamoe.mirai.recallIn
import net.mamoe.mirai.utils.*
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.jvm.JvmName
/**
@ -95,6 +99,26 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot
suspend inline fun MessageChain.reply(): MessageReceipt<TSubject> = reply(this)
// 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 上传图片
suspend inline fun ExternalImage.upload(): Image = this.upload(subject)
// endregion
@ -113,7 +137,8 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot
* 对于好友消息事件, 这个方法将会给好友 ([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(plain: String): MessageReceipt<TSubject> = reply(this.message.quote() + plain)
@ -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 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