From 3395cd9d955a46705b086f3fb74f3b1f106d77b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B1=A0?= Date: Fri, 16 Feb 2024 09:12:45 +0800 Subject: [PATCH] =?UTF-8?q?`Shamrock`:=20=E6=94=AF=E6=8C=81=E7=BE=A4?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81=E6=90=BA?= =?UTF-8?q?=E5=B8=A6=E7=BE=A4=E5=8F=B7=E4=BB=A5=E5=8F=8A=E7=BE=A4=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qqnt/kernel/api/impl/MsgService.java | 5 ++++ .../IGetTempChatInfoCallback.java | 5 ++++ .../fuqiuluo/qqinterface/servlet/MsgSvc.kt | 28 +++++++++++++++++-- .../service/api/GlobalEventTransmitter.kt | 8 ++++-- .../remote/service/data/push/MessageEvent.kt | 7 +++-- .../remote/service/listener/AioListener.kt | 12 +++++++- 6 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 qqinterface/src/main/java/com/tencent/qqnt/kernel/nativeinterface/IGetTempChatInfoCallback.java diff --git a/qqinterface/src/main/java/com/tencent/qqnt/kernel/api/impl/MsgService.java b/qqinterface/src/main/java/com/tencent/qqnt/kernel/api/impl/MsgService.java index 0b344e3..f6c1817 100644 --- a/qqinterface/src/main/java/com/tencent/qqnt/kernel/api/impl/MsgService.java +++ b/qqinterface/src/main/java/com/tencent/qqnt/kernel/api/impl/MsgService.java @@ -1,5 +1,6 @@ package com.tencent.qqnt.kernel.api.impl; +import com.tencent.qqnt.kernel.nativeinterface.IGetTempChatInfoCallback; import com.tencent.qqnt.kernel.nativeinterface.IKernelMsgListener; import com.tencent.qqnt.kernel.nativeinterface.IOperateCallback; import com.tencent.qqnt.kernel.nativeinterface.RichMediaFilePathInfo; @@ -24,4 +25,8 @@ public class MsgService { public void prepareTempChat(TempChatPrepareInfo tempChatPrepareInfo, IOperateCallback cb) { } + + public void getTempChatInfo(int chatType, @Nullable String uid, @Nullable IGetTempChatInfoCallback cb) { + + } } diff --git a/qqinterface/src/main/java/com/tencent/qqnt/kernel/nativeinterface/IGetTempChatInfoCallback.java b/qqinterface/src/main/java/com/tencent/qqnt/kernel/nativeinterface/IGetTempChatInfoCallback.java new file mode 100644 index 0000000..bff2a16 --- /dev/null +++ b/qqinterface/src/main/java/com/tencent/qqnt/kernel/nativeinterface/IGetTempChatInfoCallback.java @@ -0,0 +1,5 @@ +package com.tencent.qqnt.kernel.nativeinterface; + +public interface IGetTempChatInfoCallback { + void onResult(int code, String msg, TempChatInfo info); +} \ No newline at end of file diff --git a/xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/MsgSvc.kt b/xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/MsgSvc.kt index ea85f36..014df7c 100644 --- a/xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/MsgSvc.kt +++ b/xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/MsgSvc.kt @@ -9,6 +9,7 @@ import com.tencent.qqnt.kernel.nativeinterface.IOperateCallback import com.tencent.qqnt.kernel.nativeinterface.MsgConstant import com.tencent.qqnt.kernel.nativeinterface.MsgRecord import com.tencent.qqnt.kernel.nativeinterface.TempChatGameSession +import com.tencent.qqnt.kernel.nativeinterface.TempChatInfo import com.tencent.qqnt.kernel.nativeinterface.TempChatPrepareInfo import com.tencent.qqnt.msg.api.IMsgService import kotlinx.coroutines.DelicateCoroutinesApi @@ -42,9 +43,12 @@ internal object MsgSvc: BaseSvc() { msgService.prepareTempChat(TempChatPrepareInfo( MsgConstant.KCHATTYPETEMPC2CFROMGROUP, ContactHelper.getUidByUinAsync(peerId = peerId.toLong()), - app.getRuntimeService(ITroopMemberNameService::class.java, "all") - .getTroopMemberNameRemarkFirst(groupId, peerId), - groupId, EMPTY_BYTE_ARRAY, app.currentUid, "", TempChatGameSession() + app.getRuntimeService(ITroopMemberNameService::class.java, "all").getTroopMemberNameRemarkFirst(groupId, peerId), + groupId, + EMPTY_BYTE_ARRAY, + app.currentUid, + "", + TempChatGameSession() )) { code, reason -> if (code != 0) { LogCenter.log("临时会话创建失败: $code, $reason", Level.ERROR) @@ -53,6 +57,24 @@ internal object MsgSvc: BaseSvc() { return Result.success(Unit) } + suspend fun getTempChatInfo(chatType: Int, uid: String): Result { + val msgService = app.getRuntimeService(IKernelService::class.java, "all").msgService + ?: return Result.failure(Exception("获取消息服务失败")) + val info: TempChatInfo = withTimeoutOrNull(5000) { + suspendCancellableCoroutine { + msgService.getTempChatInfo(chatType, uid) { code, msg, tempChatInfo -> + if (code == 0) { + it.resume(tempChatInfo) + } else { + LogCenter.log("获取临时会话信息失败: $code:$msg", Level.ERROR) + it.resume(null) + } + } + } + } ?: return Result.failure(Exception("获取临时会话信息失败")) + return Result.success(info) + } + /** * 正常获取 */ 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 c060771..e1a2524 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 @@ -114,7 +114,9 @@ internal object GlobalEventTransmitter: BaseSvc() { rawMsg: String, msgHash: Int, postType: PostType, - tempSource: MessageTempSource = MessageTempSource.Unknown + tempSource: MessageTempSource = MessageTempSource.Unknown, + groupId: Long = Long.MIN_VALUE, + fromNick: String? = null ): Boolean { val botUin = app.longAccountUin var nickName = record.sendNickName @@ -148,7 +150,9 @@ internal object GlobalEventTransmitter: BaseSvc() { title = "", level = "", ), - tmpSource = tempSource.id + tmpSource = tempSource.id, + groupId = groupId, + fromNickName = fromNick ) ) return true 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 fbfa0b2..bc62ad8 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 @@ -52,10 +52,10 @@ internal data class MessageEvent ( @SerialName("message_type") val messageType: MsgType, @SerialName("sub_type") val subType: MsgSubType, @SerialName("message_id") val messageId: Int, - @SerialName("group_id") val groupId: Long = 0, + @SerialName("group_id") val groupId: Long = Long.MIN_VALUE, @SerialName("guild_id") val guildId: String? = null, @SerialName("channel_id") val channelId: String? = null, - @SerialName("target_id") val targetId: Long = 0, + @SerialName("target_id") val targetId: Long = Long.MIN_VALUE, @SerialName("peer_id") val peerId: Long, @SerialName("user_id") val userId: Long, @SerialName("anonymous") val anonymous: Anonymous? = null, @@ -63,7 +63,8 @@ internal data class MessageEvent ( @SerialName("raw_message") val rawMessage: String, @SerialName("font") val font: Int, @SerialName("sender") val sender: Sender, - @SerialName("temp_source") val tmpSource: Int = -1 + @SerialName("temp_source") val tmpSource: Int = Int.MIN_VALUE, + @SerialName("from_nick") val fromNickName: String? = null ) enum class MessageTempSource(val id: Int) { diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/listener/AioListener.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/listener/AioListener.kt index 8bad159..b3e318e 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/listener/AioListener.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/listener/AioListener.kt @@ -7,6 +7,7 @@ import com.tencent.qqnt.kernel.nativeinterface.* import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +import moe.fuqiuluo.qqinterface.servlet.MsgSvc import moe.fuqiuluo.qqinterface.servlet.TicketSvc import moe.fuqiuluo.qqinterface.servlet.msg.convert.toCQCode import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc @@ -119,13 +120,22 @@ internal object AioListener : IKernelMsgListener { if (!rule.white.isNullOrEmpty() && !rule.white.contains(record.senderUin)) return } + + var groupCode = 0L + var fromNick = "" + MsgSvc.getTempChatInfo(record.chatType, record.senderUid).onSuccess { + groupCode = it.groupCode.toLong() + fromNick = it.fromNick + } if (!GlobalEventTransmitter.MessageTransmitter.transPrivateMessage( record, record.elements, rawMsg, msgHash, tempSource = MessageTempSource.Group, - postType = postType + postType = postType, + groupId = groupCode, + fromNick = fromNick ) ) { LogCenter.log("私聊临时消息推送失败 -> MessageTransmitter", Level.WARN)