mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-05 05:59:18 +08:00
Rename MessageSource.senderId
to MessageSource.qqId
This commit is contained in:
parent
0cbc0f0e29
commit
067a949630
@ -122,38 +122,54 @@ internal abstract class QQAndroidBotBase constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun recall(source: MessageSource) {
|
override suspend fun recall(source: MessageSource) {
|
||||||
if (source.senderId != uin) {
|
if (source.qqId != uin && source.groupId != 0L) {
|
||||||
getGroup(source.groupId).checkBotPermissionOperator()
|
getGroup(source.groupId).checkBotPermissionOperator()
|
||||||
}
|
}
|
||||||
|
|
||||||
source.ensureSequenceIdAvailable()
|
source.ensureSequenceIdAvailable()
|
||||||
|
|
||||||
network.run {
|
network.run {
|
||||||
val response: PbMessageSvc.PbMsgWithDraw.Response = if (source.groupId == 0L) {
|
val response: PbMessageSvc.PbMsgWithDraw.Response =
|
||||||
PbMessageSvc.PbMsgWithDraw.Friend(bot.client, source.senderId, source.sequenceId, source.messageRandom, source.time)
|
if (source.groupId == 0L) {
|
||||||
.sendAndExpect()
|
PbMessageSvc.PbMsgWithDraw.Friend(
|
||||||
} else {
|
bot.client,
|
||||||
|
source.qqId,
|
||||||
|
source.sequenceId,
|
||||||
|
source.messageRandom,
|
||||||
|
source.time
|
||||||
|
)
|
||||||
|
.sendAndExpect()
|
||||||
|
} else {
|
||||||
|
PbMessageSvc.PbMsgWithDraw.Group(
|
||||||
|
bot.client,
|
||||||
|
source.groupId,
|
||||||
|
source.sequenceId,
|
||||||
|
source.messageRandom
|
||||||
|
)
|
||||||
|
.sendAndExpect()
|
||||||
|
}
|
||||||
|
|
||||||
PbMessageSvc.PbMsgWithDraw.Group(bot.client, source.groupId, source.sequenceId, source.messageRandom)
|
check(response is PbMessageSvc.PbMsgWithDraw.Response.Success) { "Failed to recall message #${source.id}: $response" }
|
||||||
.sendAndExpect()
|
|
||||||
}
|
|
||||||
|
|
||||||
check(response is PbMessageSvc.PbMsgWithDraw.Response.Success) { "Failed to recall message #${source.sequenceId}: $response" }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun recall(groupId: Long, senderId: Long, messageId: Long) {
|
override suspend fun _lowLevelRecallFriendMessage(friendId: Long, messageId: Long) {
|
||||||
if (senderId != uin) {
|
|
||||||
getGroup(groupId).checkBotPermissionOperator()
|
|
||||||
}
|
|
||||||
|
|
||||||
val sequenceId = (messageId shr 32).toInt()
|
|
||||||
|
|
||||||
network.run {
|
network.run {
|
||||||
val response: PbMessageSvc.PbMsgWithDraw.Response =
|
val response: PbMessageSvc.PbMsgWithDraw.Response =
|
||||||
PbMessageSvc.PbMsgWithDraw.Group(bot.client, groupId, sequenceId, messageId.toInt())
|
PbMessageSvc.PbMsgWithDraw.Friend(client, friendId, (messageId shr 32).toInt(), messageId.toInt(), 0)
|
||||||
.sendAndExpect()
|
.sendAndExpect()
|
||||||
check(response is PbMessageSvc.PbMsgWithDraw.Response.Success) { "Failed to recall message #$sequenceId: $response" }
|
|
||||||
|
check(response is PbMessageSvc.PbMsgWithDraw.Response.Success) { "Failed to recall message #${messageId}: $response" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun _lowLevelRecallGroupMessage(groupId: Long, messageId: Long) {
|
||||||
|
network.run {
|
||||||
|
val response: PbMessageSvc.PbMsgWithDraw.Response =
|
||||||
|
PbMessageSvc.PbMsgWithDraw.Group(client, groupId, (messageId shr 32).toInt(), messageId.toInt())
|
||||||
|
.sendAndExpect()
|
||||||
|
|
||||||
|
check(response is PbMessageSvc.PbMsgWithDraw.Response.Success) { "Failed to recall message #${messageId}: $response" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ internal inline class MessageSourceFromServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
|
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
|
||||||
override val senderId: Long get() = delegate.senderUin
|
override val qqId: Long get() = delegate.senderUin
|
||||||
override val groupId: Long get() = Group.calculateGroupCodeByGroupUin(delegate.toUin)
|
override val groupId: Long get() = Group.calculateGroupCodeByGroupUin(delegate.toUin)
|
||||||
|
|
||||||
override fun toString(): String = ""
|
override fun toString(): String = ""
|
||||||
@ -52,7 +52,7 @@ internal inline class MessageSourceFromMsg(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
|
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
|
||||||
override val senderId: Long get() = delegate.msgHead.fromUin
|
override val qqId: Long get() = delegate.msgHead.fromUin
|
||||||
override val groupId: Long get() = delegate.msgHead.groupInfo?.groupCode ?: 0
|
override val groupId: Long get() = delegate.msgHead.groupInfo?.groupCode ?: 0
|
||||||
|
|
||||||
fun toJceData(): ImMsgBody.SourceMsg {
|
fun toJceData(): ImMsgBody.SourceMsg {
|
||||||
|
@ -76,8 +76,7 @@ internal class PbMessageSvc {
|
|||||||
toUin: Long,
|
toUin: Long,
|
||||||
messageSequenceId: Int, // 56639
|
messageSequenceId: Int, // 56639
|
||||||
messageRandom: Int, // 921878719
|
messageRandom: Int, // 921878719
|
||||||
time: Long,
|
time: Long
|
||||||
messageType: Int = 0
|
|
||||||
): OutgoingPacket = buildOutgoingUniPacket(client) {
|
): OutgoingPacket = buildOutgoingUniPacket(client) {
|
||||||
writeProtoBuf(
|
writeProtoBuf(
|
||||||
MsgSvc.PbMsgWithDrawReq.serializer(),
|
MsgSvc.PbMsgWithDrawReq.serializer(),
|
||||||
|
@ -272,7 +272,7 @@ internal class MessageSvc {
|
|||||||
internal class MessageSourceFromSendFriend(
|
internal class MessageSourceFromSendFriend(
|
||||||
val messageRandom: Int,
|
val messageRandom: Int,
|
||||||
override val time: Long,
|
override val time: Long,
|
||||||
override val senderId: Long,
|
override val qqId: Long,
|
||||||
override val groupId: Long,
|
override val groupId: Long,
|
||||||
val sequenceId: Int
|
val sequenceId: Int
|
||||||
) : MessageSource {
|
) : MessageSource {
|
||||||
@ -293,7 +293,7 @@ internal class MessageSvc {
|
|||||||
internal class MessageSourceFromSendGroup(
|
internal class MessageSourceFromSendGroup(
|
||||||
val messageRandom: Int,
|
val messageRandom: Int,
|
||||||
override val time: Long,
|
override val time: Long,
|
||||||
override val senderId: Long,
|
override val qqId: Long,
|
||||||
override val groupId: Long// ,
|
override val groupId: Long// ,
|
||||||
// override val sourceMessage: MessageChain
|
// override val sourceMessage: MessageChain
|
||||||
) : MessageSource {
|
) : MessageSource {
|
||||||
@ -330,7 +330,7 @@ internal class MessageSvc {
|
|||||||
): OutgoingPacket {
|
): OutgoingPacket {
|
||||||
val source = MessageSourceFromSendFriend(
|
val source = MessageSourceFromSendFriend(
|
||||||
messageRandom = Random.nextInt().absoluteValue,
|
messageRandom = Random.nextInt().absoluteValue,
|
||||||
senderId = client.uin,
|
qqId = toUin,
|
||||||
time = currentTimeSeconds + client.timeDifference,
|
time = currentTimeSeconds + client.timeDifference,
|
||||||
groupId = 0,
|
groupId = 0,
|
||||||
sequenceId = client.atomicNextMessageSequenceId()
|
sequenceId = client.atomicNextMessageSequenceId()
|
||||||
@ -379,7 +379,7 @@ internal class MessageSvc {
|
|||||||
|
|
||||||
val source = MessageSourceFromSendGroup(
|
val source = MessageSourceFromSendGroup(
|
||||||
messageRandom = Random.nextInt().absoluteValue,
|
messageRandom = Random.nextInt().absoluteValue,
|
||||||
senderId = client.uin,
|
qqId = client.uin,
|
||||||
time = currentTimeSeconds + client.timeDifference,
|
time = currentTimeSeconds + client.timeDifference,
|
||||||
groupId = groupCode//,
|
groupId = groupCode//,
|
||||||
// sourceMessage = message
|
// sourceMessage = message
|
||||||
|
@ -21,6 +21,7 @@ import net.mamoe.mirai.data.AddFriendResult
|
|||||||
import net.mamoe.mirai.data.FriendInfo
|
import net.mamoe.mirai.data.FriendInfo
|
||||||
import net.mamoe.mirai.data.GroupInfo
|
import net.mamoe.mirai.data.GroupInfo
|
||||||
import net.mamoe.mirai.data.MemberInfo
|
import net.mamoe.mirai.data.MemberInfo
|
||||||
|
import net.mamoe.mirai.message.MessageReceipt
|
||||||
import net.mamoe.mirai.message.data.Image
|
import net.mamoe.mirai.message.data.Image
|
||||||
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.message.data.MessageSource
|
||||||
@ -205,30 +206,29 @@ abstract class Bot : CoroutineScope {
|
|||||||
// region actions
|
// region actions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 撤回这条消息.
|
* 撤回这条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.
|
||||||
*
|
*
|
||||||
* [Bot] 撤回自己的消息不需要权限.
|
* [Bot] 撤回自己的消息不需要权限.
|
||||||
* [Bot] 撤回群员的消息需要管理员权限.
|
* [Bot] 撤回群员的消息需要管理员权限.
|
||||||
*
|
*
|
||||||
|
* @param source 消息源. 可从 [MessageReceipt.source] 获得, 或从消息事件中的 [MessageChain] 获得.
|
||||||
|
*
|
||||||
* @throws PermissionDeniedException 当 [Bot] 无权限操作时
|
* @throws PermissionDeniedException 当 [Bot] 无权限操作时
|
||||||
* @see Bot.recall (扩展函数) 接受参数 [MessageChain]
|
* @see Bot.recall (扩展函数) 接受参数 [MessageChain]
|
||||||
*/// source.groupId, source.sequenceId, source.messageUid
|
*/
|
||||||
abstract suspend fun recall(source: MessageSource)
|
abstract suspend fun recall(source: MessageSource)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 撤回一条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.
|
* 撤回一条由机器人发送给好友的消息
|
||||||
*
|
|
||||||
* [Bot] 撤回自己的消息不需要权限.
|
|
||||||
* [Bot] 撤回群员的消息需要管理员权限.
|
|
||||||
*
|
|
||||||
* @param senderId 这条消息的发送人. 可以为 [Bot.uin] 或 [Member.id]
|
|
||||||
* @param messageId 即 [MessageSource.id]
|
|
||||||
*
|
|
||||||
* @throws PermissionDeniedException 当 [Bot] 无权限操作时
|
|
||||||
* @see Bot.recall (扩展函数) 接受参数 [MessageChain]
|
|
||||||
* @see recall 请优先使用这个函数
|
|
||||||
*/
|
*/
|
||||||
abstract suspend fun recall(groupId: Long, senderId: Long, messageId: Long)
|
@MiraiExperimentalAPI
|
||||||
|
abstract suspend fun _lowLevelRecallFriendMessage(friendId: Long, messageId: Long)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 撤回一条群里的消息. 可以是机器人发送也可以是其他群员发送.
|
||||||
|
*/
|
||||||
|
@MiraiExperimentalAPI
|
||||||
|
abstract suspend fun _lowLevelRecallGroupMessage(groupId: Long, messageId: Long)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取图片下载链接
|
* 获取图片下载链接
|
||||||
|
@ -72,7 +72,7 @@ open class MessageReceipt<C : Contact>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 撤回这条消息. [recall] 或 [recallIn] 只能被调用一次.
|
* 在一段时间后撤回这条消息.. [recall] 或 [recallIn] 只能被调用一次.
|
||||||
*
|
*
|
||||||
* @param millis 延迟时间, 单位为毫秒
|
* @param millis 延迟时间, 单位为毫秒
|
||||||
*
|
*
|
||||||
@ -91,7 +91,7 @@ open class MessageReceipt<C : Contact>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 引用这条消息. 仅群消息能被引用
|
* 引用这条消息.
|
||||||
*
|
*
|
||||||
* @see MessageChain.quote 引用一条消息
|
* @see MessageChain.quote 引用一条消息
|
||||||
*
|
*
|
||||||
@ -105,7 +105,7 @@ open class MessageReceipt<C : Contact>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 引用这条消息并回复. 仅群消息能被引用
|
* 引用这条消息并回复.
|
||||||
*
|
*
|
||||||
* @see MessageChain.quote 引用一条消息
|
* @see MessageChain.quote 引用一条消息
|
||||||
*
|
*
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
package net.mamoe.mirai.message.data
|
package net.mamoe.mirai.message.data
|
||||||
|
|
||||||
import net.mamoe.mirai.Bot
|
import net.mamoe.mirai.Bot
|
||||||
|
import net.mamoe.mirai.contact.QQ
|
||||||
import kotlin.jvm.JvmMultifileClass
|
import kotlin.jvm.JvmMultifileClass
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
|
|
||||||
@ -49,8 +50,14 @@ interface MessageSource : Message, MessageMetadata {
|
|||||||
val time: Long
|
val time: Long
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送人号码
|
* 与这个消息相关的 [QQ] 的 [QQ.id]
|
||||||
|
*
|
||||||
|
* 群消息时为发送人的 id. 好友消息时为消息发送目标好友的 id
|
||||||
*/
|
*/
|
||||||
|
val qqId: Long
|
||||||
|
|
||||||
|
@Suppress("unused") // TODO: 2020/2/29 0.25: 删除 `MessageSource.senderId`
|
||||||
|
@Deprecated("使用 qqId. 此 API 将在 0.25 删除", level = DeprecationLevel.HIDDEN, replaceWith = ReplaceWith("this.qqId"))
|
||||||
val senderId: Long
|
val senderId: Long
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user