mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: fix 群精华消息推送
This commit is contained in:
parent
7b07698f7b
commit
39120bdeae
@ -1,4 +1,5 @@
|
||||
@file:OptIn(DelicateCoroutinesApi::class)
|
||||
|
||||
package moe.fuqiuluo.shamrock.remote.service.listener
|
||||
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||
@ -9,7 +10,6 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.io.core.ByteReadPacket
|
||||
import kotlinx.io.core.discardExact
|
||||
import kotlinx.io.core.readBytes
|
||||
import kotlinx.io.core.readUInt
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import moe.fuqiuluo.proto.ProtoByteString
|
||||
@ -22,7 +22,6 @@ import moe.fuqiuluo.proto.asByteArray
|
||||
import moe.fuqiuluo.proto.asList
|
||||
import moe.fuqiuluo.proto.asULong
|
||||
import moe.fuqiuluo.qqinterface.servlet.FriendSvc.requestFriendSystemMsgNew
|
||||
import moe.fuqiuluo.qqinterface.servlet.GroupSvc
|
||||
import moe.fuqiuluo.qqinterface.servlet.GroupSvc.requestGroupSystemMsgNew
|
||||
import moe.fuqiuluo.shamrock.helper.MessageHelper
|
||||
import moe.fuqiuluo.shamrock.remote.service.data.push.NoticeSubType
|
||||
@ -78,6 +77,7 @@ internal object PrimitiveListener {
|
||||
138 -> onC2CRecall(msgTime, pb)
|
||||
290 -> onC2cPoke(msgTime, pb)
|
||||
}
|
||||
|
||||
732 -> when (subType) {
|
||||
12 -> onGroupBan(msgTime, pb)
|
||||
16 -> onGroupTitleChange(msgTime, pb)
|
||||
@ -117,7 +117,8 @@ internal object PrimitiveListener {
|
||||
LogCenter.log("私聊戳一戳: $operation $action $target $suffix")
|
||||
|
||||
if (!GlobalEventTransmitter.PrivateNoticeTransmitter
|
||||
.transPrivatePoke(msgTime, operation.toLong(), target.toLong(), action, suffix, actionImg)) {
|
||||
.transPrivatePoke(msgTime, operation.toLong(), target.toLong(), action, suffix, actionImg)
|
||||
) {
|
||||
LogCenter.log("私聊戳一戳推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -144,13 +145,13 @@ internal object PrimitiveListener {
|
||||
}
|
||||
LogCenter.log("来自$applier 的好友申请:$msg ($source)")
|
||||
if (!GlobalEventTransmitter.RequestTransmitter
|
||||
.transFriendApp(msgTime, applier, msg, flag)) {
|
||||
.transFriendApp(msgTime, applier, msg, flag)
|
||||
) {
|
||||
LogCenter.log("好友申请推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private suspend fun onCardChange(msgTime: Long, pb: ProtoMap) {
|
||||
val targetId = pb[1, 3, 2, 1, 13, 2].asUtf8String
|
||||
val newCardList = pb[1, 3, 2, 1, 13, 3].asList
|
||||
@ -164,8 +165,8 @@ internal object PrimitiveListener {
|
||||
}
|
||||
val groupId = pb[1, 3, 2, 1, 13, 4].asLong
|
||||
var oldCard = ""
|
||||
LogCenter.log("群组[$groupId]成员$targetId 群名片变动 -> $newCard")
|
||||
val targetQQ = ContactHelper.getUinByUidAsync(targetId).toLong()
|
||||
LogCenter.log("群组[$groupId]成员$targetId 群名片变动 -> $newCard")
|
||||
// oldCard暂时获取不到
|
||||
// GroupSvc.getTroopMemberInfoByUin(groupId.toString(), targetQQ.toString()).onSuccess {
|
||||
// oldCard = it.troopnick
|
||||
@ -173,7 +174,8 @@ internal object PrimitiveListener {
|
||||
// LogCenter.log("获取群成员信息失败!", Level.WARN)
|
||||
// }
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transCardChange(msgTime, targetQQ, oldCard, newCard, groupId)) {
|
||||
.transCardChange(msgTime, targetQQ, oldCard, newCard, groupId)
|
||||
) {
|
||||
LogCenter.log("群名片变动推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -195,35 +197,50 @@ internal object PrimitiveListener {
|
||||
LogCenter.log("群组[$groupId]成员$targetUin 获得群头衔 -> $title")
|
||||
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transTitleChange(msgTime, targetUin, title, groupId)) {
|
||||
.transTitleChange(msgTime, targetUin, title, groupId)
|
||||
) {
|
||||
LogCenter.log("群头衔变动推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun onEssenceMessage(msgTime: Long, pb: ProtoMap) {
|
||||
val groupId = pb[1, 3, 2, 4].asLong
|
||||
val mesSeq = pb[1, 3, 2, 37].asInt
|
||||
val operatorUin = pb[1, 3, 2, 33, 6].asLong
|
||||
val senderUin = pb[1, 3, 2, 33, 5].asLong
|
||||
val groupCode = pb[1, 1, 1].asULong
|
||||
|
||||
val readPacket = ByteReadPacket(pb[1, 3, 2].asByteArray)
|
||||
val detail = if (readPacket.readBuf32Long() == groupCode) {
|
||||
readPacket.discardExact(1)
|
||||
ProtoUtils.decodeFromByteArray(readPacket.readBytes(readPacket.readShort().toInt()))
|
||||
} else pb[1, 3, 2]
|
||||
|
||||
val groupId = detail[4].asLong
|
||||
val mesSeq = detail[37].asInt
|
||||
val senderUin = detail[33, 5].asLong
|
||||
val operatorUin = detail[33, 6].asLong
|
||||
var msgId = 0
|
||||
MessageHelper.getMsgMappingBySeq(MsgConstant.KCHATTYPEGROUP, mesSeq).also {
|
||||
if (it != null) {
|
||||
msgId = it.msgHashId
|
||||
}
|
||||
}
|
||||
val type = pb[1, 3, 2, 33, 4].asInt
|
||||
val subType = if (type == 2) {
|
||||
// remove essence
|
||||
LogCenter.log("群组[$groupId]成员$senderUin 的消息$msgId 被$operatorUin 移除精华")
|
||||
NoticeSubType.Delete
|
||||
} else {
|
||||
val subType = when (val type = detail[33, 4].asInt) {
|
||||
1 -> {
|
||||
// add essence
|
||||
LogCenter.log("群组[$groupId]成员$senderUin 的消息$msgId 被$operatorUin 设为精华")
|
||||
LogCenter.log("群设精消息($groupId): $senderUin $msgId $operatorUin")
|
||||
NoticeSubType.Add
|
||||
}
|
||||
|
||||
2 -> {
|
||||
// remove essence
|
||||
LogCenter.log("群取精消息($groupId): $senderUin $msgId $operatorUin")
|
||||
NoticeSubType.Delete
|
||||
}
|
||||
|
||||
else -> error("onEssenceMessage unknown type: $type")
|
||||
}
|
||||
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transEssenceChange(msgTime, senderUin, operatorUin, msgId, groupId, subType)) {
|
||||
.transEssenceChange(msgTime, senderUin, operatorUin, msgId, groupId, subType)
|
||||
) {
|
||||
LogCenter.log("精华消息变动推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -271,7 +288,8 @@ internal object PrimitiveListener {
|
||||
LogCenter.log("群戳一戳($groupCode): $operation $action $target $suffix")
|
||||
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupPoke(time, operation.toLong(), target.toLong(), action, suffix, actionImg, groupCode)) {
|
||||
.transGroupPoke(time, operation.toLong(), target.toLong(), action, suffix, actionImg, groupCode)
|
||||
) {
|
||||
LogCenter.log("群戳一戳推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -290,7 +308,8 @@ internal object PrimitiveListener {
|
||||
LogCenter.log("私聊消息撤回: $operation, seq = $msgSeq, hash = ${mapping.msgHashId}, tip = $tipText")
|
||||
|
||||
if (!GlobalEventTransmitter.PrivateNoticeTransmitter
|
||||
.transPrivateRecall(time, operation, mapping.msgHashId, tipText)) {
|
||||
.transPrivateRecall(time, operation, mapping.msgHashId, tipText)
|
||||
) {
|
||||
LogCenter.log("私聊消息撤回推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -304,11 +323,14 @@ internal object PrimitiveListener {
|
||||
LogCenter.log("群成员增加($groupCode): $target, type = $type")
|
||||
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupMemberNumChanged(time, target, groupCode, operation, NoticeType.GroupMemIncrease, when(type) {
|
||||
.transGroupMemberNumChanged(
|
||||
time, target, groupCode, operation, NoticeType.GroupMemIncrease, when (type) {
|
||||
130 -> NoticeSubType.Approve
|
||||
131 -> NoticeSubType.Invite
|
||||
else -> NoticeSubType.Approve
|
||||
})) {
|
||||
}
|
||||
)
|
||||
) {
|
||||
LogCenter.log("群成员增加推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -332,7 +354,8 @@ internal object PrimitiveListener {
|
||||
LogCenter.log("群成员减少($groupCode): $target, type = $subtype ($type)")
|
||||
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupMemberNumChanged(time, target, groupCode, operation, NoticeType.GroupMemDecrease, subtype)) {
|
||||
.transGroupMemberNumChanged(time, target, groupCode, operation, NoticeType.GroupMemDecrease, subtype)
|
||||
) {
|
||||
LogCenter.log("群成员减少推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -352,7 +375,8 @@ internal object PrimitiveListener {
|
||||
LogCenter.log("群管理员变动($groupCode): $target, isSetAdmin = $isSetAdmin")
|
||||
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupAdminChanged(msgTime, target, groupCode, isSetAdmin)) {
|
||||
.transGroupAdminChanged(msgTime, target, groupCode, isSetAdmin)
|
||||
) {
|
||||
LogCenter.log("群管理员变动推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -367,7 +391,8 @@ internal object PrimitiveListener {
|
||||
LogCenter.log("群禁言($groupCode): $operation -> $target, 时长 = ${duration}s")
|
||||
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupBan(msgTime, operation, target, groupCode, duration)) {
|
||||
.transGroupBan(msgTime, operation, target, groupCode, duration)
|
||||
) {
|
||||
LogCenter.log("群禁言推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -379,7 +404,7 @@ internal object PrimitiveListener {
|
||||
/**
|
||||
* 真是不理解这个傻呗设计,有些群是正常的Protobuf,有些群要去掉7字节
|
||||
*/
|
||||
val detail = if (readPacket.readUInt().toLong() == groupCode) {
|
||||
val detail = if (readPacket.readBuf32Long() == groupCode) {
|
||||
readPacket.discardExact(1)
|
||||
ProtoUtils.decodeFromByteArray(readPacket.readBytes(readPacket.readShort().toInt()))
|
||||
} else pb[1, 3, 2]
|
||||
@ -399,7 +424,8 @@ internal object PrimitiveListener {
|
||||
LogCenter.log("群消息撤回($groupCode): $operator -> $target, seq = $msgSeq, hash = $msgHash, tip = $tipText")
|
||||
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupMsgRecall(time, operator, target, groupCode, msgHash, tipText)) {
|
||||
.transGroupMsgRecall(time, operator, target, groupCode, msgHash, tipText)
|
||||
) {
|
||||
LogCenter.log("群消息撤回推送失败!", Level.WARN)
|
||||
}
|
||||
} finally {
|
||||
@ -429,10 +455,12 @@ internal object PrimitiveListener {
|
||||
"$time;$groupCode;$applier"
|
||||
}
|
||||
if (!GlobalEventTransmitter.RequestTransmitter
|
||||
.transGroupApply(time, applier, reason, groupCode, flag, RequestSubType.Add)) {
|
||||
.transGroupApply(time, applier, reason, groupCode, flag, RequestSubType.Add)
|
||||
) {
|
||||
LogCenter.log("入群申请推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
|
||||
528 -> {
|
||||
val groupCode = pb[1, 3, 2, 2, 3].asULong
|
||||
val applierUid = pb[1, 3, 2, 2, 5].asUtf8String
|
||||
@ -455,12 +483,14 @@ internal object PrimitiveListener {
|
||||
"$time;$groupCode;$applierUid"
|
||||
}
|
||||
if (GlobalEventTransmitter.RequestTransmitter
|
||||
.transGroupApply(time, applier, "", groupCode, flag, RequestSubType.Add)) {
|
||||
.transGroupApply(time, applier, "", groupCode, flag, RequestSubType.Add)
|
||||
) {
|
||||
LogCenter.log("邀请入群申请推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun onInviteGroup(time: Long, pb: ProtoMap) {
|
||||
val groupCode = pb[1, 3, 2, 1].asULong
|
||||
val invitorUid = pb[1, 3, 2, 5].asUtf8String
|
||||
@ -480,7 +510,8 @@ internal object PrimitiveListener {
|
||||
"$time;$groupCode;$uin"
|
||||
}
|
||||
if (GlobalEventTransmitter.RequestTransmitter
|
||||
.transGroupApply(time, invitor, "", groupCode, flag, RequestSubType.Invite)) {
|
||||
.transGroupApply(time, invitor, "", groupCode, flag, RequestSubType.Invite)
|
||||
) {
|
||||
LogCenter.log("邀请入群推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user