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
|
||||
@ -64,13 +63,13 @@ internal object PrimitiveListener {
|
||||
subType = pb[1, 2, 2].asInt
|
||||
}
|
||||
val msgTime = pb[1, 2, 6].asLong
|
||||
when(msgType) {
|
||||
when (msgType) {
|
||||
33 -> onGroupMemIncreased(msgTime, pb)
|
||||
34 -> onGroupMemberDecreased(msgTime, pb)
|
||||
44 -> onGroupAdminChange(msgTime, pb)
|
||||
84 -> onGroupApply(msgTime, pb)
|
||||
87 -> onInviteGroup(msgTime, pb)
|
||||
528 -> when(subType) {
|
||||
528 -> when (subType) {
|
||||
35 -> onFriendApply(msgTime, pb)
|
||||
39 -> onCardChange(msgTime, pb)
|
||||
// invite
|
||||
@ -78,7 +77,8 @@ internal object PrimitiveListener {
|
||||
138 -> onC2CRecall(msgTime, pb)
|
||||
290 -> onC2cPoke(msgTime, pb)
|
||||
}
|
||||
732 -> when(subType) {
|
||||
|
||||
732 -> when (subType) {
|
||||
12 -> onGroupBan(msgTime, pb)
|
||||
16 -> onGroupTitleChange(msgTime, pb)
|
||||
17 -> onGroupRecall(msgTime, pb)
|
||||
@ -104,7 +104,7 @@ internal object PrimitiveListener {
|
||||
.value
|
||||
.forEach {
|
||||
val value = it[2].asUtf8String
|
||||
when(it[1].asUtf8String) {
|
||||
when (it[1].asUtf8String) {
|
||||
"uin_str1" -> operation = value
|
||||
"uin_str2" -> target = value
|
||||
"action_str" -> action = value
|
||||
@ -116,8 +116,9 @@ internal object PrimitiveListener {
|
||||
|
||||
LogCenter.log("私聊戳一戳: $operation $action $target $suffix")
|
||||
|
||||
if(!GlobalEventTransmitter.PrivateNoticeTransmitter
|
||||
.transPrivatePoke(msgTime, operation.toLong(), target.toLong(), action, suffix, actionImg)) {
|
||||
if (!GlobalEventTransmitter.PrivateNoticeTransmitter
|
||||
.transPrivatePoke(msgTime, operation.toLong(), target.toLong(), action, suffix, actionImg)
|
||||
) {
|
||||
LogCenter.log("私聊戳一戳推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -143,14 +144,14 @@ internal object PrimitiveListener {
|
||||
"$msgTime;$src;$subSrc;$applier"
|
||||
}
|
||||
LogCenter.log("来自$applier 的好友申请:$msg ($source)")
|
||||
if(!GlobalEventTransmitter.RequestTransmitter
|
||||
.transFriendApp(msgTime, applier, msg, flag)) {
|
||||
if (!GlobalEventTransmitter.RequestTransmitter
|
||||
.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
|
||||
@ -158,22 +159,23 @@ internal object PrimitiveListener {
|
||||
newCardList
|
||||
.value
|
||||
.forEach {
|
||||
if(it[1].asInt == 1) {
|
||||
if (it[1].asInt == 1) {
|
||||
newCard = it[2].asUtf8String
|
||||
}
|
||||
}
|
||||
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
|
||||
// }.onFailure {
|
||||
// LogCenter.log("获取群成员信息失败!", Level.WARN)
|
||||
// }
|
||||
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transCardChange(msgTime, targetQQ, oldCard, newCard, groupId)) {
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transCardChange(msgTime, targetQQ, oldCard, newCard, groupId)
|
||||
) {
|
||||
LogCenter.log("群名片变动推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -194,36 +196,51 @@ internal object PrimitiveListener {
|
||||
|
||||
LogCenter.log("群组[$groupId]成员$targetUin 获得群头衔 -> $title")
|
||||
|
||||
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transTitleChange(msgTime, targetUin, title, groupId)) {
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.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 {
|
||||
// add essence
|
||||
LogCenter.log("群组[$groupId]成员$senderUin 的消息$msgId 被$operatorUin 设为精华")
|
||||
NoticeSubType.Add
|
||||
val subType = when (val type = detail[33, 4].asInt) {
|
||||
1 -> {
|
||||
// add essence
|
||||
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)) {
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transEssenceChange(msgTime, senderUin, operatorUin, msgId, groupId, subType)
|
||||
) {
|
||||
LogCenter.log("精华消息变动推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -234,7 +251,7 @@ internal object PrimitiveListener {
|
||||
|
||||
var groupCode: Long = groupCode1
|
||||
|
||||
val readPacket = ByteReadPacket( pb[1, 3, 2].asByteArray )
|
||||
val readPacket = ByteReadPacket(pb[1, 3, 2].asByteArray)
|
||||
val groupCode2 = readPacket.readBuf32Long()
|
||||
|
||||
var detail = if (groupCode2 == groupCode1) {
|
||||
@ -258,20 +275,21 @@ internal object PrimitiveListener {
|
||||
.asList
|
||||
.value
|
||||
.forEach {
|
||||
val value = it[2].asUtf8String
|
||||
when(it[1].asUtf8String) {
|
||||
"uin_str1" -> operation = value
|
||||
"uin_str2" -> target = value
|
||||
"action_str" -> action = value
|
||||
"alt_str1" -> action = value
|
||||
"suffix_str" -> suffix = value
|
||||
"action_img_url" -> actionImg = value
|
||||
val value = it[2].asUtf8String
|
||||
when (it[1].asUtf8String) {
|
||||
"uin_str1" -> operation = value
|
||||
"uin_str2" -> target = value
|
||||
"action_str" -> action = value
|
||||
"alt_str1" -> action = value
|
||||
"suffix_str" -> suffix = value
|
||||
"action_img_url" -> actionImg = value
|
||||
}
|
||||
}
|
||||
}
|
||||
LogCenter.log("群戳一戳($groupCode): $operation $action $target $suffix")
|
||||
|
||||
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupPoke(time, operation.toLong(), target.toLong(), action, suffix, actionImg, groupCode)) {
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupPoke(time, operation.toLong(), target.toLong(), action, suffix, actionImg, groupCode)
|
||||
) {
|
||||
LogCenter.log("群戳一戳推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -289,8 +307,9 @@ internal object PrimitiveListener {
|
||||
|
||||
LogCenter.log("私聊消息撤回: $operation, seq = $msgSeq, hash = ${mapping.msgHashId}, tip = $tipText")
|
||||
|
||||
if(!GlobalEventTransmitter.PrivateNoticeTransmitter
|
||||
.transPrivateRecall(time, operation, mapping.msgHashId, tipText)) {
|
||||
if (!GlobalEventTransmitter.PrivateNoticeTransmitter
|
||||
.transPrivateRecall(time, operation, mapping.msgHashId, tipText)
|
||||
) {
|
||||
LogCenter.log("私聊消息撤回推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -303,12 +322,15 @@ internal object PrimitiveListener {
|
||||
val target = ContactHelper.getUinByUidAsync(targetUid).toLong()
|
||||
LogCenter.log("群成员增加($groupCode): $target, type = $type")
|
||||
|
||||
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupMemberNumChanged(time, target, groupCode, operation, NoticeType.GroupMemIncrease, when(type) {
|
||||
130 -> NoticeSubType.Approve
|
||||
131 -> NoticeSubType.Invite
|
||||
else -> NoticeSubType.Approve
|
||||
})) {
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupMemberNumChanged(
|
||||
time, target, groupCode, operation, NoticeType.GroupMemIncrease, when (type) {
|
||||
130 -> NoticeSubType.Approve
|
||||
131 -> NoticeSubType.Invite
|
||||
else -> NoticeSubType.Approve
|
||||
}
|
||||
)
|
||||
) {
|
||||
LogCenter.log("群成员增加推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -320,7 +342,7 @@ internal object PrimitiveListener {
|
||||
val operation = ContactHelper.getUinByUidAsync(pb[1, 3, 2, 5].asUtf8String).toLong()
|
||||
|
||||
val target = ContactHelper.getUinByUidAsync(targetUid).toLong()
|
||||
val subtype = when(type) {
|
||||
val subtype = when (type) {
|
||||
130 -> NoticeSubType.Leave
|
||||
131 -> NoticeSubType.Kick
|
||||
3 -> NoticeSubType.KickMe
|
||||
@ -331,8 +353,9 @@ internal object PrimitiveListener {
|
||||
|
||||
LogCenter.log("群成员减少($groupCode): $target, type = $subtype ($type)")
|
||||
|
||||
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupMemberNumChanged(time, target, groupCode, operation, NoticeType.GroupMemDecrease, subtype)) {
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupMemberNumChanged(time, target, groupCode, operation, NoticeType.GroupMemDecrease, subtype)
|
||||
) {
|
||||
LogCenter.log("群成员减少推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -351,8 +374,9 @@ internal object PrimitiveListener {
|
||||
val target = ContactHelper.getUinByUidAsync(targetUid).toLong()
|
||||
LogCenter.log("群管理员变动($groupCode): $target, isSetAdmin = $isSetAdmin")
|
||||
|
||||
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupAdminChanged(msgTime, target, groupCode, isSetAdmin)) {
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupAdminChanged(msgTime, target, groupCode, isSetAdmin)
|
||||
) {
|
||||
LogCenter.log("群管理员变动推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
@ -366,20 +390,21 @@ internal object PrimitiveListener {
|
||||
val target = ContactHelper.getUinByUidAsync(targetUid).toLong()
|
||||
LogCenter.log("群禁言($groupCode): $operation -> $target, 时长 = ${duration}s")
|
||||
|
||||
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupBan(msgTime, operation, target, groupCode, duration)) {
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupBan(msgTime, operation, target, groupCode, duration)
|
||||
) {
|
||||
LogCenter.log("群禁言推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun onGroupRecall(time: Long, pb: ProtoMap) {
|
||||
val groupCode = pb[1, 1, 1].asULong
|
||||
val readPacket = ByteReadPacket( pb[1, 3, 2].asByteArray )
|
||||
val readPacket = ByteReadPacket(pb[1, 3, 2].asByteArray)
|
||||
try {
|
||||
/**
|
||||
* 真是不理解这个傻呗设计,有些群是正常的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]
|
||||
@ -398,8 +423,9 @@ internal object PrimitiveListener {
|
||||
val target = ContactHelper.getUinByUidAsync(targetUid).toLong()
|
||||
LogCenter.log("群消息撤回($groupCode): $operator -> $target, seq = $msgSeq, hash = $msgHash, tip = $tipText")
|
||||
|
||||
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupMsgRecall(time, operator, target, groupCode, msgHash, tipText)) {
|
||||
if (!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||
.transGroupMsgRecall(time, operator, target, groupCode, msgHash, tipText)
|
||||
) {
|
||||
LogCenter.log("群消息撤回推送失败!", Level.WARN)
|
||||
}
|
||||
} finally {
|
||||
@ -408,7 +434,7 @@ internal object PrimitiveListener {
|
||||
}
|
||||
|
||||
private suspend fun onGroupApply(time: Long, pb: ProtoMap) {
|
||||
when(pb[1, 2, 1].asInt) {
|
||||
when (pb[1, 2, 1].asInt) {
|
||||
84 -> {
|
||||
val groupCode = pb[1, 3, 2, 1].asULong
|
||||
val applierUid = pb[1, 3, 2, 3].asUtf8String
|
||||
@ -428,11 +454,13 @@ internal object PrimitiveListener {
|
||||
} catch (err: Throwable) {
|
||||
"$time;$groupCode;$applier"
|
||||
}
|
||||
if(!GlobalEventTransmitter.RequestTransmitter
|
||||
.transGroupApply(time, applier, reason, groupCode, flag, RequestSubType.Add)) {
|
||||
if (!GlobalEventTransmitter.RequestTransmitter
|
||||
.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
|
||||
@ -454,13 +482,15 @@ internal object PrimitiveListener {
|
||||
} catch (err: Throwable) {
|
||||
"$time;$groupCode;$applierUid"
|
||||
}
|
||||
if(GlobalEventTransmitter.RequestTransmitter
|
||||
.transGroupApply(time, applier, "", groupCode, flag, RequestSubType.Add)) {
|
||||
if (GlobalEventTransmitter.RequestTransmitter
|
||||
.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
|
||||
@ -479,8 +509,9 @@ internal object PrimitiveListener {
|
||||
} catch (err: Throwable) {
|
||||
"$time;$groupCode;$uin"
|
||||
}
|
||||
if(GlobalEventTransmitter.RequestTransmitter
|
||||
.transGroupApply(time, invitor, "", groupCode, flag, RequestSubType.Invite)) {
|
||||
if (GlobalEventTransmitter.RequestTransmitter
|
||||
.transGroupApply(time, invitor, "", groupCode, flag, RequestSubType.Invite)
|
||||
) {
|
||||
LogCenter.log("邀请入群推送失败!", Level.WARN)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user