From eebde783eee56ed59c9bae429de1b85ed460bdbc Mon Sep 17 00:00:00 2001 From: idranme <96647698+idranme@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:02:01 +0800 Subject: [PATCH] feat(qq): support get group user avatar (#293) --- adapters/qq/src/utils.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/adapters/qq/src/utils.ts b/adapters/qq/src/utils.ts index 6f900630..19d2f4e2 100644 --- a/adapters/qq/src/utils.ts +++ b/adapters/qq/src/utils.ts @@ -34,8 +34,6 @@ export function decodeGroupMessage( payload: Universal.MessageLike = message, ) { message.id = data.id - const date = data.timestamp.slice(0, data.timestamp.indexOf('m=')).trim().replace(/\+(\d{4}) CST/, 'GMT+$1') - message.timestamp = new Date(date).valueOf() message.elements = [] if (data.content.length) message.elements.push(h.text(data.content)) for (const attachment of (data.attachments ?? [])) { @@ -53,8 +51,11 @@ export function decodeGroupMessage( } message.content = message.elements.join('') - message.guild = { id: data.group_id } - message.user = { id: data.author.id } + if (!payload) return message + const date = data.timestamp.slice(0, data.timestamp.indexOf('m=')).trim().replace(/\+(\d{4}) CST/, 'GMT+$1') + payload.timestamp = new Date(date).valueOf() + payload.guild = data.group_id && { id: data.group_id } + payload.user = { id: data.author.id, avatar: `https://q.qlogo.cn/qqapp/${bot.config.id}/${data.author.id}/640` } return message } @@ -165,15 +166,12 @@ export async function adaptSession(bot: QQBot, i session.type = 'message' session.isDirect = false decodeGroupMessage(bot, input.d, session.event.message = {}, session.event) - session.guildId = session.event.message.guild.id session.channelId = session.guildId - session.userId = session.event.message.user.id session.elements.unshift(h.at(session.selfId)) } else if (input.t === 'C2C_MESSAGE_CREATE') { session.type = 'message' session.isDirect = true decodeGroupMessage(bot, input.d, session.event.message = {}, session.event) - session.userId = input.d.author.id session.channelId = session.userId } else if (input.t === 'FRIEND_ADD') { session.type = 'friend-added'