Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Shamrock: fix wrong group request event
Browse files Browse the repository at this point in the history
  • Loading branch information
ikechan8370 committed Nov 22, 2023
1 parent 89154f0 commit 03d62c5
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 27 deletions.
62 changes: 47 additions & 15 deletions xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/GroupSvc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,15 @@ internal object GroupSvc: BaseSvc() {
}

// ProfileService.Pb.ReqSystemMsgAction.Group
suspend fun requestGroupRequest(msgSeq: Long, uin: Long, gid: Long, msg: String? = "", approve: Boolean? = true, notSee: Boolean? = false): Result<String>{
suspend fun requestGroupRequest(
msgSeq: Long,
uin: Long,
gid: Long,
msg: String? = "",
approve: Boolean? = true,
notSee: Boolean? = false,
subType: String
): Result<String>{
// val app = AppRuntimeFetcher.appRuntime
// if (app !is AppInterface)
// throw RuntimeException("AppRuntime cannot cast to AppInterface")
Expand All @@ -617,20 +625,44 @@ internal object GroupSvc: BaseSvc() {
// app
// )
// 实在找不到接口了 发pb吧
val buffer = protobufOf(
1 to 2,
2 to msgSeq,
3 to uin,
4 to 1,
5 to 2,
6 to 30024,
7 to 1,
8 to mapOf(
1 to if (approve != false) 11 else 12,
2 to gid
),
9 to 1000
).toByteArray()
val buffer: ByteArray
when (subType) {
"invite" -> {
buffer = protobufOf(
1 to 1,
2 to msgSeq,
3 to uin, // self
4 to 1,
5 to 3,
6 to 10016,
7 to 2,
8 to mapOf(
1 to if (approve != false) 11 else 12,
2 to gid
),
9 to 1000
).toByteArray()
}
"add" -> {
buffer = protobufOf(
1 to 2,
2 to msgSeq,
3 to uin,
4 to 1,
5 to 2,
6 to 30024,
7 to 1,
8 to mapOf(
1 to if (approve != false) 11 else 12,
2 to gid
),
9 to 1000
).toByteArray()
}
else -> {
return Result.failure(Exception("不支持的sub_type"))
}
}
val respBuffer = sendBufferAW("ProfileService.Pb.ReqSystemMsgAction.Group", true, buffer)
?: return Result.failure(Exception("操作失败"))
val result = ProtoUtils.decodeFromByteArray(respBuffer.slice(4))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package moe.fuqiuluo.shamrock.remote.action.handlers

import kotlinx.serialization.json.JsonElement
import moe.fuqiuluo.qqinterface.servlet.FriendSvc
import moe.fuqiuluo.qqinterface.servlet.GroupSvc
import moe.fuqiuluo.shamrock.remote.action.ActionSession
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
import moe.fuqiuluo.shamrock.remote.service.data.push.NoticeSubType
import moe.fuqiuluo.shamrock.tools.EmptyJsonString

internal object SetGroupAddRequest: IActionHandler() {
Expand All @@ -22,9 +20,9 @@ internal object SetGroupAddRequest: IActionHandler() {
val flags = flag.split(";")
val ts = flags[0].toLong()
val groupCode = flags[1].toLong()
val applier = flags[2].toLong()
val uin = flags[2].toLong()
return try {
val result = GroupSvc.requestGroupRequest(ts, applier, groupCode, remark ?: "", approve, notSeen)
val result = GroupSvc.requestGroupRequest(ts, uin, groupCode, remark ?: "", approve, notSeen, subType)
if (result.isSuccess) {
ok(result.getOrNull(), echo)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ fun Routing.requestRouter() {
val flag = fetchOrThrow("flag")
val approve = fetchOrNull("approve")?.toBooleanStrict() ?: true
val remark = fetchOrNull("reason")
val subType = fetchOrNull("sub_type")
val subType = fetchOrThrow("sub_type")
val notSeen = fetchOrNull("not_seen")?.toBooleanStrict() ?: false

call.respondText(
SetGroupAddRequest(flag, approve, subType ?: "add", remark, notSeen),
SetGroupAddRequest(flag, approve, subType, remark, notSeen),
ContentType.Application.Json
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ internal object PrimitiveListener {
34 -> onGroupMemberDecreased(msgTime, pb)
44 -> onGroupAdminChange(msgTime, pb)
84 -> onGroupApply(msgTime, pb)
87 -> onInviteGroup(msgTime, pb)
528 -> when(subType) {
35 -> onFriendApply(msgTime, pb)
// invite
Expand Down Expand Up @@ -337,13 +338,12 @@ internal object PrimitiveListener {
val applierUid = pb[1, 3, 2, 3].asUtf8String
val reason = pb[1, 3, 2, 5].asUtf8String
val applier = ContactHelper.getUinByUidAsync(applierUid).toLong()
val msg_time = pb[1, 2, 6].asLong

LogCenter.log("$msg_time 入群申请($groupCode) $applier: \"$reason\"")
LogCenter.log("入群申请($groupCode) $applier: \"$reason\"")
try {
val reqs = requestGroupSystemMsgNew(20, 0, 0)
val req = reqs?.first {
it.msg_time.get() == msg_time
it.msg_time.get() == time
}
val seq = req?.msg_seq?.get()
val flag = "$seq;$groupCode;$applierUid"
Expand All @@ -363,18 +363,21 @@ internal object PrimitiveListener {
val groupCode = pb[1, 3, 2, 2, 3].asULong
val applierUid = pb[1, 3, 2, 2, 5].asUtf8String
val applier = ContactHelper.getUinByUidAsync(applierUid).toLong()
val msg_time = pb[1, 2, 6].asLong
if (pb[1, 3, 2, 2, 1].asInt < 3) {
// todo
return
}
LogCenter.log("邀请入群申请($groupCode): $applier")
try {
val reqs = requestGroupSystemMsgNew(20, 0, 0)
val req = reqs?.first {
it.msg_time.get() == msg_time
it.msg_time.get() == time
}
val seq = req?.msg_seq?.get()
val flag = "$seq;$groupCode;$applierUid"
if(!seq?.let {
GlobalEventTransmitter.GroupNoticeTransmitter
.transGroupApply(it, applier, "", groupCode, flag, NoticeSubType.Invite)
.transGroupApply(it, applier, "", groupCode, flag, NoticeSubType.Add)
}!!) {
LogCenter.log("邀请入群申请推送失败!", Level.WARN)
}
Expand All @@ -386,4 +389,29 @@ internal object PrimitiveListener {
}
}
}
private suspend fun onInviteGroup(time: Long, pb: ProtoMap) {
val groupCode = pb[1, 3, 2, 1].asULong
val invitorUid = pb[1, 3, 2, 5].asUtf8String
val invitor = ContactHelper.getUinByUidAsync(invitorUid).toLong()
val uin = pb[1, 1, 5].asLong
LogCenter.log("邀请入群$groupCode 邀请者: \"$invitor\"")
try {
val reqs = requestGroupSystemMsgNew(20, 0, 0)
val req = reqs?.first {
it.msg_time.get() == time
}
val seq = req?.msg_seq?.get()
val flag = "$seq;$groupCode;$uin"
if(!seq?.let {
GlobalEventTransmitter.GroupNoticeTransmitter
.transGroupApply(it, invitor, "", groupCode, flag, NoticeSubType.Invite)
}!!) {
LogCenter.log("邀请入群推送失败!", Level.WARN)
}
} catch (err: Throwable) {
LogCenter.log("邀请入群推送失败!", Level.WARN)
LogCenter.log(err.stackTraceToString(), Level.ERROR)
}
}

}

0 comments on commit 03d62c5

Please sign in to comment.