From 9608b467993dfd30447214784167aae71d110f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B1=A0?= Date: Thu, 15 Feb 2024 13:14:37 +0800 Subject: [PATCH] =?UTF-8?q?`Shamrock`:=20=E6=98=AF=E6=AD=A3=E3=83=A1?= =?UTF-8?q?=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=83=97=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=A5=E3=82=A2=E3=82=A4=E3=83=87=E3=83=B3=E3=83=86=E3=82=A3?= =?UTF-8?q?=E3=83=86=E3=82=A3=E3=81=AE=E5=8F=96=E5=BE=97=E3=81=8C=E9=81=85?= =?UTF-8?q?=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fuqiuluo/qqinterface/servlet/GroupSvc.kt | 23 +++++++++++++++---- .../action/handlers/GetTroopMemberInfo.kt | 6 +---- .../action/handlers/GetTroopMemberList.kt | 5 ++-- .../service/api/GlobalEventTransmitter.kt | 6 ++--- .../remote/service/data/push/MessageEvent.kt | 4 +++- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/GroupSvc.kt b/xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/GroupSvc.kt index ed14a7b5..03ad7ebb 100644 --- a/xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/GroupSvc.kt +++ b/xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/GroupSvc.kt @@ -59,6 +59,7 @@ import moe.fuqiuluo.shamrock.remote.service.data.EssenceMessage import moe.fuqiuluo.shamrock.remote.service.data.GroupAnnouncement import moe.fuqiuluo.shamrock.remote.service.data.GroupAnnouncementMessage import moe.fuqiuluo.shamrock.remote.service.data.GroupAnnouncementMessageImage +import moe.fuqiuluo.shamrock.remote.service.data.push.MemberRole import moe.fuqiuluo.shamrock.tools.EmptyJsonArray import moe.fuqiuluo.shamrock.tools.GlobalClient import moe.fuqiuluo.shamrock.tools.asInt @@ -394,6 +395,20 @@ internal object GroupSvc: BaseSvc() { .filter { it != 0L } } + suspend fun getMemberRole(groupId: Long, memberUin: Long): MemberRole { + return when(getTroopMemberInfoByUinViaNt(groupId.toString(), memberUin, 3000).getOrNull()?.role) { + com.tencent.qqnt.kernel.nativeinterface.MemberRole.STRANGER -> MemberRole.Stranger + com.tencent.qqnt.kernel.nativeinterface.MemberRole.MEMBER -> MemberRole.Member + com.tencent.qqnt.kernel.nativeinterface.MemberRole.ADMIN -> MemberRole.Admin + com.tencent.qqnt.kernel.nativeinterface.MemberRole.OWNER -> MemberRole.Owner + com.tencent.qqnt.kernel.nativeinterface.MemberRole.UNSPECIFIED, null -> when (memberUin) { + getOwner(groupId.toString()) -> MemberRole.Owner + in getAdminList(groupId.toString()) -> MemberRole.Admin + else -> MemberRole.Member + } + } + } + fun getOwner(groupId: String): Long { val groupInfo = getGroupInfo(groupId) return groupInfo.troopowneruin?.toLong() ?: 0 @@ -574,7 +589,7 @@ internal object GroupSvc: BaseSvc() { val service = app.getRuntimeService(ITroopMemberInfoService::class.java, "all") var info = service.getTroopMember(groupId, uin) if (refresh || !service.isMemberInCache(groupId, uin) || info == null || info.troopnick == null) { - info = requestTroopMemberInfo(service, groupId.toLong(), uin.toLong()).getOrNull() + info = requestTroopMemberInfo(service, groupId.toLong(), uin.toLong(), timeout = 2000).getOrNull() } if (info == null) { info = getTroopMemberInfoByUinViaNt(groupId, uin.toLong(), timeout = 2000L).getOrNull()?.let { @@ -621,7 +636,7 @@ internal object GroupSvc: BaseSvc() { } } - private suspend fun getTroopMemberInfoByUinViaNt( + suspend fun getTroopMemberInfoByUinViaNt( groupId: String, qq: Long, timeout: Long = 5000L @@ -809,7 +824,7 @@ internal object GroupSvc: BaseSvc() { } } - private suspend fun requestTroopMemberInfo(service: ITroopMemberInfoService, groupId: Long, memberUin: Long): Result { + private suspend fun requestTroopMemberInfo(service: ITroopMemberInfoService, groupId: Long, memberUin: Long, timeout: Long = 10_000): Result { val info = RefreshTroopMemberInfoLock.withLock { val groupIdStr = groupId.toString() val memberUinStr = memberUin.toString() @@ -819,7 +834,7 @@ internal object GroupSvc: BaseSvc() { requestMemberInfoV2(groupId, memberUin) requestMemberInfo(groupId, memberUin) - withTimeoutOrNull(10000) { + withTimeoutOrNull(timeout) { while (!service.isMemberInCache(groupIdStr, memberUinStr)) { delay(200) } diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetTroopMemberInfo.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetTroopMemberInfo.kt index f869983d..79d87961 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetTroopMemberInfo.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetTroopMemberInfo.kt @@ -52,11 +52,7 @@ internal object GetTroopMemberInfo : IActionHandler() { area = info.alias ?: "", lastSentTime = info.last_active_time, level = info.level, - role = when { - GroupSvc.getOwner(groupId).toString() == uin -> MemberRole.Owner - uin.toLong() in GroupSvc.getAdminList(groupId) -> MemberRole.Admin - else -> MemberRole.Member - }, + role = GroupSvc.getMemberRole(groupId.toLong(), uin.toLong()), unfriendly = false, title = info.mUniqueTitle ?: "", titleExpireTime = info.mUniqueTitleExpire, diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetTroopMemberList.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetTroopMemberList.kt index 54d23dc1..e56d0771 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetTroopMemberList.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetTroopMemberList.kt @@ -54,12 +54,13 @@ internal object GetTroopMemberList : IActionHandler() { area = info.alias ?: "", lastSentTime = info.last_active_time, level = info.level, - role = when { + role = GroupSvc.getMemberRole(groupId.toLong(), info.memberuin.toLong()) + /*when { GroupSvc.getOwner(groupId) .toString() == info.memberuin -> MemberRole.Owner info.memberuin.toLong() in GroupSvc.getAdminList(groupId) -> MemberRole.Admin else -> MemberRole.Member - }, + }*/, unfriendly = false, title = info.mUniqueTitle ?: "", titleExpireTime = info.mUniqueTitleExpire, diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt index 7c8d6202..c0607713 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt @@ -92,11 +92,11 @@ internal object GlobalEventTransmitter: BaseSvc() { .ifEmpty { record.sendMemberName } .ifEmpty { record.peerName }, card = record.sendMemberName, - role = when (record.senderUin) { + role = GroupSvc.getMemberRole(record.peerUin, record.senderUin)/*when (record.senderUin) { GroupSvc.getOwner(record.peerUin.toString()) -> MemberRole.Owner in GroupSvc.getAdminList(record.peerUin.toString()) -> MemberRole.Admin else -> MemberRole.Member - }, + }*/, title = "", level = "", ) @@ -194,7 +194,7 @@ internal object GlobalEventTransmitter: BaseSvc() { userId = record.senderUid.toLong(), nickname = nickName, card = record.sendMemberName, - role = MemberRole.Member, + role = MemberRole.Member, // TODO(GUILD ROLE) title = record.sendNickName, level = record.roleId.toString(), tinyId = record.senderUid diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/data/push/MessageEvent.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/data/push/MessageEvent.kt index 68575247..fbfa0b22 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/data/push/MessageEvent.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/data/push/MessageEvent.kt @@ -88,7 +88,9 @@ internal data class Anonymous( internal enum class MemberRole { @SerialName("owner") Owner, @SerialName("admin") Admin, - @SerialName("member") Member + @SerialName("member") Member, + @SerialName("stranger") Stranger, + @SerialName("unknown") Unknown } @Serializable