Fix botMuteTimeRemaining updating

This commit is contained in:
Him188 2020-02-20 22:20:16 +08:00
parent 97615e5d7e
commit 68140a14ff

View File

@ -142,9 +142,10 @@ internal class OnlinePush {
@UseExperimental(ExperimentalStdlibApi::class) @UseExperimental(ExperimentalStdlibApi::class)
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot, sequenceId: Int): Packet { override suspend fun ByteReadPacket.decode(bot: QQAndroidBot, sequenceId: Int): Packet {
val reqPushMsg = decodeUniPacket(OnlinePushPack.SvcReqPushMsg.serializer(), "req") val reqPushMsg = decodeUniPacket(OnlinePushPack.SvcReqPushMsg.serializer(), "req")
val packets = reqPushMsg.vMsgInfos.mapNotNull { msgInfo: MsgInfo ->
msgInfo.vMsg!!.read {
@Suppress("USELESS_CAST") // 不要信任 kotlin 类型推断
val packets: List<Packet> = reqPushMsg.vMsgInfos.mapNotNull { msgInfo: MsgInfo ->
msgInfo.vMsg!!.read {
when { when {
msgInfo.shMsgType.toInt() == 732 -> { msgInfo.shMsgType.toInt() == 732 -> {
val group = bot.getGroup(this.readUInt().toLong()) val group = bot.getGroup(this.readUInt().toLong())
@ -162,41 +163,48 @@ internal class OnlinePush {
val target = this.readUInt().toLong() val target = this.readUInt().toLong()
val time = this.readInt() val time = this.readInt()
return@mapNotNull if (target == 0L) { if (target == 0L) {
if (time == 0) { if (time == 0) {
GroupMuteAllEvent( return@mapNotNull GroupMuteAllEvent(
origin = group.isMuteAll.also { group._muteAll = false }, origin = group.isMuteAll.also { group._muteAll = false },
new = false, new = false,
operator = operator, operator = operator,
group = group group = group
) ) as Packet
} else { } else {
GroupMuteAllEvent( return@mapNotNull GroupMuteAllEvent(
origin = group.isMuteAll.also { group._muteAll = true }, origin = group.isMuteAll.also { group._muteAll = true },
new = true, new = true,
operator = operator, operator = operator,
group = group group = group
) ) as Packet
} }
} else { } else {
if (target == bot.uin) { if (target == bot.uin) {
@Suppress("IMPLICIT_CAST_TO_ANY") // false positive if (group._botMuteRemaining != time) {
return@mapNotNull if (time == 0) { if (time == 0) {
BotUnmuteEvent(operator) group._botMuteRemaining = 0
} else return@mapNotNull BotUnmuteEvent(operator) as Packet
BotMuteEvent(durationSeconds = time, operator = operator) } else {
group._botMuteRemaining = time
return@mapNotNull BotMuteEvent(durationSeconds = time, operator = operator) as Packet
}
} else {
return@mapNotNull null
}
} else { } else {
val member = group[target] val member = group[target]
@Suppress("IMPLICIT_CAST_TO_ANY") // false positive // TODO: 2020/2/20 检查是否重复
return@mapNotNull if (time == 0) { return@mapNotNull if (time == 0) {
MemberUnmuteEvent(operator = operator, member = member) MemberUnmuteEvent(operator = operator, member = member)
} else { } else {
MemberMuteEvent(operator = operator, member = member, durationSeconds = time) MemberMuteEvent(operator = operator, member = member, durationSeconds = time) as Packet
} }
} }
} }
} }
3585 -> { // 匿名 3585 -> {
// 匿名
val operator = group[this.readUInt().toLong()] val operator = group[this.readUInt().toLong()]
val switch = this.readInt() == 0 val switch = this.readInt() == 0
return@mapNotNull GroupAllowAnonymousChatEvent( return@mapNotNull GroupAllowAnonymousChatEvent(
@ -239,7 +247,7 @@ internal class OnlinePush {
} }
else -> { else -> {
bot.network.logger.debug { "Unknown server messages $message" } bot.network.logger.debug { "Unknown server messages $message" }
return@mapNotNull NoPacket return@mapNotNull null
} }
} }
} }
@ -250,26 +258,28 @@ internal class OnlinePush {
// } // }
else -> { else -> {
bot.network.logger.debug { "unknown group internal type $internalType , data: " + this.readBytes().toUHexString() + " " } bot.network.logger.debug { "unknown group internal type $internalType , data: " + this.readBytes().toUHexString() + " " }
return@mapNotNull null
} }
} }
return@mapNotNull null
} }
msgInfo.shMsgType.toInt() == 528 -> { msgInfo.shMsgType.toInt() == 528 -> {
bot.network.logger.debug { "unknown shtype ${msgInfo.shMsgType.toInt()}" } bot.network.logger.debug { "unknown shtype ${msgInfo.shMsgType.toInt()}" }
// val content = msgInfo.vMsg.loadAs(OnlinePushPack.MsgType0x210.serializer()) // val content = msgInfo.vMsg.loadAs(OnlinePushPack.MsgType0x210.serializer())
// println(content.contentToString()) // println(content.contentToString())
return@mapNotNull null
} }
else -> { else -> {
bot.network.logger.debug { "unknown shtype ${msgInfo.shMsgType.toInt()}" } bot.network.logger.debug { "unknown shtype ${msgInfo.shMsgType.toInt()}" }
} return@mapNotNull null
} }
} }
return@mapNotNull null return@mapNotNull null
} }
}
return MultiPacket(packets) return MultiPacket(packets)
} }
override suspend fun QQAndroidBot.handle(packet: Packet, sequenceId: Int): OutgoingPacket? { override suspend fun QQAndroidBot.handle(packet: Packet, sequenceId: Int): OutgoingPacket? {
return buildResponseUniPacket(client, sequenceId = sequenceId) { return buildResponseUniPacket(client, sequenceId = sequenceId) {