mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 14:20:24 +08:00
Remove legacy sendAndExpect
to reduce code complexity to avoid compiler bugs, fix #2049
This commit is contained in:
parent
167a29e0d8
commit
c3f94a66d6
@ -52,7 +52,6 @@ import net.mamoe.mirai.internal.network.protocol.packet.chat.PbMessageSvc
|
|||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.PttStore
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.PttStore
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc
|
import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.summarycard.SummaryCard
|
import net.mamoe.mirai.internal.network.protocol.packet.summarycard.SummaryCard
|
||||||
import net.mamoe.mirai.internal.network.psKey
|
import net.mamoe.mirai.internal.network.psKey
|
||||||
import net.mamoe.mirai.internal.network.sKey
|
import net.mamoe.mirai.internal.network.sKey
|
||||||
@ -257,7 +256,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
override suspend fun getOnlineOtherClientsList(bot: Bot, mayIncludeSelf: Boolean): List<OtherClientInfo> {
|
override suspend fun getOnlineOtherClientsList(bot: Bot, mayIncludeSelf: Boolean): List<OtherClientInfo> {
|
||||||
bot.asQQAndroidBot()
|
bot.asQQAndroidBot()
|
||||||
val response = bot.network.run {
|
val response = bot.network.run {
|
||||||
StatSvc.GetDevLoginInfo(bot.client).sendAndExpect()
|
bot.network.sendAndExpect(StatSvc.GetDevLoginInfo(bot.client))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun SvcDevLoginInfo.toOtherClientInfo() = OtherClientInfo(
|
fun SvcDevLoginInfo.toOtherClientInfo() = OtherClientInfo(
|
||||||
@ -352,7 +351,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
override suspend fun getRawGroupList(bot: Bot): Sequence<Long> {
|
override suspend fun getRawGroupList(bot: Bot): Sequence<Long> {
|
||||||
bot.asQQAndroidBot()
|
bot.asQQAndroidBot()
|
||||||
return bot.network.run {
|
return bot.network.run {
|
||||||
FriendList.GetTroopListSimplify(bot.client).sendAndExpect(retry = 2)
|
bot.network.sendAndExpect(FriendList.GetTroopListSimplify(bot.client))
|
||||||
}.groups.asSequence().map { it.groupUin.shl(32) and it.groupCode }
|
}.groups.asSequence().map { it.groupUin.shl(32) and it.groupCode }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,44 +361,45 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
groupUin: Long,
|
groupUin: Long,
|
||||||
groupCode: Long,
|
groupCode: Long,
|
||||||
ownerId: Long
|
ownerId: Long
|
||||||
): Sequence<MemberInfo> =
|
): Sequence<MemberInfo> {
|
||||||
bot.asQQAndroidBot().network.run {
|
var nextUin = 0L
|
||||||
var nextUin = 0L
|
var sequence = sequenceOf<MemberInfoImpl>()
|
||||||
var sequence = sequenceOf<MemberInfoImpl>()
|
while (true) {
|
||||||
while (true) {
|
val data = bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
val data = FriendList.GetTroopMemberList(
|
FriendList.GetTroopMemberList(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
targetGroupUin = groupUin,
|
targetGroupUin = groupUin,
|
||||||
targetGroupCode = groupCode,
|
targetGroupCode = groupCode,
|
||||||
nextUin = nextUin
|
nextUin = nextUin
|
||||||
).sendAndExpect(retry = 3)
|
), 5000, 3
|
||||||
sequence += data.members.asSequence().map { troopMemberInfo ->
|
)
|
||||||
MemberInfoImpl(bot.client, troopMemberInfo, ownerId)
|
sequence += data.members.asSequence().map { troopMemberInfo ->
|
||||||
}
|
MemberInfoImpl(bot.client, troopMemberInfo, ownerId)
|
||||||
nextUin = data.nextUin
|
}
|
||||||
if (nextUin == 0L) {
|
nextUin = data.nextUin
|
||||||
break
|
if (nextUin == 0L) {
|
||||||
}
|
break
|
||||||
}
|
}
|
||||||
return sequence
|
|
||||||
}
|
}
|
||||||
|
return sequence
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun recallGroupMessageRaw(
|
override suspend fun recallGroupMessageRaw(
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
groupCode: Long,
|
groupCode: Long,
|
||||||
messageIds: IntArray,
|
messageIds: IntArray,
|
||||||
messageInternalIds: IntArray,
|
messageInternalIds: IntArray,
|
||||||
): Boolean = bot.asQQAndroidBot().run {
|
): Boolean {
|
||||||
val response = network.run {
|
val response = bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
PbMessageSvc.PbMsgWithDraw.createForGroupMessage(
|
PbMessageSvc.PbMsgWithDraw.createForGroupMessage(
|
||||||
client,
|
bot.client,
|
||||||
groupCode,
|
groupCode,
|
||||||
messageIds,
|
messageIds,
|
||||||
messageInternalIds
|
messageInternalIds
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
|
|
||||||
response is PbMessageSvc.PbMsgWithDraw.Response.Success
|
return response is PbMessageSvc.PbMsgWithDraw.Response.Success
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun recallFriendMessageRaw(
|
override suspend fun recallFriendMessageRaw(
|
||||||
@ -408,18 +408,18 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
messageIds: IntArray,
|
messageIds: IntArray,
|
||||||
messageInternalIds: IntArray,
|
messageInternalIds: IntArray,
|
||||||
time: Int,
|
time: Int,
|
||||||
): Boolean = bot.asQQAndroidBot().run {
|
): Boolean {
|
||||||
val response = network.run {
|
val response = bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
PbMessageSvc.PbMsgWithDraw.createForFriendMessage(
|
PbMessageSvc.PbMsgWithDraw.createForFriendMessage(
|
||||||
client,
|
bot.client,
|
||||||
targetId,
|
targetId,
|
||||||
messageIds,
|
messageIds,
|
||||||
messageInternalIds,
|
messageInternalIds,
|
||||||
time,
|
time,
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
|
|
||||||
response is PbMessageSvc.PbMsgWithDraw.Response.Success
|
return response is PbMessageSvc.PbMsgWithDraw.Response.Success
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun recallGroupTempMessageRaw(
|
override suspend fun recallGroupTempMessageRaw(
|
||||||
@ -429,19 +429,19 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
messageIds: IntArray,
|
messageIds: IntArray,
|
||||||
messageInternalIds: IntArray,
|
messageInternalIds: IntArray,
|
||||||
time: Int
|
time: Int
|
||||||
): Boolean = bot.asQQAndroidBot().run {
|
): Boolean {
|
||||||
val response = network.run {
|
val response = bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
PbMessageSvc.PbMsgWithDraw.createForGroupTempMessage(
|
PbMessageSvc.PbMsgWithDraw.createForGroupTempMessage(
|
||||||
client,
|
bot.client,
|
||||||
groupUin,
|
groupUin,
|
||||||
targetId,
|
targetId,
|
||||||
messageIds,
|
messageIds,
|
||||||
messageInternalIds,
|
messageInternalIds,
|
||||||
time,
|
time,
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
|
|
||||||
response is PbMessageSvc.PbMsgWithDraw.Response.Success
|
return response is PbMessageSvc.PbMsgWithDraw.Response.Success
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("RemoveExplicitTypeArguments") // false positive
|
@Suppress("RemoveExplicitTypeArguments") // false positive
|
||||||
@ -474,81 +474,92 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
network.run {
|
|
||||||
|
bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
PbMessageSvc.PbMsgWithDraw.createForGroupMessage(
|
PbMessageSvc.PbMsgWithDraw.createForGroupMessage(
|
||||||
bot.asQQAndroidBot().client,
|
bot.asQQAndroidBot().client,
|
||||||
group.id,
|
group.id,
|
||||||
source.sequenceIds,
|
source.sequenceIds,
|
||||||
source.internalIds
|
source.internalIds
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
is OnlineMessageSourceFromFriendImpl,
|
is OnlineMessageSourceFromFriendImpl,
|
||||||
is OnlineMessageSourceToFriendImpl,
|
is OnlineMessageSourceToFriendImpl,
|
||||||
is OnlineMessageSourceFromStrangerImpl,
|
is OnlineMessageSourceFromStrangerImpl,
|
||||||
is OnlineMessageSourceToStrangerImpl,
|
is OnlineMessageSourceToStrangerImpl,
|
||||||
-> network.run {
|
-> {
|
||||||
check(source.fromId == bot.id) {
|
check(source.fromId == bot.id) {
|
||||||
"can only recall a message sent by bot"
|
"can only recall a message sent by bot"
|
||||||
}
|
}
|
||||||
PbMessageSvc.PbMsgWithDraw.createForFriendMessage(
|
bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
bot.client,
|
PbMessageSvc.PbMsgWithDraw.createForFriendMessage(
|
||||||
source.targetId,
|
bot.client,
|
||||||
source.sequenceIds,
|
source.targetId,
|
||||||
source.internalIds,
|
source.sequenceIds,
|
||||||
source.time
|
source.internalIds,
|
||||||
).sendAndExpect<PbMessageSvc.PbMsgWithDraw.Response>()
|
source.time
|
||||||
|
), 5000, 2
|
||||||
|
)
|
||||||
}
|
}
|
||||||
is OnlineMessageSourceFromTempImpl,
|
is OnlineMessageSourceFromTempImpl,
|
||||||
is OnlineMessageSourceToTempImpl
|
is OnlineMessageSourceToTempImpl
|
||||||
-> network.run {
|
-> {
|
||||||
check(source.fromId == bot.id) {
|
check(source.fromId == bot.id) {
|
||||||
"can only recall a message sent by bot"
|
"can only recall a message sent by bot"
|
||||||
}
|
}
|
||||||
source as OnlineMessageSourceToTempImpl
|
source as OnlineMessageSourceToTempImpl
|
||||||
PbMessageSvc.PbMsgWithDraw.createForGroupTempMessage(
|
bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
bot.client,
|
PbMessageSvc.PbMsgWithDraw.createForGroupTempMessage(
|
||||||
(source.target.group as GroupImpl).uin,
|
bot.client,
|
||||||
source.targetId,
|
(source.target.group as GroupImpl).uin,
|
||||||
source.sequenceIds,
|
source.targetId,
|
||||||
source.internalIds,
|
source.sequenceIds,
|
||||||
source.time
|
source.internalIds,
|
||||||
).sendAndExpect<PbMessageSvc.PbMsgWithDraw.Response>()
|
source.time
|
||||||
|
), 5000, 2
|
||||||
|
)
|
||||||
}
|
}
|
||||||
is OfflineMessageSource -> network.run {
|
is OfflineMessageSource -> {
|
||||||
when (source.kind) {
|
when (source.kind) {
|
||||||
MessageSourceKind.FRIEND, MessageSourceKind.STRANGER -> {
|
MessageSourceKind.FRIEND, MessageSourceKind.STRANGER -> {
|
||||||
check(source.fromId == bot.id) {
|
check(source.fromId == bot.id) {
|
||||||
"can only recall a message sent by bot"
|
"can only recall a message sent by bot"
|
||||||
}
|
}
|
||||||
PbMessageSvc.PbMsgWithDraw.createForFriendMessage(
|
bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
bot.client,
|
PbMessageSvc.PbMsgWithDraw.createForFriendMessage(
|
||||||
source.targetId,
|
bot.client,
|
||||||
source.sequenceIds,
|
source.targetId,
|
||||||
source.internalIds,
|
source.sequenceIds,
|
||||||
source.time
|
source.internalIds,
|
||||||
).sendAndExpect<PbMessageSvc.PbMsgWithDraw.Response>()
|
source.time
|
||||||
|
), 5000, 2
|
||||||
|
)
|
||||||
}
|
}
|
||||||
MessageSourceKind.TEMP -> {
|
MessageSourceKind.TEMP -> {
|
||||||
check(source.fromId == bot.id) {
|
check(source.fromId == bot.id) {
|
||||||
"can only recall a message sent by bot"
|
"can only recall a message sent by bot"
|
||||||
}
|
}
|
||||||
PbMessageSvc.PbMsgWithDraw.createForGroupTempMessage(
|
bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
bot.client,
|
PbMessageSvc.PbMsgWithDraw.createForGroupTempMessage(
|
||||||
source.targetId, // groupUin
|
bot.client,
|
||||||
source.targetId, // memberUin
|
source.targetId, // groupUin
|
||||||
source.sequenceIds,
|
source.targetId, // memberUin
|
||||||
source.internalIds,
|
source.sequenceIds,
|
||||||
source.time
|
source.internalIds,
|
||||||
).sendAndExpect<PbMessageSvc.PbMsgWithDraw.Response>()
|
source.time
|
||||||
|
), 5000, 2
|
||||||
|
)
|
||||||
}
|
}
|
||||||
MessageSourceKind.GROUP -> {
|
MessageSourceKind.GROUP -> {
|
||||||
PbMessageSvc.PbMsgWithDraw.createForGroupMessage(
|
bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
bot.client,
|
PbMessageSvc.PbMsgWithDraw.createForGroupMessage(
|
||||||
source.targetId,
|
bot.client,
|
||||||
source.sequenceIds,
|
source.targetId,
|
||||||
source.internalIds
|
source.sequenceIds,
|
||||||
).sendAndExpect<PbMessageSvc.PbMsgWithDraw.Response>()
|
source.internalIds
|
||||||
|
), 5000, 2
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -648,20 +659,20 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
accept: Boolean,
|
accept: Boolean,
|
||||||
blackList: Boolean
|
blackList: Boolean
|
||||||
): Unit = bot.asQQAndroidBot().run {
|
): Unit = bot.asQQAndroidBot().run {
|
||||||
network.apply {
|
network.sendWithoutExpect(
|
||||||
NewContact.SystemMsgNewFriend.Action(
|
NewContact.SystemMsgNewFriend.Action(
|
||||||
bot.client,
|
bot.client,
|
||||||
eventId = eventId,
|
eventId = eventId,
|
||||||
fromId = fromId,
|
fromId = fromId,
|
||||||
accept = accept,
|
accept = accept,
|
||||||
blackList = blackList
|
blackList = blackList
|
||||||
).sendWithoutExpect()
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if (!accept) return@apply
|
if (!accept) return
|
||||||
|
|
||||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
bot.friends.delegate.add(newFriend(bot, FriendInfoImpl(fromId, fromNick, "")))
|
bot.friends.delegate.add(newFriend(bot, FriendInfoImpl(fromId, fromNick, "")))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun solveBotInvitedJoinGroupRequestEvent(
|
override suspend fun solveBotInvitedJoinGroupRequestEvent(
|
||||||
@ -670,8 +681,8 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
invitorId: Long,
|
invitorId: Long,
|
||||||
groupId: Long,
|
groupId: Long,
|
||||||
accept: Boolean
|
accept: Boolean
|
||||||
) = bot.asQQAndroidBot().run {
|
) {
|
||||||
network.run {
|
bot.asQQAndroidBot().network.sendWithoutExpect(
|
||||||
NewContact.SystemMsgNewGroup.Action(
|
NewContact.SystemMsgNewGroup.Action(
|
||||||
bot.client,
|
bot.client,
|
||||||
eventId = eventId,
|
eventId = eventId,
|
||||||
@ -679,8 +690,8 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
groupId = groupId,
|
groupId = groupId,
|
||||||
isInvited = true,
|
isInvited = true,
|
||||||
accept = accept
|
accept = accept
|
||||||
).sendWithoutExpect()
|
)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun solveMemberJoinRequestEvent(
|
override suspend fun solveMemberJoinRequestEvent(
|
||||||
@ -692,8 +703,8 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
accept: Boolean?,
|
accept: Boolean?,
|
||||||
blackList: Boolean,
|
blackList: Boolean,
|
||||||
message: String
|
message: String
|
||||||
) = bot.asQQAndroidBot().run {
|
) {
|
||||||
network.run {
|
bot.asQQAndroidBot().network.sendWithoutExpect(
|
||||||
NewContact.SystemMsgNewGroup.Action(
|
NewContact.SystemMsgNewGroup.Action(
|
||||||
bot.client,
|
bot.client,
|
||||||
eventId = eventId,
|
eventId = eventId,
|
||||||
@ -703,8 +714,8 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
accept = accept,
|
accept = accept,
|
||||||
blackList = blackList,
|
blackList = blackList,
|
||||||
message = message
|
message = message
|
||||||
).sendWithoutExpect()
|
)
|
||||||
}
|
)
|
||||||
// Add member in MsgOnlinePush.PbPushMsg
|
// Add member in MsgOnlinePush.PbPushMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -715,10 +726,12 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
groupId: Long,
|
groupId: Long,
|
||||||
dstUin: Long
|
dstUin: Long
|
||||||
): String {
|
): String {
|
||||||
bot.asQQAndroidBot().network.run {
|
val response = bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
val response = PttStore.GroupPttDown(bot.client, groupId, dstUin, md5).sendAndExpect()
|
PttStore.GroupPttDown(bot.client, groupId, dstUin, md5),
|
||||||
return "http://${response.strDomain}${response.downPara.decodeToString()}"
|
5000,
|
||||||
}
|
2
|
||||||
|
)
|
||||||
|
return "http://${response.strDomain}${response.downPara.decodeToString()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun muteAnonymousMember(
|
override suspend fun muteAnonymousMember(
|
||||||
@ -769,10 +782,11 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun queryProfile(bot: Bot, targetId: Long): UserProfile {
|
override suspend fun queryProfile(bot: Bot, targetId: Long): UserProfile {
|
||||||
bot.asQQAndroidBot().network.apply {
|
|
||||||
return SummaryCard.ReqSummaryCard(bot.client, targetId)
|
return bot.asQQAndroidBot().network.sendAndExpect(
|
||||||
.sendAndExpect()
|
SummaryCard.ReqSummaryCard(bot.client, targetId),
|
||||||
}
|
5000, 2
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun sendNudge(bot: Bot, nudge: Nudge, receiver: Contact): Boolean {
|
override suspend fun sendNudge(bot: Bot, nudge: Nudge, receiver: Contact): Boolean {
|
||||||
@ -784,17 +798,21 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
bot.network.run {
|
bot.network.run {
|
||||||
return if (receiver is Group) {
|
return if (receiver is Group) {
|
||||||
receiver.checkIsGroupImpl()
|
receiver.checkIsGroupImpl()
|
||||||
NudgePacket.troopInvoke(
|
bot.network.sendAndExpect(
|
||||||
client = bot.client,
|
NudgePacket.troopInvoke(
|
||||||
messageReceiverGroupCode = receiver.id,
|
client = bot.client,
|
||||||
nudgeTargetId = nudge.target.id,
|
messageReceiverGroupCode = receiver.id,
|
||||||
).sendAndExpect<NudgePacket.Response>().success
|
nudgeTargetId = nudge.target.id,
|
||||||
|
)
|
||||||
|
).success
|
||||||
} else {
|
} else {
|
||||||
NudgePacket.friendInvoke(
|
bot.network.sendAndExpect(
|
||||||
client = bot.client,
|
NudgePacket.friendInvoke(
|
||||||
messageReceiverUin = receiver.id,
|
client = bot.client,
|
||||||
nudgeTargetId = nudge.target.id,
|
messageReceiverUin = receiver.id,
|
||||||
).sendAndExpect<NudgePacket.Response>().success
|
nudgeTargetId = nudge.target.id,
|
||||||
|
)
|
||||||
|
).success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -876,7 +894,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
|||||||
resourceKind: ResourceKind,
|
resourceKind: ResourceKind,
|
||||||
): MsgTransmit.PbMultiMsgTransmit {
|
): MsgTransmit.PbMultiMsgTransmit {
|
||||||
bot.asQQAndroidBot()
|
bot.asQQAndroidBot()
|
||||||
when (val resp = MultiMsg.ApplyDown(bot.client, 2, resourceId, 1).sendAndExpect(bot)) {
|
when (val resp = bot.network.sendAndExpect(MultiMsg.ApplyDown(bot.client, 2, resourceId, 1))) {
|
||||||
is MultiMsg.ApplyDown.Response.RequireDownload -> {
|
is MultiMsg.ApplyDown.Response.RequireDownload -> {
|
||||||
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
|
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
|
||||||
val http = Mirai.Http
|
val http = Mirai.Http
|
||||||
|
@ -28,7 +28,6 @@ import net.mamoe.mirai.internal.network.highway.tryServersUpload
|
|||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0x352
|
import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0x352
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.ImgStore
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.ImgStore
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.LongConn
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.LongConn
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.internal.utils.AtomicIntSeq
|
import net.mamoe.mirai.internal.utils.AtomicIntSeq
|
||||||
import net.mamoe.mirai.internal.utils.C2CPkgMsgParsingCache
|
import net.mamoe.mirai.internal.utils.C2CPkgMsgParsingCache
|
||||||
import net.mamoe.mirai.internal.utils.structureToString
|
import net.mamoe.mirai.internal.utils.structureToString
|
||||||
@ -76,7 +75,7 @@ internal sealed class AbstractUser(
|
|||||||
throw EventCancelledException("cancelled by BeforeImageUploadEvent.ToGroup")
|
throw EventCancelledException("cancelled by BeforeImageUploadEvent.ToGroup")
|
||||||
}
|
}
|
||||||
val imageInfo = runBIO { resource.calculateImageInfo() }
|
val imageInfo = runBIO { resource.calculateImageInfo() }
|
||||||
val resp = bot.network.run {
|
val resp = bot.network.sendAndExpect(
|
||||||
LongConn.OffPicUp(
|
LongConn.OffPicUp(
|
||||||
bot.client,
|
bot.client,
|
||||||
Cmd0x352.TryUpImgReq(
|
Cmd0x352.TryUpImgReq(
|
||||||
@ -92,8 +91,8 @@ internal sealed class AbstractUser(
|
|||||||
imgOriginal = true,
|
imgOriginal = true,
|
||||||
buildVer = bot.client.buildVer,
|
buildVer = bot.client.buildVer,
|
||||||
),
|
),
|
||||||
).sendAndExpect<LongConn.OffPicUp.Response>()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
|
|
||||||
return when (resp) {
|
return when (resp) {
|
||||||
is LongConn.OffPicUp.Response.FileExists -> {
|
is LongConn.OffPicUp.Response.FileExists -> {
|
||||||
@ -141,16 +140,18 @@ internal sealed class AbstractUser(
|
|||||||
)
|
)
|
||||||
}.recoverCatchingSuppressed {
|
}.recoverCatchingSuppressed {
|
||||||
// try upload as group image
|
// try upload as group image
|
||||||
val response: ImgStore.GroupPicUp.Response = ImgStore.GroupPicUp(
|
val response: ImgStore.GroupPicUp.Response = bot.network.sendAndExpect(
|
||||||
bot.client,
|
ImgStore.GroupPicUp(
|
||||||
uin = bot.id,
|
bot.client,
|
||||||
groupCode = id,
|
uin = bot.id,
|
||||||
md5 = resource.md5,
|
groupCode = id,
|
||||||
size = resource.size,
|
md5 = resource.md5,
|
||||||
picWidth = imageInfo.width,
|
size = resource.size,
|
||||||
picHeight = imageInfo.height,
|
picWidth = imageInfo.width,
|
||||||
picType = getIdByImageType(imageInfo.imageType),
|
picHeight = imageInfo.height,
|
||||||
).sendAndExpect(bot)
|
picType = getIdByImageType(imageInfo.imageType),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
when (response) {
|
when (response) {
|
||||||
is ImgStore.GroupPicUp.Response.Failed -> {
|
is ImgStore.GroupPicUp.Response.Failed -> {
|
||||||
|
@ -30,7 +30,6 @@ import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody
|
|||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.PttStore
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.PttStore
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.audioCodec
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.audioCodec
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.loadAs
|
import net.mamoe.mirai.internal.utils.io.serialization.loadAs
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.toByteArray
|
import net.mamoe.mirai.internal.utils.io.serialization.toByteArray
|
||||||
import net.mamoe.mirai.message.MessageReceipt
|
import net.mamoe.mirai.message.MessageReceipt
|
||||||
@ -69,10 +68,8 @@ internal class FriendImpl(
|
|||||||
check(bot.friends[id] != null) {
|
check(bot.friends[id] != null) {
|
||||||
"Friend $id had already been deleted"
|
"Friend $id had already been deleted"
|
||||||
}
|
}
|
||||||
bot.network.run {
|
bot.network.sendAndExpect(FriendList.DelFriend.invoke(bot.client, this@FriendImpl), 5000, 2).let {
|
||||||
FriendList.DelFriend.invoke(bot.client, this@FriendImpl).sendAndExpect().also {
|
check(it.isSuccess) { "delete friend failed: ${it.resultCode}" }
|
||||||
check(it.isSuccess) { "delete friend failed: ${it.resultCode}" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +117,7 @@ internal class FriendImpl(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}.recoverCatchingSuppressed {
|
}.recoverCatchingSuppressed {
|
||||||
when (val resp = PttStore.GroupPttUp(bot.client, bot.id, id, res).sendAndExpect(bot)) {
|
when (val resp = bot.network.sendAndExpect(PttStore.GroupPttUp(bot.client, bot.id, id, res))) {
|
||||||
is PttStore.GroupPttUp.Response.RequireUpload -> {
|
is PttStore.GroupPttUp.Response.RequireUpload -> {
|
||||||
tryServersUpload(
|
tryServersUpload(
|
||||||
bot,
|
bot,
|
||||||
|
@ -28,7 +28,6 @@ import net.mamoe.mirai.internal.contact.file.RemoteFilesImpl
|
|||||||
import net.mamoe.mirai.internal.contact.info.MemberInfoImpl
|
import net.mamoe.mirai.internal.contact.info.MemberInfoImpl
|
||||||
import net.mamoe.mirai.internal.message.*
|
import net.mamoe.mirai.internal.message.*
|
||||||
import net.mamoe.mirai.internal.network.components.BdhSession
|
import net.mamoe.mirai.internal.network.components.BdhSession
|
||||||
import net.mamoe.mirai.internal.network.handler.NetworkHandler
|
|
||||||
import net.mamoe.mirai.internal.network.handler.logger
|
import net.mamoe.mirai.internal.network.handler.logger
|
||||||
import net.mamoe.mirai.internal.network.highway.ChannelKind
|
import net.mamoe.mirai.internal.network.highway.ChannelKind
|
||||||
import net.mamoe.mirai.internal.network.highway.Highway
|
import net.mamoe.mirai.internal.network.highway.Highway
|
||||||
@ -43,7 +42,6 @@ import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.PttStore
|
|||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.audioCodec
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.audioCodec
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.voiceCodec
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.voiceCodec
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.list.ProfileService
|
import net.mamoe.mirai.internal.network.protocol.packet.list.ProfileService
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.internal.utils.GroupPkgMsgParsingCache
|
import net.mamoe.mirai.internal.utils.GroupPkgMsgParsingCache
|
||||||
import net.mamoe.mirai.internal.utils.ImagePatcher
|
import net.mamoe.mirai.internal.utils.ImagePatcher
|
||||||
import net.mamoe.mirai.internal.utils.RemoteFileImpl
|
import net.mamoe.mirai.internal.utils.RemoteFileImpl
|
||||||
@ -151,15 +149,13 @@ internal class GroupImpl constructor(
|
|||||||
if (!bot.groups.delegate.remove(this)) {
|
if (!bot.groups.delegate.remove(this)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
bot.network.run {
|
|
||||||
val response: ProfileService.GroupMngReq.GroupMngReqResponse = ProfileService.GroupMngReq(
|
val response: ProfileService.GroupMngReq.GroupMngReqResponse = bot.network.sendAndExpect(
|
||||||
bot.client,
|
ProfileService.GroupMngReq(bot.client, this@GroupImpl.id), 5000, 2
|
||||||
this@GroupImpl.id
|
)
|
||||||
).sendAndExpect()
|
check(response.errorCode == 0) {
|
||||||
check(response.errorCode == 0) {
|
"Group.quit failed: $response".also {
|
||||||
"Group.quit failed: $response".also {
|
bot.groups.delegate.add(this@GroupImpl)
|
||||||
bot.groups.delegate.add(this@GroupImpl)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BotLeaveEvent.Active(this).broadcast()
|
BotLeaveEvent.Active(this).broadcast()
|
||||||
@ -210,8 +206,9 @@ internal class GroupImpl constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val imageInfo = runBIO { resource.calculateImageInfo() }
|
val imageInfo = runBIO { resource.calculateImageInfo() }
|
||||||
bot.network.run<NetworkHandler, Image> {
|
|
||||||
val response: ImgStore.GroupPicUp.Response = ImgStore.GroupPicUp(
|
val response: ImgStore.GroupPicUp.Response = bot.network.sendAndExpect(
|
||||||
|
ImgStore.GroupPicUp(
|
||||||
bot.client,
|
bot.client,
|
||||||
uin = bot.id,
|
uin = bot.id,
|
||||||
groupCode = id,
|
groupCode = id,
|
||||||
@ -222,60 +219,60 @@ internal class GroupImpl constructor(
|
|||||||
picHeight = imageInfo.height,
|
picHeight = imageInfo.height,
|
||||||
picType = getIdByImageType(imageInfo.imageType),
|
picType = getIdByImageType(imageInfo.imageType),
|
||||||
originalPic = 1
|
originalPic = 1
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
|
)
|
||||||
|
|
||||||
when (response) {
|
when (response) {
|
||||||
is ImgStore.GroupPicUp.Response.Failed -> {
|
is ImgStore.GroupPicUp.Response.Failed -> {
|
||||||
ImageUploadEvent.Failed(this@GroupImpl, resource, response.resultCode, response.message).broadcast()
|
ImageUploadEvent.Failed(this@GroupImpl, resource, response.resultCode, response.message).broadcast()
|
||||||
if (response.message == "over file size max") throw OverFileSizeMaxException()
|
if (response.message == "over file size max") throw OverFileSizeMaxException()
|
||||||
error("upload group image failed with reason ${response.message}")
|
error("upload group image failed with reason ${response.message}")
|
||||||
}
|
}
|
||||||
is ImgStore.GroupPicUp.Response.FileExists -> {
|
is ImgStore.GroupPicUp.Response.FileExists -> {
|
||||||
val resourceId = resource.calculateResourceId()
|
val resourceId = resource.calculateResourceId()
|
||||||
return response.fileInfo.run {
|
return response.fileInfo.run {
|
||||||
OfflineGroupImage(
|
OfflineGroupImage(
|
||||||
imageId = resourceId,
|
imageId = resourceId,
|
||||||
height = fileHeight,
|
height = fileHeight,
|
||||||
width = fileWidth,
|
width = fileWidth,
|
||||||
imageType = getImageTypeById(fileType),
|
imageType = getImageTypeById(fileType),
|
||||||
size = resource.size
|
size = resource.size
|
||||||
)
|
|
||||||
}
|
|
||||||
.also {
|
|
||||||
it.fileId = response.fileId.toInt()
|
|
||||||
}
|
|
||||||
.also { it.putIntoCache() }
|
|
||||||
.also { ImageUploadEvent.Succeed(this@GroupImpl, resource, it).broadcast() }
|
|
||||||
}
|
|
||||||
is ImgStore.GroupPicUp.Response.RequireUpload -> {
|
|
||||||
// val servers = response.uploadIpList.zip(response.uploadPortList)
|
|
||||||
Highway.uploadResourceBdh(
|
|
||||||
bot = bot,
|
|
||||||
resource = resource,
|
|
||||||
kind = GROUP_IMAGE,
|
|
||||||
commandId = 2,
|
|
||||||
initialTicket = response.uKey,
|
|
||||||
noBdhAwait = true,
|
|
||||||
fallbackSession = {
|
|
||||||
BdhSession(
|
|
||||||
EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY,
|
|
||||||
ssoAddresses = response.uploadIpList.zip(response.uploadPortList).toMutableSet(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return imageInfo.run {
|
|
||||||
OfflineGroupImage(
|
|
||||||
imageId = resource.calculateResourceId(),
|
|
||||||
width = width,
|
|
||||||
height = height,
|
|
||||||
imageType = imageType,
|
|
||||||
size = resource.size
|
|
||||||
)
|
|
||||||
}.also { it.fileId = response.fileId.toInt() }
|
|
||||||
.also { it.putIntoCache() }
|
|
||||||
.also { ImageUploadEvent.Succeed(this@GroupImpl, resource, it).broadcast() }
|
|
||||||
}
|
}
|
||||||
|
.also {
|
||||||
|
it.fileId = response.fileId.toInt()
|
||||||
|
}
|
||||||
|
.also { it.putIntoCache() }
|
||||||
|
.also { ImageUploadEvent.Succeed(this@GroupImpl, resource, it).broadcast() }
|
||||||
|
}
|
||||||
|
is ImgStore.GroupPicUp.Response.RequireUpload -> {
|
||||||
|
// val servers = response.uploadIpList.zip(response.uploadPortList)
|
||||||
|
Highway.uploadResourceBdh(
|
||||||
|
bot = bot,
|
||||||
|
resource = resource,
|
||||||
|
kind = GROUP_IMAGE,
|
||||||
|
commandId = 2,
|
||||||
|
initialTicket = response.uKey,
|
||||||
|
noBdhAwait = true,
|
||||||
|
fallbackSession = {
|
||||||
|
BdhSession(
|
||||||
|
EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY,
|
||||||
|
ssoAddresses = response.uploadIpList.zip(response.uploadPortList).toMutableSet(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
return imageInfo.run {
|
||||||
|
OfflineGroupImage(
|
||||||
|
imageId = resource.calculateResourceId(),
|
||||||
|
width = width,
|
||||||
|
height = height,
|
||||||
|
imageType = imageType,
|
||||||
|
size = resource.size
|
||||||
|
)
|
||||||
|
}.also { it.fileId = response.fileId.toInt() }
|
||||||
|
.also { it.putIntoCache() }
|
||||||
|
.also { ImageUploadEvent.Succeed(this@GroupImpl, resource, it).broadcast() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -300,8 +297,8 @@ internal class GroupImpl constructor(
|
|||||||
res.voiceCodec,
|
res.voiceCodec,
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun uploadAudioResource(resource: ExternalResource) {
|
private suspend fun uploadAudioResource(resource: ExternalResource) {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
@ -314,7 +311,7 @@ internal class GroupImpl constructor(
|
|||||||
.toByteArray(Cmd0x388.ReqBody.serializer()),
|
.toByteArray(Cmd0x388.ReqBody.serializer()),
|
||||||
)
|
)
|
||||||
}.recoverCatchingSuppressed {
|
}.recoverCatchingSuppressed {
|
||||||
when (val resp = PttStore.GroupPttUp(bot.client, bot.id, id, resource).sendAndExpect(bot)) {
|
when (val resp = bot.network.sendAndExpect(PttStore.GroupPttUp(bot.client, bot.id, id, resource))) {
|
||||||
is PttStore.GroupPttUp.Response.RequireUpload -> {
|
is PttStore.GroupPttUp.Response.RequireUpload -> {
|
||||||
tryServersUpload(
|
tryServersUpload(
|
||||||
bot,
|
bot,
|
||||||
@ -354,14 +351,14 @@ internal class GroupImpl constructor(
|
|||||||
|
|
||||||
override suspend fun setEssenceMessage(source: MessageSource): Boolean {
|
override suspend fun setEssenceMessage(source: MessageSource): Boolean {
|
||||||
checkBotPermission(MemberPermission.ADMINISTRATOR)
|
checkBotPermission(MemberPermission.ADMINISTRATOR)
|
||||||
val result = bot.network.run {
|
val result = bot.network.sendAndExpect(
|
||||||
TroopEssenceMsgManager.SetEssence(
|
TroopEssenceMsgManager.SetEssence(
|
||||||
bot.client,
|
bot.client,
|
||||||
this@GroupImpl.uin,
|
this@GroupImpl.uin,
|
||||||
source.internalIds.first(),
|
source.internalIds.first(),
|
||||||
source.ids.first()
|
source.ids.first()
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
return result.success
|
return result.success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.contact
|
package net.mamoe.mirai.internal.contact
|
||||||
@ -24,7 +24,6 @@ import net.mamoe.mirai.internal.network.QQAndroidClient
|
|||||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopManagement.GroupOperation
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopManagement.GroupOperation
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopManagement.SwitchAnonymousChat
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopManagement.SwitchAnonymousChat
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
|
|
||||||
@Suppress("SetterBackingFieldAssignment")
|
@Suppress("SetterBackingFieldAssignment")
|
||||||
internal class GroupSettingsImpl(
|
internal class GroupSettingsImpl(
|
||||||
@ -43,9 +42,7 @@ internal class GroupSettingsImpl(
|
|||||||
val oldValue = getter()
|
val oldValue = getter()
|
||||||
setter(newValue)
|
setter(newValue)
|
||||||
launch {
|
launch {
|
||||||
bot.network.run {
|
bot.network.sendWithoutExpect(packetConstructor(bot.client, id, newValue))
|
||||||
packetConstructor(bot.client, id, newValue).sendWithoutExpect()
|
|
||||||
}
|
|
||||||
eventConstructor(oldValue).broadcast()
|
eventConstructor(oldValue).broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,7 +95,7 @@ internal class GroupSettingsImpl(
|
|||||||
checkBotPermission(MemberPermission.ADMINISTRATOR)
|
checkBotPermission(MemberPermission.ADMINISTRATOR)
|
||||||
launch {
|
launch {
|
||||||
//Handle it in NoticePipelineContext#processAllowAnonymousChat
|
//Handle it in NoticePipelineContext#processAllowAnonymousChat
|
||||||
SwitchAnonymousChat(bot.client, id, newValue).sendAndExpect(bot.network)
|
bot.network.sendAndExpect(SwitchAnonymousChat(bot.client, id, newValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("EXPERIMENTAL_API_USAGE")
|
@file:Suppress("EXPERIMENTAL_API_USAGE")
|
||||||
@ -93,13 +93,13 @@ internal class NormalMemberImpl constructor(
|
|||||||
val oldValue = _nameCard
|
val oldValue = _nameCard
|
||||||
_nameCard = newValue
|
_nameCard = newValue
|
||||||
launch {
|
launch {
|
||||||
bot.network.run {
|
bot.network.sendWithoutExpect(
|
||||||
TroopManagement.EditGroupNametag(
|
TroopManagement.EditGroupNametag(
|
||||||
bot.client,
|
bot.client,
|
||||||
this@NormalMemberImpl,
|
this@NormalMemberImpl,
|
||||||
newValue,
|
newValue,
|
||||||
).sendWithoutExpect()
|
)
|
||||||
}
|
)
|
||||||
MemberCardChangeEvent(oldValue, newValue, this@NormalMemberImpl).broadcast()
|
MemberCardChangeEvent(oldValue, newValue, this@NormalMemberImpl).broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,13 +113,13 @@ internal class NormalMemberImpl constructor(
|
|||||||
val oldValue = _specialTitle
|
val oldValue = _specialTitle
|
||||||
_specialTitle = newValue
|
_specialTitle = newValue
|
||||||
launch {
|
launch {
|
||||||
bot.network.run {
|
bot.network.sendWithoutExpect(
|
||||||
TroopManagement.EditSpecialTitle(
|
TroopManagement.EditSpecialTitle(
|
||||||
bot.client,
|
bot.client,
|
||||||
this@NormalMemberImpl,
|
this@NormalMemberImpl,
|
||||||
newValue,
|
newValue,
|
||||||
).sendWithoutExpect()
|
)
|
||||||
}
|
)
|
||||||
MemberSpecialTitleChangeEvent(oldValue, newValue, this@NormalMemberImpl, null).broadcast()
|
MemberSpecialTitleChangeEvent(oldValue, newValue, this@NormalMemberImpl, null).broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,14 +133,14 @@ internal class NormalMemberImpl constructor(
|
|||||||
"durationSeconds must greater than zero"
|
"durationSeconds must greater than zero"
|
||||||
}
|
}
|
||||||
checkBotPermissionHigherThanThis("mute")
|
checkBotPermissionHigherThanThis("mute")
|
||||||
bot.network.run {
|
bot.network.sendAndExpect(
|
||||||
TroopManagement.Mute(
|
TroopManagement.Mute(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
groupCode = group.id,
|
groupCode = group.id,
|
||||||
memberUin = this@NormalMemberImpl.id,
|
memberUin = this@NormalMemberImpl.id,
|
||||||
timeInSecond = durationSeconds,
|
timeInSecond = durationSeconds,
|
||||||
).sendAndExpect<TroopManagement.Mute.Response>()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
|
|
||||||
@Suppress("RemoveRedundantQualifierName") // or unresolved reference
|
@Suppress("RemoveRedundantQualifierName") // or unresolved reference
|
||||||
(net.mamoe.mirai.event.events.MemberMuteEvent(this@NormalMemberImpl, durationSeconds, null).broadcast())
|
(net.mamoe.mirai.event.events.MemberMuteEvent(this@NormalMemberImpl, durationSeconds, null).broadcast())
|
||||||
@ -149,14 +149,14 @@ internal class NormalMemberImpl constructor(
|
|||||||
|
|
||||||
override suspend fun unmute() {
|
override suspend fun unmute() {
|
||||||
checkBotPermissionHigherThanThis("unmute")
|
checkBotPermissionHigherThanThis("unmute")
|
||||||
bot.network.run {
|
bot.network.sendAndExpect(
|
||||||
TroopManagement.Mute(
|
TroopManagement.Mute(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
groupCode = group.id,
|
groupCode = group.id,
|
||||||
memberUin = this@NormalMemberImpl.id,
|
memberUin = this@NormalMemberImpl.id,
|
||||||
timeInSecond = 0,
|
timeInSecond = 0,
|
||||||
).sendAndExpect<TroopManagement.Mute.Response>()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
|
|
||||||
@Suppress("RemoveRedundantQualifierName") // or unresolved reference
|
@Suppress("RemoveRedundantQualifierName") // or unresolved reference
|
||||||
(net.mamoe.mirai.event.events.MemberUnmuteEvent(this@NormalMemberImpl, null).broadcast())
|
(net.mamoe.mirai.event.events.MemberUnmuteEvent(this@NormalMemberImpl, null).broadcast())
|
||||||
@ -168,25 +168,25 @@ internal class NormalMemberImpl constructor(
|
|||||||
check(group.members[this.id] != null) {
|
check(group.members[this.id] != null) {
|
||||||
"Member ${this.id} had already been kicked from group ${group.id}"
|
"Member ${this.id} had already been kicked from group ${group.id}"
|
||||||
}
|
}
|
||||||
bot.network.run {
|
val response: TroopManagement.Kick.Response = bot.network.sendAndExpect(
|
||||||
val response: TroopManagement.Kick.Response = TroopManagement.Kick(
|
TroopManagement.Kick(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
groupCode = group.groupCode,
|
groupCode = group.groupCode,
|
||||||
memberId = id,
|
memberId = id,
|
||||||
message = message,
|
message = message,
|
||||||
ban = block
|
ban = block
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
|
)
|
||||||
|
|
||||||
// Note: when member not found, result is still true.
|
// Note: when member not found, result is still true.
|
||||||
|
|
||||||
if (response.ret == 255) error("Operation too fast") // https://github.com/mamoe/mirai/issues/1503
|
if (response.ret == 255) error("Operation too fast") // https://github.com/mamoe/mirai/issues/1503
|
||||||
check(response.success) { "kick failed: ${response.ret}" }
|
check(response.success) { "kick failed: ${response.ret}" }
|
||||||
|
|
||||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
group.members.delegate.removeIf { it.id == this@NormalMemberImpl.id }
|
group.members.delegate.removeIf { it.id == this@NormalMemberImpl.id }
|
||||||
this@NormalMemberImpl.cancel(CancellationException("Kicked by bot"))
|
this@NormalMemberImpl.cancel(CancellationException("Kicked by bot"))
|
||||||
MemberLeaveEvent.Kick(this@NormalMemberImpl, null).broadcast()
|
MemberLeaveEvent.Kick(this@NormalMemberImpl, null).broadcast()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun modifyAdmin(operation: Boolean) {
|
override suspend fun modifyAdmin(operation: Boolean) {
|
||||||
@ -201,21 +201,21 @@ internal class NormalMemberImpl constructor(
|
|||||||
|
|
||||||
if (origin == new) return
|
if (origin == new) return
|
||||||
|
|
||||||
bot.network.run {
|
val resp: TroopManagement.ModifyAdmin.Response = bot.network.sendAndExpect(
|
||||||
val resp: TroopManagement.ModifyAdmin.Response = TroopManagement.ModifyAdmin(
|
TroopManagement.ModifyAdmin(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
member = this@NormalMemberImpl,
|
member = this@NormalMemberImpl,
|
||||||
operation = operation,
|
operation = operation,
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
|
) as TroopManagement.ModifyAdmin.Response
|
||||||
|
|
||||||
check(resp.success) {
|
check(resp.success) {
|
||||||
"Failed to modify admin, cause: ${resp.msg}"
|
"Failed to modify admin, cause: ${resp.msg}"
|
||||||
}
|
|
||||||
|
|
||||||
this@NormalMemberImpl.permission = new
|
|
||||||
|
|
||||||
MemberPermissionChangeEvent(this@NormalMemberImpl, origin, new).broadcast()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this@NormalMemberImpl.permission = new
|
||||||
|
|
||||||
|
MemberPermissionChangeEvent(this@NormalMemberImpl, origin, new).broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ internal abstract class SendMessageHandler<C : Contact> {
|
|||||||
fragmented = step == SendMessageStep.FRAGMENTED
|
fragmented = step == SendMessageStep.FRAGMENTED
|
||||||
) { source = it }.forEach { packet ->
|
) { source = it }.forEach { packet ->
|
||||||
|
|
||||||
when (val resp = packet.sendAndExpect<Packet>()) {
|
when (val resp = bot.network.sendAndExpect<Packet>(packet, 5000, 2)) {
|
||||||
is MessageSvcPbSendMsg.Response -> {
|
is MessageSvcPbSendMsg.Response -> {
|
||||||
if (resp is MessageSvcPbSendMsg.Response.MessageTooLarge) {
|
if (resp is MessageSvcPbSendMsg.Response.MessageTooLarge) {
|
||||||
return when (step) {
|
return when (step) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
@file:OptIn(LowLevelApi::class)
|
@file:OptIn(LowLevelApi::class)
|
||||||
@file:Suppress(
|
@file:Suppress(
|
||||||
@ -54,11 +54,8 @@ internal class StrangerImpl(
|
|||||||
check(bot.strangers[this.id] != null) {
|
check(bot.strangers[this.id] != null) {
|
||||||
"Stranger ${this.id} had already been deleted"
|
"Stranger ${this.id} had already been deleted"
|
||||||
}
|
}
|
||||||
bot.network.run {
|
bot.network.sendAndExpect(StrangerList.DelStranger(bot.client, this@StrangerImpl), 5000, 2).also {
|
||||||
StrangerList.DelStranger(bot.client, this@StrangerImpl)
|
check(it.isSuccess) { "delete Stranger failed: ${it.result}" }
|
||||||
.sendAndExpect().also {
|
|
||||||
check(it.isSuccess) { "delete Stranger failed: ${it.result}" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
@ -15,7 +15,6 @@ import net.mamoe.mirai.contact.file.AbsoluteFolder
|
|||||||
import net.mamoe.mirai.internal.message.FileMessageImpl
|
import net.mamoe.mirai.internal.message.FileMessageImpl
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.message.data.FileMessage
|
import net.mamoe.mirai.message.data.FileMessage
|
||||||
import net.mamoe.mirai.utils.toUHexString
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
|
|
||||||
@ -59,13 +58,14 @@ internal class AbsoluteFileImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun exists(): Boolean {
|
override suspend fun exists(): Boolean {
|
||||||
return FileManagement.GetFileInfo(
|
return bot.network.sendAndExpect(
|
||||||
client,
|
FileManagement.GetFileInfo(
|
||||||
groupCode = contact.id,
|
client,
|
||||||
busId = busId,
|
groupCode = contact.id,
|
||||||
fileId = id
|
busId = busId,
|
||||||
).sendAndExpect(bot)
|
fileId = id
|
||||||
.toResult("AbsoluteFileImpl.exists", checkResp = false)
|
)
|
||||||
|
).toResult("AbsoluteFileImpl.exists", checkResp = false)
|
||||||
.getOrThrow()
|
.getOrThrow()
|
||||||
.fileInfo != null
|
.fileInfo != null
|
||||||
}
|
}
|
||||||
@ -78,9 +78,20 @@ internal class AbsoluteFileImpl(
|
|||||||
if (folder.absolutePath == this.parentOrRoot.absolutePath) return true
|
if (folder.absolutePath == this.parentOrRoot.absolutePath) return true
|
||||||
checkPermission("moveTo")
|
checkPermission("moveTo")
|
||||||
|
|
||||||
val result = FileManagement.MoveFile(client, contact.id, busId, id, parent.idOrRoot, folder.idOrRoot)
|
|
||||||
.sendAndExpect(bot).toResult("AbsoluteFileImpl.moveTo", checkResp = false)
|
val result =
|
||||||
.getOrThrow()
|
bot.network.sendAndExpect(
|
||||||
|
FileManagement.MoveFile(
|
||||||
|
client,
|
||||||
|
contact.id,
|
||||||
|
busId,
|
||||||
|
id,
|
||||||
|
parent.idOrRoot,
|
||||||
|
folder.idOrRoot
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.toResult("AbsoluteFileImpl.moveTo", checkResp = false)
|
||||||
|
.getOrThrow()
|
||||||
|
|
||||||
return when (result.int32RetCode) {
|
return when (result.int32RetCode) {
|
||||||
-36 -> throwPermissionDeniedException("moveTo")
|
-36 -> throwPermissionDeniedException("moveTo")
|
||||||
@ -103,14 +114,14 @@ internal class AbsoluteFileImpl(
|
|||||||
// java.lang.IllegalStateException: Failed AbsoluteFileImpl.getUrl, result=-303, msg=param error: bus_id
|
// java.lang.IllegalStateException: Failed AbsoluteFileImpl.getUrl, result=-303, msg=param error: bus_id
|
||||||
// java.lang.IllegalStateException: Failed AbsoluteFileImpl.getUrl, result=-103, msg=GetFileAttrAction file not exist
|
// java.lang.IllegalStateException: Failed AbsoluteFileImpl.getUrl, result=-103, msg=GetFileAttrAction file not exist
|
||||||
|
|
||||||
val resp = FileManagement.RequestDownload(
|
val resp = bot.network.sendAndExpect(
|
||||||
client,
|
FileManagement.RequestDownload(
|
||||||
groupCode = contact.id,
|
client,
|
||||||
busId = busId,
|
groupCode = contact.id,
|
||||||
fileId = id
|
busId = busId,
|
||||||
).sendAndExpect(bot)
|
fileId = id
|
||||||
.toResult("AbsoluteFileImpl.getUrl")
|
)
|
||||||
.getOrElse { return null }
|
).toResult("AbsoluteFileImpl.getUrl").getOrElse { return null }
|
||||||
|
|
||||||
|
|
||||||
return "http://${resp.downloadIp}/ftn_handler/${resp.downloadUrl.toUHexString("")}/?fname=" +
|
return "http://${resp.downloadIp}/ftn_handler/${resp.downloadUrl.toUHexString("")}/?fname=" +
|
||||||
@ -133,8 +144,7 @@ internal class AbsoluteFileImpl(
|
|||||||
override fun toString(): String = "AbsoluteFile(name=$name, absolutePath=$absolutePath, id=$id)"
|
override fun toString(): String = "AbsoluteFile(name=$name, absolutePath=$absolutePath, id=$id)"
|
||||||
|
|
||||||
override suspend fun refreshed(): AbsoluteFile? {
|
override suspend fun refreshed(): AbsoluteFile? {
|
||||||
val result = FileManagement.GetFileInfo(client, contact.id, id, busId)
|
val result = bot.network.sendAndExpect(FileManagement.GetFileInfo(client, contact.id, id, busId))
|
||||||
.sendAndExpect(bot)
|
|
||||||
.toResult("AbsoluteFile.refreshed")
|
.toResult("AbsoluteFile.refreshed")
|
||||||
.getOrNull()?.fileInfo
|
.getOrNull()?.fileInfo
|
||||||
?: return null
|
?: return null
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
@ -27,7 +27,6 @@ import net.mamoe.mirai.internal.network.protocol
|
|||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.*
|
import net.mamoe.mirai.internal.network.protocol.data.proto.*
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.internal.utils.FileSystem
|
import net.mamoe.mirai.internal.utils.FileSystem
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.toByteArray
|
import net.mamoe.mirai.internal.utils.io.serialization.toByteArray
|
||||||
import net.mamoe.mirai.utils.*
|
import net.mamoe.mirai.utils.*
|
||||||
@ -113,12 +112,15 @@ internal class AbsoluteFolderImpl(
|
|||||||
return flow {
|
return flow {
|
||||||
var index = 0
|
var index = 0
|
||||||
while (true) {
|
while (true) {
|
||||||
val list = FileManagement.GetFileList(
|
val list =
|
||||||
client,
|
client.bot.network.sendAndExpect(
|
||||||
groupCode = contact.id,
|
FileManagement.GetFileList(
|
||||||
folderId = folderId,
|
client,
|
||||||
startIndex = index
|
groupCode = contact.id,
|
||||||
).sendAndExpect(client.bot).toResult("AbsoluteFolderImpl.getFilesFlow").getOrThrow()
|
folderId = folderId,
|
||||||
|
startIndex = index
|
||||||
|
)
|
||||||
|
).toResult("AbsoluteFolderImpl.getFilesFlow").getOrThrow()
|
||||||
index += list.itemList.size
|
index += list.itemList.size
|
||||||
|
|
||||||
if (list.int32RetCode != 0) return@flow
|
if (list.int32RetCode != 0) return@flow
|
||||||
@ -139,13 +141,16 @@ internal class AbsoluteFolderImpl(
|
|||||||
// TODO: 12/10/2021 checkPermission for AbsoluteFolderImpl.upload
|
// TODO: 12/10/2021 checkPermission for AbsoluteFolderImpl.upload
|
||||||
|
|
||||||
content.withAutoClose {
|
content.withAutoClose {
|
||||||
val resp = FileManagement.RequestUpload(
|
val resp =
|
||||||
folder.client,
|
folder.bot.network.sendAndExpect(
|
||||||
groupCode = folder.contact.id,
|
FileManagement.RequestUpload(
|
||||||
folderId = folder.id,
|
folder.client,
|
||||||
resource = content,
|
groupCode = folder.contact.id,
|
||||||
filename = filepath
|
folderId = folder.id,
|
||||||
).sendAndExpect(folder.bot).toResult("AbsoluteFolderImpl.upload").getOrThrow()
|
resource = content,
|
||||||
|
filename = filepath
|
||||||
|
)
|
||||||
|
).toResult("AbsoluteFolderImpl.upload").getOrThrow()
|
||||||
|
|
||||||
when (resp.int32RetCode) {
|
when (resp.int32RetCode) {
|
||||||
-36 -> folder.throwPermissionDeniedException("uploadNewFile")
|
-36 -> folder.throwPermissionDeniedException("uploadNewFile")
|
||||||
@ -254,12 +259,14 @@ internal class AbsoluteFolderImpl(
|
|||||||
var index = 0
|
var index = 0
|
||||||
while (true) {
|
while (true) {
|
||||||
val list = runBlocking {
|
val list = runBlocking {
|
||||||
FileManagement.GetFileList(
|
bot.network.sendAndExpect(
|
||||||
client,
|
FileManagement.GetFileList(
|
||||||
groupCode = contact.id,
|
client,
|
||||||
folderId = id,
|
groupCode = contact.id,
|
||||||
startIndex = index
|
folderId = id,
|
||||||
).sendAndExpect(bot)
|
startIndex = index
|
||||||
|
)
|
||||||
|
)
|
||||||
}.toResult("AbsoluteFolderImpl.getFilesFlow").getOrThrow()
|
}.toResult("AbsoluteFolderImpl.getFilesFlow").getOrThrow()
|
||||||
index += list.itemList.size
|
index += list.itemList.size
|
||||||
|
|
||||||
@ -307,8 +314,8 @@ internal class AbsoluteFolderImpl(
|
|||||||
|
|
||||||
// server only support nesting depth level of 1 so we don't need to check the name
|
// server only support nesting depth level of 1 so we don't need to check the name
|
||||||
|
|
||||||
val result = FileManagement.CreateFolder(client, contact.id, this.id, name)
|
val result = bot.network.sendAndExpect(FileManagement.CreateFolder(client, contact.id, this.id, name))
|
||||||
.sendAndExpect(bot).toResult("AbsoluteFolderImpl.mkdir", checkResp = false)
|
.toResult("AbsoluteFolderImpl.mkdir", checkResp = false)
|
||||||
.getOrThrow() // throw protocol errors
|
.getOrThrow() // throw protocol errors
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -389,7 +396,7 @@ internal class AbsoluteFolderImpl(
|
|||||||
|
|
||||||
if (!deep) return null
|
if (!deep) return null
|
||||||
|
|
||||||
return folders().map { it.resolveFileById(id, deep) }.firstOrNull{ it != null }
|
return folders().map { it.resolveFileById(id, deep) }.firstOrNull { it != null }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resolveFiles(path: String): Flow<AbsoluteFile> {
|
override suspend fun resolveFiles(path: String): Flow<AbsoluteFile> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
@ -19,7 +19,6 @@ import net.mamoe.mirai.contact.file.AbsoluteFolder
|
|||||||
import net.mamoe.mirai.internal.asQQAndroidBot
|
import net.mamoe.mirai.internal.asQQAndroidBot
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.internal.utils.FileSystem
|
import net.mamoe.mirai.internal.utils.FileSystem
|
||||||
import net.mamoe.mirai.utils.cast
|
import net.mamoe.mirai.utils.cast
|
||||||
|
|
||||||
@ -72,11 +71,13 @@ internal abstract class AbstractAbsoluteFileFolder(
|
|||||||
parentOrFail()
|
parentOrFail()
|
||||||
checkPermission("renameTo")
|
checkPermission("renameTo")
|
||||||
|
|
||||||
val result = if (isFile) {
|
val result = bot.network.sendAndExpect(
|
||||||
FileManagement.RenameFile(client, contact.id, busId, id, parent.idOrRoot, newName)
|
if (isFile) {
|
||||||
} else {
|
FileManagement.RenameFile(client, contact.id, busId, id, parent.idOrRoot, newName)
|
||||||
FileManagement.RenameFolder(client, contact.id, id, newName)
|
} else {
|
||||||
}.sendAndExpect(bot)
|
FileManagement.RenameFolder(client, contact.id, id, newName)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
result.toResult("AbstractAbsoluteFileFolder.renameTo") {
|
result.toResult("AbstractAbsoluteFileFolder.renameTo") {
|
||||||
when (it) {
|
when (it) {
|
||||||
@ -95,10 +96,10 @@ internal abstract class AbstractAbsoluteFileFolder(
|
|||||||
suspend fun delete(): Boolean {
|
suspend fun delete(): Boolean {
|
||||||
checkPermission("delete")
|
checkPermission("delete")
|
||||||
val result = if (isFile) {
|
val result = if (isFile) {
|
||||||
FileManagement.DeleteFile(client, contact.id, busId, id, parent.idOrRoot).sendAndExpect(bot)
|
bot.network.sendAndExpect(FileManagement.DeleteFile(client, contact.id, busId, id, parent.idOrRoot))
|
||||||
} else {
|
} else {
|
||||||
// natively 'recursive'
|
// natively 'recursive'
|
||||||
FileManagement.DeleteFolder(client, contact.id, id).sendAndExpect(bot)
|
bot.network.sendAndExpect(FileManagement.DeleteFolder(client, contact.id, id))
|
||||||
}.toResult("AbstractAbsoluteFileFolder.delete", checkResp = false).getOrThrow()
|
}.toResult("AbstractAbsoluteFileFolder.delete", checkResp = false).getOrThrow()
|
||||||
|
|
||||||
return when (result.int32RetCode) {
|
return when (result.int32RetCode) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
@ -25,7 +25,6 @@ import net.mamoe.mirai.internal.contact.FriendImpl
|
|||||||
import net.mamoe.mirai.internal.message.toMessageChainOnline
|
import net.mamoe.mirai.internal.message.toMessageChainOnline
|
||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm
|
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbGetRoamMsgReq
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbGetRoamMsgReq
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.message.data.MessageChain
|
import net.mamoe.mirai.message.data.MessageChain
|
||||||
import net.mamoe.mirai.utils.*
|
import net.mamoe.mirai.utils.*
|
||||||
import java.util.stream.Stream
|
import java.util.stream.Stream
|
||||||
@ -123,15 +122,17 @@ internal class RoamingMessagesImplFriend(
|
|||||||
lastMessageTime: Long,
|
lastMessageTime: Long,
|
||||||
random: Long
|
random: Long
|
||||||
): MessageSvcPbGetRoamMsgReq.Response {
|
): MessageSvcPbGetRoamMsgReq.Response {
|
||||||
return MessageSvcPbGetRoamMsgReq.createForFriend(
|
return contact.bot.network.sendAndExpect(
|
||||||
client = contact.bot.client,
|
MessageSvcPbGetRoamMsgReq.createForFriend(
|
||||||
uin = contact.id,
|
client = contact.bot.client,
|
||||||
timeStart = timeStart,
|
uin = contact.id,
|
||||||
lastMsgTime = lastMessageTime,
|
timeStart = timeStart,
|
||||||
random = random,
|
lastMsgTime = lastMessageTime,
|
||||||
maxCount = 1000,
|
random = random,
|
||||||
sig = byteArrayOf(),
|
maxCount = 1000,
|
||||||
pwd = byteArrayOf()
|
sig = byteArrayOf(),
|
||||||
).sendAndExpect(contact.bot).value.check()
|
pwd = byteArrayOf()
|
||||||
|
)
|
||||||
|
).value.check()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -28,7 +28,6 @@ import net.mamoe.mirai.internal.contact.file.resolved
|
|||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.Oidb0x6d8.GetFileListRspBody
|
import net.mamoe.mirai.internal.network.protocol.data.proto.Oidb0x6d8.GetFileListRspBody
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.message.data.FileMessage
|
import net.mamoe.mirai.message.data.FileMessage
|
||||||
import net.mamoe.mirai.utils.cast
|
import net.mamoe.mirai.utils.cast
|
||||||
import kotlin.contracts.contract
|
import kotlin.contracts.contract
|
||||||
@ -51,8 +50,8 @@ internal data class FileMessageImpl(
|
|||||||
get() = busId
|
get() = busId
|
||||||
|
|
||||||
override suspend fun toAbsoluteFile(contact: FileSupported): AbsoluteFile? {
|
override suspend fun toAbsoluteFile(contact: FileSupported): AbsoluteFile? {
|
||||||
val result = FileManagement.GetFileInfo(contact.bot.asQQAndroidBot().client, contact.id, id, busId)
|
val result = contact.bot.asQQAndroidBot().network
|
||||||
.sendAndExpect(contact.bot.asQQAndroidBot())
|
.sendAndExpect(FileManagement.GetFileInfo(contact.bot.asQQAndroidBot().client, contact.id, id, busId))
|
||||||
.toResult("FileMessage.toAbsoluteFile").getOrThrow()
|
.toResult("FileMessage.toAbsoluteFile").getOrThrow()
|
||||||
if (result.fileInfo == null) return null
|
if (result.fileInfo == null) return null
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
@ -18,7 +18,6 @@ import net.mamoe.mirai.internal.asQQAndroidBot
|
|||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0x352
|
import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0x352
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.ImgStore
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.ImgStore
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.LongConn
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.LongConn
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.internal.utils.ImagePatcher
|
import net.mamoe.mirai.internal.utils.ImagePatcher
|
||||||
import net.mamoe.mirai.internal.utils.ImagePatcher.Companion.withCache
|
import net.mamoe.mirai.internal.utils.ImagePatcher.Companion.withCache
|
||||||
import net.mamoe.mirai.message.data.Image
|
import net.mamoe.mirai.message.data.Image
|
||||||
@ -66,18 +65,20 @@ internal class InternalImageProtocolImpl : InternalImageProtocol {
|
|||||||
width: Int,
|
width: Int,
|
||||||
height: Int
|
height: Int
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val response: ImgStore.GroupPicUp.Response = ImgStore.GroupPicUp(
|
val response: ImgStore.GroupPicUp.Response = bot.network.sendAndExpect(
|
||||||
bot.client,
|
ImgStore.GroupPicUp(
|
||||||
uin = bot.id,
|
bot.client,
|
||||||
groupCode = context.id,
|
uin = bot.id,
|
||||||
md5 = md5,
|
groupCode = context.id,
|
||||||
size = size,
|
md5 = md5,
|
||||||
filename = "${md5.toUHexString("")}.${type.formatName}",
|
size = size,
|
||||||
picWidth = width,
|
filename = "${md5.toUHexString("")}.${type.formatName}",
|
||||||
picHeight = height,
|
picWidth = width,
|
||||||
picType = getIdByImageType(type),
|
picHeight = height,
|
||||||
originalPic = 1
|
picType = getIdByImageType(type),
|
||||||
).sendAndExpect(bot)
|
originalPic = 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return response is ImgStore.GroupPicUp.Response.FileExists
|
return response is ImgStore.GroupPicUp.Response.FileExists
|
||||||
}
|
}
|
||||||
@ -93,22 +94,24 @@ internal class InternalImageProtocolImpl : InternalImageProtocol {
|
|||||||
width: Int,
|
width: Int,
|
||||||
height: Int
|
height: Int
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val resp = LongConn.OffPicUp(
|
val resp = bot.network.sendAndExpect(
|
||||||
bot.client,
|
LongConn.OffPicUp(
|
||||||
Cmd0x352.TryUpImgReq(
|
bot.client,
|
||||||
buType = 1,
|
Cmd0x352.TryUpImgReq(
|
||||||
srcUin = bot.id,
|
buType = 1,
|
||||||
dstUin = context.id,
|
srcUin = bot.id,
|
||||||
fileMd5 = md5,
|
dstUin = context.id,
|
||||||
fileSize = size,
|
fileMd5 = md5,
|
||||||
imgWidth = width,
|
fileSize = size,
|
||||||
imgHeight = height,
|
imgWidth = width,
|
||||||
imgType = getIdByImageType(type),
|
imgHeight = height,
|
||||||
fileName = "${md5.toUHexString("")}.${type.formatName}",
|
imgType = getIdByImageType(type),
|
||||||
imgOriginal = true,
|
fileName = "${md5.toUHexString("")}.${type.formatName}",
|
||||||
buildVer = bot.client.buildVer,
|
imgOriginal = true,
|
||||||
),
|
buildVer = bot.client.buildVer,
|
||||||
).sendAndExpect<LongConn.OffPicUp.Response>(bot)
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return resp is LongConn.OffPicUp.Response.FileExists
|
return resp is LongConn.OffPicUp.Response.FileExists
|
||||||
}
|
}
|
||||||
@ -124,18 +127,20 @@ internal class InternalImageProtocolImpl : InternalImageProtocol {
|
|||||||
width: Int,
|
width: Int,
|
||||||
height: Int
|
height: Int
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val response: ImgStore.GroupPicUp.Response = ImgStore.GroupPicUp(
|
val response: ImgStore.GroupPicUp.Response = bot.network.sendAndExpect(
|
||||||
bot.client,
|
ImgStore.GroupPicUp(
|
||||||
uin = bot.id,
|
bot.client,
|
||||||
groupCode = 1,
|
uin = bot.id,
|
||||||
md5 = md5,
|
groupCode = 1,
|
||||||
size = size,
|
md5 = md5,
|
||||||
filename = "${md5.toUHexString("")}.${type.formatName}",
|
size = size,
|
||||||
picWidth = width,
|
filename = "${md5.toUHexString("")}.${type.formatName}",
|
||||||
picHeight = height,
|
picWidth = width,
|
||||||
picType = getIdByImageType(type),
|
picHeight = height,
|
||||||
originalPic = 1
|
picType = getIdByImageType(type),
|
||||||
).sendAndExpect(bot)
|
originalPic = 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return response is ImgStore.GroupPicUp.Response.FileExists
|
return response is ImgStore.GroupPicUp.Response.FileExists
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
@ -194,14 +194,14 @@ internal open class MultiMsgUploader(
|
|||||||
open suspend fun uploadAndReturnResId(): String {
|
open suspend fun uploadAndReturnResId(): String {
|
||||||
val data = toMessageValidationData()
|
val data = toMessageValidationData()
|
||||||
|
|
||||||
val response = client.bot.network.run {
|
val response = client.bot.network.sendAndExpect(
|
||||||
MultiMsg.ApplyUp.createForGroup(
|
MultiMsg.ApplyUp.createForGroup(
|
||||||
buType = if (isLong) 1 else 2,
|
buType = if (isLong) 1 else 2,
|
||||||
client = client,
|
client = client,
|
||||||
messageData = data,
|
messageData = data,
|
||||||
dstUin = handler.targetUin
|
dstUin = handler.targetUin
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
|
|
||||||
val resId: String
|
val resId: String
|
||||||
when (response) {
|
when (response) {
|
||||||
|
@ -28,7 +28,6 @@ import net.mamoe.mirai.internal.contact.info.GroupInfoImpl
|
|||||||
import net.mamoe.mirai.internal.contact.info.MemberInfoImpl
|
import net.mamoe.mirai.internal.contact.info.MemberInfoImpl
|
||||||
import net.mamoe.mirai.internal.contact.info.StrangerInfoImpl
|
import net.mamoe.mirai.internal.contact.info.StrangerInfoImpl
|
||||||
import net.mamoe.mirai.internal.contact.toMiraiFriendInfo
|
import net.mamoe.mirai.internal.contact.toMiraiFriendInfo
|
||||||
import net.mamoe.mirai.internal.network.Packet
|
|
||||||
import net.mamoe.mirai.internal.network.component.ComponentKey
|
import net.mamoe.mirai.internal.network.component.ComponentKey
|
||||||
import net.mamoe.mirai.internal.network.component.ComponentStorage
|
import net.mamoe.mirai.internal.network.component.ComponentStorage
|
||||||
import net.mamoe.mirai.internal.network.isValid
|
import net.mamoe.mirai.internal.network.isValid
|
||||||
@ -39,7 +38,6 @@ import net.mamoe.mirai.internal.network.protocol.data.jce.isValid
|
|||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopManagement
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopManagement
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.list.StrangerList
|
import net.mamoe.mirai.internal.network.protocol.packet.list.StrangerList
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.utils.MiraiLogger
|
import net.mamoe.mirai.utils.MiraiLogger
|
||||||
import net.mamoe.mirai.utils.info
|
import net.mamoe.mirai.utils.info
|
||||||
import net.mamoe.mirai.utils.retryCatching
|
import net.mamoe.mirai.utils.retryCatching
|
||||||
@ -140,9 +138,11 @@ internal class ContactUpdaterImpl(
|
|||||||
var count = 0
|
var count = 0
|
||||||
var total: Short
|
var total: Short
|
||||||
while (true) {
|
while (true) {
|
||||||
val data = FriendList.GetFriendGroupList(
|
val data = bot.network.sendAndExpect(
|
||||||
bot.client, count, 150, 0, 0
|
FriendList.GetFriendGroupList(bot.client, count, 150, 0, 0),
|
||||||
).sendAndExpect(bot, timeoutMillis = 5000, retry = 2)
|
timeout = 5000,
|
||||||
|
attempts = 2
|
||||||
|
)
|
||||||
|
|
||||||
total = data.totalFriendCount
|
total = data.totalFriendCount
|
||||||
|
|
||||||
@ -163,9 +163,11 @@ internal class ContactUpdaterImpl(
|
|||||||
logger.info { "Loaded ${list.size} friends from local cache." }
|
logger.info { "Loaded ${list.size} friends from local cache." }
|
||||||
|
|
||||||
// For sync bot nick
|
// For sync bot nick
|
||||||
FriendList.GetFriendGroupList(
|
bot.network.sendAndExpect(
|
||||||
bot.client, 0, 1, 0, 0
|
FriendList.GetFriendGroupList(
|
||||||
).sendAndExpect<Packet>(bot)
|
bot.client, 0, 1, 0, 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
list
|
list
|
||||||
} else {
|
} else {
|
||||||
@ -225,8 +227,12 @@ internal class ContactUpdaterImpl(
|
|||||||
}
|
}
|
||||||
var currentCount = 0
|
var currentCount = 0
|
||||||
logger.info { "Start loading stranger list..." }
|
logger.info { "Start loading stranger list..." }
|
||||||
val response = StrangerList.GetStrangerList(bot.client)
|
|
||||||
.sendAndExpect(bot, timeoutMillis = 5000, retry = 2)
|
val response = bot.network.sendAndExpect(
|
||||||
|
StrangerList.GetStrangerList(bot.client),
|
||||||
|
timeout = 5000,
|
||||||
|
attempts = 2
|
||||||
|
)
|
||||||
|
|
||||||
if (response.result == 0) {
|
if (response.result == 0) {
|
||||||
response.strangerList.forEach {
|
response.strangerList.forEach {
|
||||||
@ -245,11 +251,12 @@ internal class ContactUpdaterImpl(
|
|||||||
if (initGroupOk) {
|
if (initGroupOk) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
TroopManagement.GetTroopConfig(bot.client).sendAndExpect(bot)
|
|
||||||
|
bot.network.sendAndExpect(TroopManagement.GetTroopConfig(bot.client))
|
||||||
|
|
||||||
logger.info { "Start loading group list..." }
|
logger.info { "Start loading group list..." }
|
||||||
val troopListData = FriendList.GetTroopListSimplify(bot.client)
|
|
||||||
.sendAndExpect(bot, retry = 5)
|
val troopListData = bot.network.sendAndExpect(FriendList.GetTroopListSimplify(bot.client), attempts = 5)
|
||||||
|
|
||||||
val semaphore = Semaphore(30)
|
val semaphore = Semaphore(30)
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import net.mamoe.mirai.internal.network.component.ComponentKey
|
|||||||
import net.mamoe.mirai.internal.network.handler.NetworkHandler
|
import net.mamoe.mirai.internal.network.handler.NetworkHandler
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.login.Heartbeat
|
import net.mamoe.mirai.internal.network.protocol.packet.login.Heartbeat
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc
|
import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
|
|
||||||
internal interface HeartbeatProcessor {
|
internal interface HeartbeatProcessor {
|
||||||
/**
|
/**
|
||||||
@ -44,18 +43,18 @@ internal interface HeartbeatProcessor {
|
|||||||
|
|
||||||
internal class HeartbeatProcessorImpl : HeartbeatProcessor {
|
internal class HeartbeatProcessorImpl : HeartbeatProcessor {
|
||||||
override suspend fun doStatHeartbeatNow(networkHandler: NetworkHandler) {
|
override suspend fun doStatHeartbeatNow(networkHandler: NetworkHandler) {
|
||||||
StatSvc.SimpleGet(networkHandler.context.bot.client).sendAndExpect(
|
networkHandler.sendAndExpect(
|
||||||
networkHandler,
|
StatSvc.SimpleGet(networkHandler.context.bot.client),
|
||||||
timeoutMillis = networkHandler.context[SsoProcessorContext].configuration.heartbeatTimeoutMillis,
|
timeout = networkHandler.context[SsoProcessorContext].configuration.heartbeatTimeoutMillis,
|
||||||
retry = 2
|
attempts = 2
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun doAliveHeartbeatNow(networkHandler: NetworkHandler) {
|
override suspend fun doAliveHeartbeatNow(networkHandler: NetworkHandler) {
|
||||||
Heartbeat.Alive(networkHandler.context.bot.client).sendAndExpect(
|
networkHandler.sendAndExpect(
|
||||||
networkHandler,
|
Heartbeat.Alive(networkHandler.context.bot.client),
|
||||||
timeoutMillis = networkHandler.context[SsoProcessorContext].configuration.heartbeatTimeoutMillis,
|
timeout = networkHandler.context[SsoProcessorContext].configuration.heartbeatTimeoutMillis,
|
||||||
retry = 2
|
attempts = 2
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.network.components
|
package net.mamoe.mirai.internal.network.components
|
||||||
@ -13,7 +13,6 @@ import kotlinx.coroutines.*
|
|||||||
import net.mamoe.mirai.internal.network.component.ComponentKey
|
import net.mamoe.mirai.internal.network.component.ComponentKey
|
||||||
import net.mamoe.mirai.internal.network.handler.NetworkHandler
|
import net.mamoe.mirai.internal.network.handler.NetworkHandler
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin15
|
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin15
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.network.LoginFailedException
|
import net.mamoe.mirai.network.LoginFailedException
|
||||||
import net.mamoe.mirai.utils.MiraiLogger
|
import net.mamoe.mirai.utils.MiraiLogger
|
||||||
import net.mamoe.mirai.utils.info
|
import net.mamoe.mirai.utils.info
|
||||||
@ -66,6 +65,6 @@ internal class KeyRefreshProcessorImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun refreshKeysNow(handler: NetworkHandler) {
|
override suspend fun refreshKeysNow(handler: NetworkHandler) {
|
||||||
WtLogin15(handler.context[SsoProcessor].client).sendAndExpect(handler)
|
handler.sendAndExpect(WtLogin15(handler.context[SsoProcessor].client))
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,6 @@ import net.mamoe.mirai.internal.QQAndroidBot
|
|||||||
import net.mamoe.mirai.internal.network.component.ComponentKey
|
import net.mamoe.mirai.internal.network.component.ComponentKey
|
||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgSvc
|
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgSvc
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbGetMsg
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbGetMsg
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.utils.MiraiLogger
|
import net.mamoe.mirai.utils.MiraiLogger
|
||||||
import net.mamoe.mirai.utils.addNameHierarchically
|
import net.mamoe.mirai.utils.addNameHierarchically
|
||||||
import net.mamoe.mirai.utils.childScope
|
import net.mamoe.mirai.utils.childScope
|
||||||
@ -64,7 +63,7 @@ internal class MessageSvcSyncerImpl(
|
|||||||
it.bot == this@MessageSvcSyncerImpl.bot
|
it.bot == this@MessageSvcSyncerImpl.bot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MessageSvcPbGetMsg(bot.client, MsgSvc.SyncFlag.START, null).sendAndExpect(bot)
|
bot.network.sendAndExpect(MessageSvcPbGetMsg(bot.client, MsgSvc.SyncFlag.START, null))
|
||||||
} ?: error("timeout syncing friend message history.")
|
} ?: error("timeout syncing friend message history.")
|
||||||
logger.info { "Syncing friend message history: Success." }
|
logger.info { "Syncing friend message history: Success." }
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin10
|
|||||||
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin2
|
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin2
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin20
|
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin20
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin9
|
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin9
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.network.*
|
import net.mamoe.mirai.network.*
|
||||||
import net.mamoe.mirai.utils.BotConfiguration.MiraiProtocol
|
import net.mamoe.mirai.utils.BotConfiguration.MiraiProtocol
|
||||||
import net.mamoe.mirai.utils.LoginSolver
|
import net.mamoe.mirai.utils.LoginSolver
|
||||||
@ -148,7 +147,9 @@ internal class SsoProcessorImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun registerClientOnline(handler: NetworkHandler): StatSvc.Register.Response {
|
private suspend fun registerClientOnline(handler: NetworkHandler): StatSvc.Register.Response {
|
||||||
return StatSvc.Register.online(client).sendAndExpect(handler).also { registerResp = it }
|
return handler.sendAndExpect(StatSvc.Register.online(client)).also {
|
||||||
|
registerResp = it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun logout(handler: NetworkHandler) {
|
override suspend fun logout(handler: NetworkHandler) {
|
||||||
@ -179,7 +180,8 @@ internal class SsoProcessorImpl(
|
|||||||
protected val bot get() = context.bot
|
protected val bot get() = context.bot
|
||||||
protected val logger get() = bot.logger
|
protected val logger get() = bot.logger
|
||||||
|
|
||||||
protected suspend fun <R : Packet?> OutgoingPacketWithRespType<R>.sendAndExpect(): R = sendAndExpect(handler)
|
protected suspend fun <R : Packet?> OutgoingPacketWithRespType<R>.sendAndExpect(): R =
|
||||||
|
handler.sendAndExpect(this)
|
||||||
|
|
||||||
abstract suspend fun doLogin()
|
abstract suspend fun doLogin()
|
||||||
}
|
}
|
||||||
@ -300,7 +302,7 @@ internal class SsoProcessorImpl(
|
|||||||
|
|
||||||
private inner class FastLoginImpl(handler: NetworkHandler) : LoginStrategy(handler) {
|
private inner class FastLoginImpl(handler: NetworkHandler) : LoginStrategy(handler) {
|
||||||
override suspend fun doLogin() {
|
override suspend fun doLogin() {
|
||||||
val login10 = WtLogin10(client).sendAndExpect(handler)
|
val login10 = handler.sendAndExpect(WtLogin10(client))
|
||||||
check(login10 is LoginPacketResponse.Success) { "Fast login failed: $login10" }
|
check(login10 is LoginPacketResponse.Success) { "Fast login failed: $login10" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,12 @@ internal interface NetworkHandler : CoroutineScope {
|
|||||||
suspend fun resumeConnection()
|
suspend fun resumeConnection()
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <P : Packet?> sendAndExpect(
|
||||||
|
packet: OutgoingPacketWithRespType<P>,
|
||||||
|
timeout: Long = 5000,
|
||||||
|
attempts: Int = 2
|
||||||
|
): P
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends [packet], suspends and expects to receive a response from the server.
|
* Sends [packet], suspends and expects to receive a response from the server.
|
||||||
*
|
*
|
||||||
@ -139,7 +145,8 @@ internal interface NetworkHandler : CoroutineScope {
|
|||||||
*
|
*
|
||||||
* @param attempts ranges `1..INFINITY`
|
* @param attempts ranges `1..INFINITY`
|
||||||
*/
|
*/
|
||||||
suspend fun sendAndExpect(packet: OutgoingPacket, timeout: Long = 5000, attempts: Int = 2): Packet?
|
suspend fun <P : Packet?> sendAndExpect(packet: OutgoingPacket, timeout: Long = 5000, attempts: Int = 2): P
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends [packet] and does not expect any response.
|
* Sends [packet] and does not expect any response.
|
||||||
@ -163,32 +170,6 @@ internal interface NetworkHandler : CoroutineScope {
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// compatibility
|
// compatibility
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
|
||||||
* @suppress This is for compatibility with old code. Use [sendWithoutExpect] without extension receiver instead.
|
|
||||||
*/
|
|
||||||
suspend fun OutgoingPacket.sendWithoutExpect(
|
|
||||||
antiCollisionParam: Any? = null,
|
|
||||||
) = this@NetworkHandler.sendWithoutExpect(this)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @suppress This is for compatibility with old code. Use [sendAndExpect] without extension receiver instead.
|
|
||||||
*/
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
suspend fun <R> OutgoingPacket.sendAndExpect(
|
|
||||||
timeoutMillis: Long = 5000,
|
|
||||||
retry: Int = 2,
|
|
||||||
antiCollisionParam: Any? = null, // signature collision
|
|
||||||
): R = sendAndExpect(this, timeoutMillis, retry) as R
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @suppress This is for compatibility with old code. Use [sendAndExpect] without extension receiver instead.
|
|
||||||
*/
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
suspend fun <R : Packet?> OutgoingPacketWithRespType<R>.sendAndExpect(
|
|
||||||
timeoutMillis: Long = 5000,
|
|
||||||
retry: Int = 2,
|
|
||||||
): R = sendAndExpect(this, timeoutMillis, retry) as R
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val NetworkHandler.logger: MiraiLogger get() = context.logger
|
internal val NetworkHandler.logger: MiraiLogger get() = context.logger
|
||||||
|
@ -21,6 +21,7 @@ import net.mamoe.mirai.internal.network.handler.selector.NetworkHandlerSelector
|
|||||||
import net.mamoe.mirai.internal.network.handler.state.StateObserver
|
import net.mamoe.mirai.internal.network.handler.state.StateObserver
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.IncomingPacket
|
import net.mamoe.mirai.internal.network.protocol.packet.IncomingPacket
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
||||||
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketWithRespType
|
||||||
import net.mamoe.mirai.internal.utils.SingleEntrantLock
|
import net.mamoe.mirai.internal.utils.SingleEntrantLock
|
||||||
import net.mamoe.mirai.internal.utils.fromMiraiLogger
|
import net.mamoe.mirai.internal.utils.fromMiraiLogger
|
||||||
import net.mamoe.mirai.internal.utils.subLogger
|
import net.mamoe.mirai.internal.utils.subLogger
|
||||||
@ -93,7 +94,7 @@ internal abstract class NetworkHandlerSupport(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final override suspend fun sendAndExpect(packet: OutgoingPacket, timeout: Long, attempts: Int): Packet? {
|
final override suspend fun <P : Packet?> sendAndExpect(packet: OutgoingPacket, timeout: Long, attempts: Int): P {
|
||||||
require(attempts >= 1) { "attempts must be at least 1." }
|
require(attempts >= 1) { "attempts must be at least 1." }
|
||||||
val listener = PacketListener(packet.commandName, packet.sequenceId)
|
val listener = PacketListener(packet.commandName, packet.sequenceId)
|
||||||
packetListeners.add(listener)
|
packetListeners.add(listener)
|
||||||
@ -103,9 +104,10 @@ internal abstract class NetworkHandlerSupport(
|
|||||||
context[PacketLoggingStrategy].logSent(logger, packet)
|
context[PacketLoggingStrategy].logSent(logger, packet)
|
||||||
sendPacketImpl(packet)
|
sendPacketImpl(packet)
|
||||||
try {
|
try {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
return withTimeout(timeout) {
|
return withTimeout(timeout) {
|
||||||
listener.result.await()
|
listener.result.await()
|
||||||
}
|
} as P
|
||||||
} catch (e: TimeoutCancellationException) {
|
} catch (e: TimeoutCancellationException) {
|
||||||
collectException(e)
|
collectException(e)
|
||||||
}
|
}
|
||||||
@ -122,6 +124,12 @@ internal abstract class NetworkHandlerSupport(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final override suspend fun <P : Packet?> sendAndExpect(
|
||||||
|
packet: OutgoingPacketWithRespType<P>,
|
||||||
|
timeout: Long,
|
||||||
|
attempts: Int
|
||||||
|
): P = sendAndExpect(packet as OutgoingPacket, timeout, attempts)
|
||||||
|
|
||||||
final override suspend fun sendWithoutExpect(packet: OutgoingPacket) {
|
final override suspend fun sendWithoutExpect(packet: OutgoingPacket) {
|
||||||
context[PacketLoggingStrategy].logSent(logger, packet)
|
context[PacketLoggingStrategy].logSent(logger, packet)
|
||||||
sendPacketImpl(packet)
|
sendPacketImpl(packet)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.network.handler.selector
|
package net.mamoe.mirai.internal.network.handler.selector
|
||||||
@ -13,10 +13,12 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.channels.ReceiveChannel
|
import kotlinx.coroutines.channels.ReceiveChannel
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
|
import net.mamoe.mirai.internal.network.Packet
|
||||||
import net.mamoe.mirai.internal.network.handler.NetworkHandler
|
import net.mamoe.mirai.internal.network.handler.NetworkHandler
|
||||||
import net.mamoe.mirai.internal.network.handler.NetworkHandler.State
|
import net.mamoe.mirai.internal.network.handler.NetworkHandler.State
|
||||||
import net.mamoe.mirai.internal.network.handler.NetworkHandlerContext
|
import net.mamoe.mirai.internal.network.handler.NetworkHandlerContext
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
||||||
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketWithRespType
|
||||||
import net.mamoe.mirai.utils.addNameHierarchically
|
import net.mamoe.mirai.utils.addNameHierarchically
|
||||||
import net.mamoe.mirai.utils.childScope
|
import net.mamoe.mirai.utils.childScope
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
@ -70,9 +72,15 @@ internal open class SelectorNetworkHandler<out H : NetworkHandler>(
|
|||||||
instance() // the selector will resume connection for us.
|
instance() // the selector will resume connection for us.
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun sendAndExpect(packet: OutgoingPacket, timeout: Long, attempts: Int) =
|
override suspend fun <P : Packet?> sendAndExpect(packet: OutgoingPacket, timeout: Long, attempts: Int): P =
|
||||||
instance().sendAndExpect(packet, timeout, attempts)
|
instance().sendAndExpect(packet, timeout, attempts)
|
||||||
|
|
||||||
|
override suspend fun <P : Packet?> sendAndExpect(
|
||||||
|
packet: OutgoingPacketWithRespType<P>,
|
||||||
|
timeout: Long,
|
||||||
|
attempts: Int
|
||||||
|
): P = instance().sendAndExpect(packet, timeout, attempts)
|
||||||
|
|
||||||
override suspend fun sendWithoutExpect(packet: OutgoingPacket) = instance().sendWithoutExpect(packet)
|
override suspend fun sendWithoutExpect(packet: OutgoingPacket) = instance().sendWithoutExpect(packet)
|
||||||
override fun close(cause: Throwable?) {
|
override fun close(cause: Throwable?) {
|
||||||
if (cause is NetworkException && cause.recoverable) {
|
if (cause is NetworkException && cause.recoverable) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.network.notice
|
package net.mamoe.mirai.internal.network.notice
|
||||||
@ -25,7 +25,6 @@ import net.mamoe.mirai.internal.getGroupByUin
|
|||||||
import net.mamoe.mirai.internal.network.protocol.data.jce.StTroopNum
|
import net.mamoe.mirai.internal.network.protocol.data.jce.StTroopNum
|
||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm
|
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
|
|
||||||
internal interface NewContactSupport { // can be a marker interface when context receivers are available.
|
internal interface NewContactSupport { // can be a marker interface when context receivers are available.
|
||||||
|
|
||||||
@ -89,9 +88,10 @@ internal interface NewContactSupport { // can be a marker interface when context
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun QQAndroidBot.getNewGroup(groupCode: Long): GroupImpl? {
|
private suspend fun QQAndroidBot.getNewGroup(groupCode: Long): GroupImpl? {
|
||||||
val troopNum = FriendList.GetTroopListSimplify(client)
|
val troopNum = network.sendAndExpect(
|
||||||
.sendAndExpect(network, timeoutMillis = 10_000, retry = 5)
|
FriendList.GetTroopListSimplify(client),
|
||||||
.groups.firstOrNull { it.groupCode == groupCode } ?: return null
|
timeout = 10_000, attempts = 5
|
||||||
|
).groups.firstOrNull { it.groupCode == groupCode } ?: return null
|
||||||
|
|
||||||
return getNewGroup(troopNum)
|
return getNewGroup(troopNum)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.network.notice
|
package net.mamoe.mirai.internal.network.notice
|
||||||
@ -106,14 +106,10 @@ internal class UnconsumedNoticesAlerter(
|
|||||||
// 前 4 byte 是群号
|
// 前 4 byte 是群号
|
||||||
}
|
}
|
||||||
84, 87 -> { // 请求入群验证 和 被邀请入群
|
84, 87 -> { // 请求入群验证 和 被邀请入群
|
||||||
bot.network.run {
|
bot.network.sendWithoutExpect(NewContact.SystemMsgNewGroup(bot.client))
|
||||||
NewContact.SystemMsgNewGroup(bot.client).sendWithoutExpect()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
187 -> { // 请求加好友验证
|
187 -> { // 请求加好友验证
|
||||||
bot.network.run {
|
bot.network.sendWithoutExpect(NewContact.SystemMsgNewFriend(bot.client))
|
||||||
NewContact.SystemMsgNewFriend(bot.client).sendWithoutExpect()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
logger.debug { "unknown PbGetMsg type ${data.msgHead.msgType}, data=${data.msgBody.msgContent.toUHexString()}" }
|
logger.debug { "unknown PbGetMsg type ${data.msgHead.msgType}, data=${data.msgBody.msgContent.toUHexString()}" }
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.network.notice.priv
|
package net.mamoe.mirai.internal.network.notice.priv
|
||||||
@ -35,7 +35,6 @@ import net.mamoe.mirai.internal.network.protocol.data.proto.Submsgtype0x44.Subms
|
|||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.Submsgtype0xb3.SubMsgType0xb3
|
import net.mamoe.mirai.internal.network.protocol.data.proto.Submsgtype0xb3.SubMsgType0xb3
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.NewContact
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.NewContact
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList.GetFriendGroupList
|
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList.GetFriendGroupList
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.internal.utils.io.ProtoBuf
|
import net.mamoe.mirai.internal.utils.io.ProtoBuf
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.loadAs
|
import net.mamoe.mirai.internal.utils.io.serialization.loadAs
|
||||||
import net.mamoe.mirai.internal.utils.structureToString
|
import net.mamoe.mirai.internal.utils.structureToString
|
||||||
@ -92,9 +91,7 @@ internal class FriendNoticeProcessor(
|
|||||||
val nick = fromNick.ifEmpty { authNick }.ifEmpty { pbNick }
|
val nick = fromNick.ifEmpty { authNick }.ifEmpty { pbNick }
|
||||||
collect(StrangerAddEvent(bot.addNewStranger(StrangerInfoImpl(id, nick, fromGroup)) ?: return))
|
collect(StrangerAddEvent(bot.addNewStranger(StrangerInfoImpl(id, nick, fromGroup)) ?: return))
|
||||||
//同时需要请求好友验证消息(有新请求需要同意)
|
//同时需要请求好友验证消息(有新请求需要同意)
|
||||||
bot.network.run {
|
bot.network.sendWithoutExpect(NewContact.SystemMsgNewFriend(bot.client))
|
||||||
NewContact.SystemMsgNewFriend(bot.client).sendWithoutExpect()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -252,7 +249,8 @@ internal class FriendNoticeProcessor(
|
|||||||
3, 9, 10 -> {
|
3, 9, 10 -> {
|
||||||
if (bot.getFriend(fuin) != null) return
|
if (bot.getFriend(fuin) != null) return
|
||||||
|
|
||||||
val response = GetFriendGroupList.forSingleFriend(bot.client, fuin).sendAndExpect(bot)
|
|
||||||
|
val response = bot.network.sendAndExpect(GetFriendGroupList.forSingleFriend(bot.client, fuin))
|
||||||
val info = response.friendList.firstOrNull() ?: return
|
val info = response.friendList.firstOrNull() ?: return
|
||||||
collect(
|
collect(
|
||||||
FriendAddEvent(bot.addNewFriendAndRemoveStranger(info.toMiraiFriendInfo()) ?: return),
|
FriendAddEvent(bot.addNewFriendAndRemoveStranger(info.toMiraiFriendInfo()) ?: return),
|
||||||
@ -274,7 +272,7 @@ internal class FriendNoticeProcessor(
|
|||||||
val added = bot.addNewFriendAndRemoveStranger(info) ?: return
|
val added = bot.addNewFriendAndRemoveStranger(info) ?: return
|
||||||
collect(FriendAddEvent(added))
|
collect(FriendAddEvent(added))
|
||||||
if (removed != null) collect(StrangerRelationChangeEvent.Friended(removed, added))
|
if (removed != null) collect(StrangerRelationChangeEvent.Friended(removed, added))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun NoticePipelineContext.handlePrivateNudge(body: Submsgtype0x122.Submsgtype0x122.MsgBody) {
|
private fun NoticePipelineContext.handlePrivateNudge(body: Submsgtype0x122.Submsgtype0x122.MsgBody) {
|
||||||
val action = body.msgTemplParam["action_str"].orEmpty()
|
val action = body.msgTemplParam["action_str"].orEmpty()
|
||||||
|
@ -11,12 +11,10 @@ package net.mamoe.mirai.internal.network.protocol.packet
|
|||||||
|
|
||||||
|
|
||||||
import kotlinx.io.core.*
|
import kotlinx.io.core.*
|
||||||
import net.mamoe.mirai.internal.QQAndroidBot
|
|
||||||
import net.mamoe.mirai.internal.network.Packet
|
import net.mamoe.mirai.internal.network.Packet
|
||||||
import net.mamoe.mirai.internal.network.QQAndroidClient
|
import net.mamoe.mirai.internal.network.QQAndroidClient
|
||||||
import net.mamoe.mirai.internal.network.appClientVersion
|
import net.mamoe.mirai.internal.network.appClientVersion
|
||||||
import net.mamoe.mirai.internal.network.components.EcdhInitialPublicKeyUpdater
|
import net.mamoe.mirai.internal.network.components.EcdhInitialPublicKeyUpdater
|
||||||
import net.mamoe.mirai.internal.network.handler.NetworkHandler
|
|
||||||
import net.mamoe.mirai.internal.utils.io.encryptAndWrite
|
import net.mamoe.mirai.internal.utils.io.encryptAndWrite
|
||||||
import net.mamoe.mirai.internal.utils.io.writeHex
|
import net.mamoe.mirai.internal.utils.io.writeHex
|
||||||
import net.mamoe.mirai.internal.utils.io.writeIntLVPacket
|
import net.mamoe.mirai.internal.utils.io.writeIntLVPacket
|
||||||
@ -76,36 +74,6 @@ internal class IncomingPacket private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
internal suspend inline fun <E : Packet> OutgoingPacketWithRespType<E>.sendAndExpect(
|
|
||||||
network: NetworkHandler,
|
|
||||||
timeoutMillis: Long = 5000,
|
|
||||||
retry: Int = 2
|
|
||||||
): E = network.sendAndExpect(this, timeoutMillis, retry) as E
|
|
||||||
|
|
||||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "UNCHECKED_CAST")
|
|
||||||
@kotlin.internal.LowPriorityInOverloadResolution
|
|
||||||
internal suspend inline fun <E : Packet> OutgoingPacket.sendAndExpect(
|
|
||||||
network: NetworkHandler,
|
|
||||||
timeoutMillis: Long = 5000,
|
|
||||||
retry: Int = 2
|
|
||||||
): E = network.sendAndExpect(this, timeoutMillis, retry) as E
|
|
||||||
|
|
||||||
internal suspend inline fun <E : Packet> OutgoingPacketWithRespType<E>.sendAndExpect(
|
|
||||||
bot: QQAndroidBot,
|
|
||||||
timeoutMillis: Long = 5000,
|
|
||||||
retry: Int = 2
|
|
||||||
): E = (this@sendAndExpect as OutgoingPacket).sendAndExpect(bot.network, timeoutMillis, retry)
|
|
||||||
|
|
||||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "UNCHECKED_CAST")
|
|
||||||
@kotlin.internal.LowPriorityInOverloadResolution
|
|
||||||
internal suspend inline fun <E : Packet> OutgoingPacket.sendAndExpect(
|
|
||||||
bot: QQAndroidBot,
|
|
||||||
timeoutMillis: Long = 5000,
|
|
||||||
retry: Int = 2
|
|
||||||
): E = bot.network.sendAndExpect(this, timeoutMillis, retry) as E
|
|
||||||
|
|
||||||
|
|
||||||
@Suppress("DuplicatedCode")
|
@Suppress("DuplicatedCode")
|
||||||
internal inline fun <R : Packet?> OutgoingPacketFactory<R>.buildOutgoingUniPacket(
|
internal inline fun <R : Packet?> OutgoingPacketFactory<R>.buildOutgoingUniPacket(
|
||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.network.protocol.packet.chat
|
package net.mamoe.mirai.internal.network.protocol.packet.chat
|
||||||
@ -16,7 +16,6 @@ import net.mamoe.mirai.internal.network.Packet
|
|||||||
import net.mamoe.mirai.internal.network.QQAndroidClient
|
import net.mamoe.mirai.internal.network.QQAndroidClient
|
||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0xed3
|
import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0xed3
|
||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.OidbSso
|
import net.mamoe.mirai.internal.network.protocol.data.proto.OidbSso
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket
|
import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.loadAs
|
import net.mamoe.mirai.internal.utils.io.serialization.loadAs
|
||||||
@ -38,7 +37,7 @@ internal object NudgePacket : OutgoingPacketFactory<NudgePacket.Response>("OidbS
|
|||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
nudgeTargetId: Long,
|
nudgeTargetId: Long,
|
||||||
messageReceiverUin: Long,
|
messageReceiverUin: Long,
|
||||||
): OutgoingPacket = buildOutgoingUniPacket(client) {
|
) = buildOutgoingUniPacket(client) {
|
||||||
writeProtoBuf(
|
writeProtoBuf(
|
||||||
OidbSso.OIDBSSOPkg.serializer(),
|
OidbSso.OIDBSSOPkg.serializer(),
|
||||||
OidbSso.OIDBSSOPkg(
|
OidbSso.OIDBSSOPkg(
|
||||||
@ -57,7 +56,7 @@ internal object NudgePacket : OutgoingPacketFactory<NudgePacket.Response>("OidbS
|
|||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
messageReceiverGroupCode: Long,
|
messageReceiverGroupCode: Long,
|
||||||
nudgeTargetId: Long,
|
nudgeTargetId: Long,
|
||||||
): OutgoingPacket = buildOutgoingUniPacket(client) {
|
) = buildOutgoingUniPacket(client) {
|
||||||
writeProtoBuf(
|
writeProtoBuf(
|
||||||
OidbSso.OIDBSSOPkg.serializer(),
|
OidbSso.OIDBSSOPkg.serializer(),
|
||||||
OidbSso.OIDBSSOPkg(
|
OidbSso.OIDBSSOPkg(
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.network.protocol.packet.chat
|
package net.mamoe.mirai.internal.network.protocol.packet.chat
|
||||||
@ -24,6 +24,7 @@ import net.mamoe.mirai.internal.network.protocol.data.jce.stUinInfo
|
|||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.*
|
import net.mamoe.mirai.internal.network.protocol.data.proto.*
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory
|
||||||
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketWithRespType
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket
|
import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket
|
||||||
import net.mamoe.mirai.internal.network.subAppId
|
import net.mamoe.mirai.internal.network.subAppId
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.*
|
import net.mamoe.mirai.internal.utils.io.serialization.*
|
||||||
@ -41,7 +42,7 @@ internal class TroopManagement {
|
|||||||
groupCode: Long,
|
groupCode: Long,
|
||||||
memberUin: Long,
|
memberUin: Long,
|
||||||
timeInSecond: Int
|
timeInSecond: Int
|
||||||
): OutgoingPacket {
|
): OutgoingPacketWithRespType<Response> {
|
||||||
require(timeInSecond in 0..30.daysToSeconds)
|
require(timeInSecond in 0..30.daysToSeconds)
|
||||||
return buildOutgoingUniPacket(client) {
|
return buildOutgoingUniPacket(client) {
|
||||||
writeProtoBuf(
|
writeProtoBuf(
|
||||||
@ -73,7 +74,7 @@ internal class TroopManagement {
|
|||||||
operator fun invoke(
|
operator fun invoke(
|
||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
groupCode: Long
|
groupCode: Long
|
||||||
): OutgoingPacket {
|
): OutgoingPacketWithRespType<GroupInfoImpl> {
|
||||||
return buildOutgoingUniPacket(client) {
|
return buildOutgoingUniPacket(client) {
|
||||||
writeProtoBuf(
|
writeProtoBuf(
|
||||||
OidbSso.OIDBSSOPkg.serializer(),
|
OidbSso.OIDBSSOPkg.serializer(),
|
||||||
@ -382,7 +383,7 @@ internal class TroopManagement {
|
|||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
member: Member,
|
member: Member,
|
||||||
newName: String
|
newName: String
|
||||||
): OutgoingPacket {
|
): OutgoingPacketWithRespType<Response> {
|
||||||
return buildOutgoingUniPacket(client) {
|
return buildOutgoingUniPacket(client) {
|
||||||
writeJceStruct(
|
writeJceStruct(
|
||||||
RequestPacket.serializer(),
|
RequestPacket.serializer(),
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.network.protocol.packet.chat.image
|
package net.mamoe.mirai.internal.network.protocol.packet.chat.image
|
||||||
@ -14,7 +14,6 @@ import net.mamoe.mirai.internal.QQAndroidBot
|
|||||||
import net.mamoe.mirai.internal.network.Packet
|
import net.mamoe.mirai.internal.network.Packet
|
||||||
import net.mamoe.mirai.internal.network.QQAndroidClient
|
import net.mamoe.mirai.internal.network.QQAndroidClient
|
||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0x352
|
import net.mamoe.mirai.internal.network.protocol.data.proto.Cmd0x352
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory
|
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket
|
import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.readProtoBuf
|
import net.mamoe.mirai.internal.utils.io.serialization.readProtoBuf
|
||||||
@ -24,8 +23,8 @@ internal class LongConn {
|
|||||||
|
|
||||||
internal object OffPicUp : OutgoingPacketFactory<OffPicUp.Response>("LongConn.OffPicUp") {
|
internal object OffPicUp : OutgoingPacketFactory<OffPicUp.Response>("LongConn.OffPicUp") {
|
||||||
|
|
||||||
operator fun invoke(client: QQAndroidClient, req: Cmd0x352.TryUpImgReq): OutgoingPacket {
|
operator fun invoke(client: QQAndroidClient, req: Cmd0x352.TryUpImgReq) =
|
||||||
return buildOutgoingUniPacket(client) {
|
buildOutgoingUniPacket(client) {
|
||||||
writeProtoBuf(
|
writeProtoBuf(
|
||||||
Cmd0x352.ReqBody.serializer(),
|
Cmd0x352.ReqBody.serializer(),
|
||||||
Cmd0x352.ReqBody(
|
Cmd0x352.ReqBody(
|
||||||
@ -37,7 +36,6 @@ internal class LongConn {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//08 01 12 7D 08 00 10 AB E1 9D DF 07 18 00 28 01 32 1C 0A 10 8E C4 9D 72 26 AE 20 C0 5D A2 B6 78 4D 12 B7 3A 10 E9 07 18 86 1F 20 30 28 30 52 25 2F 61 30 30 39 32 64 61 39 2D 64 39 31 38 2D 34 38 31 62 2D 38 34 30 63 2D 33 32 33 64 64 33 39 33 34 35 37 63 5A 25 2F 61 30 30 39 32 64 61 39 2D 64 39 31 38 2D 34 38 31 62 2D 38 34 30 63 2D 33 32 33 64 64 33 39 33 34 35 37 63 60 00 68 80 40 20 01
|
//08 01 12 7D 08 00 10 AB E1 9D DF 07 18 00 28 01 32 1C 0A 10 8E C4 9D 72 26 AE 20 C0 5D A2 B6 78 4D 12 B7 3A 10 E9 07 18 86 1F 20 30 28 30 52 25 2F 61 30 30 39 32 64 61 39 2D 64 39 31 38 2D 34 38 31 62 2D 38 34 30 63 2D 33 32 33 64 64 33 39 33 34 35 37 63 5A 25 2F 61 30 30 39 32 64 61 39 2D 64 39 31 38 2D 34 38 31 62 2D 38 34 30 63 2D 33 32 33 64 64 33 39 33 34 35 37 63 60 00 68 80 40 20 01
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
@ -31,21 +31,21 @@ internal object MessageSvcPbDeleteMsg : OutgoingPacketFactory<Nothing?>("Message
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal suspend fun delete(bot: QQAndroidBot, messages: List<MsgComm.Msg>) =
|
internal suspend fun delete(bot: QQAndroidBot, messages: List<MsgComm.Msg>) {
|
||||||
bot.network.run {
|
val map = messages.map {
|
||||||
val map = messages.map {
|
MsgSvc.PbDeleteMsgReq.MsgItem(
|
||||||
MsgSvc.PbDeleteMsgReq.MsgItem(
|
fromUin = it.msgHead.fromUin,
|
||||||
fromUin = it.msgHead.fromUin,
|
toUin = it.msgHead.toUin,
|
||||||
toUin = it.msgHead.toUin,
|
// 群为84、好友为187。群通过其他方法删除,但测试结果显示通过187也能删除群消息。
|
||||||
// 群为84、好友为187。群通过其他方法删除,但测试结果显示通过187也能删除群消息。
|
msgType = 187,
|
||||||
msgType = 187,
|
msgSeq = it.msgHead.msgSeq,
|
||||||
msgSeq = it.msgHead.msgSeq,
|
msgUid = it.msgHead.msgUid,
|
||||||
msgUid = it.msgHead.msgUid,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageSvcPbDeleteMsg(bot.client, map).sendWithoutExpect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bot.network.sendWithoutExpect(MessageSvcPbDeleteMsg(bot.client, map))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot) = null
|
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot) = null
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
@ -113,9 +113,7 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
|
|||||||
// .warning { "MessageSvcPushNotify: result != 0, result = ${resp.result}, errorMsg=${resp.errmsg}" }
|
// .warning { "MessageSvcPushNotify: result != 0, result = ${resp.result}, errorMsg=${resp.errmsg}" }
|
||||||
bot.network.launch(CoroutineName("MessageSvcPushNotify.retry")) {
|
bot.network.launch(CoroutineName("MessageSvcPushNotify.retry")) {
|
||||||
delay(500 + Random.nextLong(0, 1000))
|
delay(500 + Random.nextLong(0, 1000))
|
||||||
bot.network.run {
|
bot.network.sendWithoutExpect(MessageSvcPbGetMsg(bot.client, syncCookie = null))
|
||||||
MessageSvcPbGetMsg(bot.client, syncCookie = null).sendWithoutExpect()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return EmptyResponse(bot)
|
return EmptyResponse(bot)
|
||||||
}
|
}
|
||||||
@ -170,24 +168,24 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
MsgSvc.SyncFlag.START -> {
|
MsgSvc.SyncFlag.START -> {
|
||||||
network.run {
|
network.sendAndExpect(
|
||||||
MessageSvcPbGetMsg(
|
MessageSvcPbGetMsg(
|
||||||
client,
|
client,
|
||||||
MsgSvc.SyncFlag.CONTINUE,
|
MsgSvc.SyncFlag.CONTINUE,
|
||||||
bot.syncController.syncCookie,
|
bot.syncController.syncCookie,
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
MsgSvc.SyncFlag.CONTINUE -> {
|
MsgSvc.SyncFlag.CONTINUE -> {
|
||||||
network.run {
|
network.sendAndExpect(
|
||||||
MessageSvcPbGetMsg(
|
MessageSvcPbGetMsg(
|
||||||
client,
|
client,
|
||||||
MsgSvc.SyncFlag.CONTINUE,
|
MsgSvc.SyncFlag.CONTINUE,
|
||||||
bot.syncController.syncCookie,
|
bot.syncController.syncCookie,
|
||||||
).sendAndExpect()
|
), 5000, 2
|
||||||
}
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.internal.network.protocol.packet.chat.receive
|
package net.mamoe.mirai.internal.network.protocol.packet.chat.receive
|
||||||
@ -17,13 +17,12 @@ import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
|||||||
import net.mamoe.mirai.internal.network.protocol.packet.buildResponseUniPacket
|
import net.mamoe.mirai.internal.network.protocol.packet.buildResponseUniPacket
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc
|
import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin10
|
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin10
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
|
|
||||||
internal object OnlinePushSidExpired : IncomingPacketFactory<Packet?>("OnlinePush.SidTicketExpired") {
|
internal object OnlinePushSidExpired : IncomingPacketFactory<Packet?>("OnlinePush.SidTicketExpired") {
|
||||||
|
|
||||||
override suspend fun QQAndroidBot.handle(packet: Packet?, sequenceId: Int): OutgoingPacket {
|
override suspend fun QQAndroidBot.handle(packet: Packet?, sequenceId: Int): OutgoingPacket {
|
||||||
WtLogin10(client, mainSigMap = 3554528).sendAndExpect(bot)
|
bot.network.sendAndExpect(WtLogin10(client, mainSigMap = 3554528))
|
||||||
StatSvc.Register.online(client).sendAndExpect(bot)
|
bot.network.sendAndExpect(StatSvc.Register.online(client))
|
||||||
return buildResponseUniPacket(client, sequenceId = sequenceId)
|
return buildResponseUniPacket(client, sequenceId = sequenceId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import net.mamoe.mirai.internal.message.FriendImage
|
|||||||
import net.mamoe.mirai.internal.message.OfflineGroupImage
|
import net.mamoe.mirai.internal.message.OfflineGroupImage
|
||||||
import net.mamoe.mirai.internal.network.component.ComponentKey
|
import net.mamoe.mirai.internal.network.component.ComponentKey
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.ImgStore
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.image.ImgStore
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.utils.ResourceAccessLock
|
import net.mamoe.mirai.utils.ResourceAccessLock
|
||||||
import net.mamoe.mirai.utils.UnsafeMutableNonNullProperty
|
import net.mamoe.mirai.utils.UnsafeMutableNonNullProperty
|
||||||
import net.mamoe.mirai.utils.currentTimeMillis
|
import net.mamoe.mirai.utils.currentTimeMillis
|
||||||
@ -117,13 +116,15 @@ internal open class ImagePatcher {
|
|||||||
|
|
||||||
val bot = group.bot
|
val bot = group.bot
|
||||||
|
|
||||||
val response: ImgStore.GroupPicUp.Response = ImgStore.GroupPicUp(
|
val response: ImgStore.GroupPicUp.Response = bot.network.sendAndExpect(
|
||||||
bot.client,
|
ImgStore.GroupPicUp(
|
||||||
uin = bot.id,
|
bot.client,
|
||||||
groupCode = group.id,
|
uin = bot.id,
|
||||||
md5 = image.md5,
|
groupCode = group.id,
|
||||||
size = 1,
|
md5 = image.md5,
|
||||||
).sendAndExpect(bot)
|
size = 1,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
when (response) {
|
when (response) {
|
||||||
is ImgStore.GroupPicUp.Response.Failed -> {
|
is ImgStore.GroupPicUp.Response.Failed -> {
|
||||||
@ -154,13 +155,15 @@ internal open class ImagePatcher {
|
|||||||
|
|
||||||
val bot = group.bot
|
val bot = group.bot
|
||||||
|
|
||||||
val response = ImgStore.GroupPicUp(
|
val response = bot.network.sendAndExpect(
|
||||||
bot.client,
|
ImgStore.GroupPicUp(
|
||||||
uin = bot.id,
|
bot.client,
|
||||||
groupCode = group.id,
|
uin = bot.id,
|
||||||
md5 = image.md5,
|
groupCode = group.id,
|
||||||
size = image.size
|
md5 = image.md5,
|
||||||
).sendAndExpect(bot.network)
|
size = image.size
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return OfflineGroupImage(
|
return OfflineGroupImage(
|
||||||
imageId = image.imageId,
|
imageId = image.imageId,
|
||||||
|
@ -26,7 +26,6 @@ import net.mamoe.mirai.internal.network.protocol
|
|||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.*
|
import net.mamoe.mirai.internal.network.protocol.data.proto.*
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.FileManagement
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult
|
||||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.toByteArray
|
import net.mamoe.mirai.internal.utils.io.serialization.toByteArray
|
||||||
import net.mamoe.mirai.message.MessageReceipt
|
import net.mamoe.mirai.message.MessageReceipt
|
||||||
import net.mamoe.mirai.message.data.FileMessage
|
import net.mamoe.mirai.message.data.FileMessage
|
||||||
@ -222,12 +221,14 @@ internal class RemoteFileImpl(
|
|||||||
return flow {
|
return flow {
|
||||||
var index = 0
|
var index = 0
|
||||||
while (true) {
|
while (true) {
|
||||||
val list = FileManagement.GetFileList(
|
val list = bot.network.sendAndExpect(
|
||||||
client,
|
FileManagement.GetFileList(
|
||||||
groupCode = contact.id,
|
client,
|
||||||
folderId = info.id,
|
groupCode = contact.id,
|
||||||
startIndex = index
|
folderId = info.id,
|
||||||
).sendAndExpect(bot).toResult("RemoteFile.listFiles").getOrThrow()
|
startIndex = index
|
||||||
|
)
|
||||||
|
).toResult("RemoteFile.listFiles").getOrThrow()
|
||||||
index += list.itemList.size
|
index += list.itemList.size
|
||||||
|
|
||||||
if (list.int32RetCode != 0) return@flow
|
if (list.int32RetCode != 0) return@flow
|
||||||
@ -275,12 +276,14 @@ internal class RemoteFileImpl(
|
|||||||
private var ended = false
|
private var ended = false
|
||||||
|
|
||||||
private suspend fun updateItems() {
|
private suspend fun updateItems() {
|
||||||
val list = FileManagement.GetFileList(
|
val list = bot.network.sendAndExpect(
|
||||||
client,
|
FileManagement.GetFileList(
|
||||||
groupCode = contact.id,
|
client,
|
||||||
folderId = path,
|
groupCode = contact.id,
|
||||||
startIndex = index
|
folderId = path,
|
||||||
).sendAndExpect(bot).toResult("RemoteFile.listFiles").getOrThrow()
|
startIndex = index
|
||||||
|
)
|
||||||
|
).toResult("RemoteFile.listFiles").getOrThrow()
|
||||||
if (list.int32RetCode != 0 || list.itemList.isEmpty()) {
|
if (list.int32RetCode != 0 || list.itemList.isEmpty()) {
|
||||||
ended = true
|
ended = true
|
||||||
return
|
return
|
||||||
@ -356,13 +359,15 @@ internal class RemoteFileImpl(
|
|||||||
if (!info.isOperable()) return false
|
if (!info.isOperable()) return false
|
||||||
return when {
|
return when {
|
||||||
info.isFile -> {
|
info.isFile -> {
|
||||||
FileManagement.DeleteFile(
|
bot.network.sendAndExpect(
|
||||||
client,
|
FileManagement.DeleteFile(
|
||||||
groupCode = contact.id,
|
client,
|
||||||
busId = info.busId,
|
groupCode = contact.id,
|
||||||
fileId = info.id,
|
busId = info.busId,
|
||||||
parentFolderId = info.parentFolderId,
|
fileId = info.id,
|
||||||
).sendAndExpect(bot).toResult("RemoteFile.delete", checkResp = false).getOrThrow().int32RetCode == 0
|
parentFolderId = info.parentFolderId,
|
||||||
|
)
|
||||||
|
).toResult("RemoteFile.delete", checkResp = false).getOrThrow().int32RetCode == 0
|
||||||
}
|
}
|
||||||
// recursively -> {
|
// recursively -> {
|
||||||
// this.listFiles().collect { child ->
|
// this.listFiles().collect { child ->
|
||||||
@ -372,9 +377,11 @@ internal class RemoteFileImpl(
|
|||||||
// }
|
// }
|
||||||
else -> {
|
else -> {
|
||||||
// natively 'recursive'
|
// natively 'recursive'
|
||||||
FileManagement.DeleteFolder(
|
bot.network.sendAndExpect(
|
||||||
client, contact.id, info.id
|
FileManagement.DeleteFolder(
|
||||||
).sendAndExpect(bot).toResult("RemoteFile.delete").getOrThrow().int32RetCode == 0
|
client, contact.id, info.id
|
||||||
|
)
|
||||||
|
).toResult("RemoteFile.delete").getOrThrow().int32RetCode == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,11 +394,13 @@ internal class RemoteFileImpl(
|
|||||||
|
|
||||||
val info = getFileFolderInfo() ?: return false
|
val info = getFileFolderInfo() ?: return false
|
||||||
if (!info.isOperable()) return false
|
if (!info.isOperable()) return false
|
||||||
return if (info.isFile) {
|
return bot.network.sendAndExpect(
|
||||||
FileManagement.RenameFile(client, contact.id, info.busId, info.id, info.parentFolderId, normalized)
|
if (info.isFile) {
|
||||||
} else {
|
FileManagement.RenameFile(client, contact.id, info.busId, info.id, info.parentFolderId, normalized)
|
||||||
FileManagement.RenameFolder(client, contact.id, info.id, normalized)
|
} else {
|
||||||
}.sendAndExpect(bot).toResult("RemoteFile.renameTo", checkResp = false).getOrThrow().int32RetCode == 0
|
FileManagement.RenameFolder(client, contact.id, info.id, normalized)
|
||||||
|
}
|
||||||
|
).toResult("RemoteFile.renameTo", checkResp = false).getOrThrow().int32RetCode == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -424,10 +433,18 @@ internal class RemoteFileImpl(
|
|||||||
if (!info.isOperable()) return false
|
if (!info.isOperable()) return false
|
||||||
return if (info.isFile) {
|
return if (info.isFile) {
|
||||||
val newParentId = target.parent?.checkIsImpl()?.getIdSmart() ?: return false
|
val newParentId = target.parent?.checkIsImpl()?.getIdSmart() ?: return false
|
||||||
FileManagement.MoveFile(client, contact.id, info.busId, info.id, info.parentFolderId, newParentId)
|
bot.network.sendAndExpect(
|
||||||
.sendAndExpect(bot).toResult("RemoteFile.moveTo", checkResp = false).getOrThrow().int32RetCode == 0
|
FileManagement.MoveFile(
|
||||||
|
client,
|
||||||
|
contact.id,
|
||||||
|
info.busId,
|
||||||
|
info.id,
|
||||||
|
info.parentFolderId,
|
||||||
|
newParentId
|
||||||
|
)
|
||||||
|
).toResult("RemoteFile.moveTo", checkResp = false).getOrThrow().int32RetCode == 0
|
||||||
} else {
|
} else {
|
||||||
return FileManagement.RenameFolder(client, contact.id, info.id, target.name).sendAndExpect(bot)
|
return bot.network.sendAndExpect(FileManagement.RenameFolder(client, contact.id, info.id, target.name))
|
||||||
.toResult("RemoteFile.moveTo", checkResp = false).getOrThrow().int32RetCode == 0
|
.toResult("RemoteFile.moveTo", checkResp = false).getOrThrow().int32RetCode == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,8 +456,8 @@ internal class RemoteFileImpl(
|
|||||||
|
|
||||||
val parentFolderId: String = parent?.getIdSmart() ?: return false
|
val parentFolderId: String = parent?.getIdSmart() ?: return false
|
||||||
|
|
||||||
return FileManagement.CreateFolder(client, contact.id, parentFolderId, this.name)
|
return bot.network.sendAndExpect(FileManagement.CreateFolder(client, contact.id, parentFolderId, this.name))
|
||||||
.sendAndExpect(bot).toResult("RemoteFile.mkdir", checkResp = false).getOrThrow().int32RetCode == 0
|
.toResult("RemoteFile.mkdir", checkResp = false).getOrThrow().int32RetCode == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun upload0(
|
private suspend fun upload0(
|
||||||
@ -449,13 +466,15 @@ internal class RemoteFileImpl(
|
|||||||
): Oidb0x6d6.UploadFileRspBody? = resource.withAutoClose {
|
): Oidb0x6d6.UploadFileRspBody? = resource.withAutoClose {
|
||||||
val parent = parent ?: return null
|
val parent = parent ?: return null
|
||||||
val parentInfo = parent.getFileFolderInfo() ?: return null
|
val parentInfo = parent.getFileFolderInfo() ?: return null
|
||||||
val resp = FileManagement.RequestUpload(
|
val resp = bot.network.sendAndExpect(
|
||||||
client,
|
FileManagement.RequestUpload(
|
||||||
groupCode = contact.id,
|
client,
|
||||||
folderId = parentInfo.id,
|
groupCode = contact.id,
|
||||||
resource = resource,
|
folderId = parentInfo.id,
|
||||||
filename = this.name
|
resource = resource,
|
||||||
).sendAndExpect(bot).toResult("RemoteFile.upload").getOrThrow()
|
filename = this.name
|
||||||
|
)
|
||||||
|
).toResult("RemoteFile.upload").getOrThrow()
|
||||||
if (resp.boolFileExist) {
|
if (resp.boolFileExist) {
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
@ -585,12 +604,14 @@ internal class RemoteFileImpl(
|
|||||||
override suspend fun getDownloadInfo(): RemoteFile.DownloadInfo? {
|
override suspend fun getDownloadInfo(): RemoteFile.DownloadInfo? {
|
||||||
val info = getFileFolderInfo() ?: return null
|
val info = getFileFolderInfo() ?: return null
|
||||||
if (!info.isFile) return null
|
if (!info.isFile) return null
|
||||||
val resp = FileManagement.RequestDownload(
|
val resp = bot.network.sendAndExpect(
|
||||||
client,
|
FileManagement.RequestDownload(
|
||||||
groupCode = contact.id,
|
client,
|
||||||
busId = info.busId,
|
groupCode = contact.id,
|
||||||
fileId = info.id
|
busId = info.busId,
|
||||||
).sendAndExpect(bot).toResult("RemoteFile.getDownloadInfo").getOrThrow()
|
fileId = info.id
|
||||||
|
)
|
||||||
|
).toResult("RemoteFile.getDownloadInfo").getOrThrow()
|
||||||
|
|
||||||
return RemoteFile.DownloadInfo(
|
return RemoteFile.DownloadInfo(
|
||||||
filename = name,
|
filename = name,
|
||||||
|
Loading…
Reference in New Issue
Block a user