Skip to content

Commit

Permalink
feat(qq): support to get group user avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
idranme committed Jul 12, 2024
1 parent 5e34920 commit 142bfe4
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions adapters/qq/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? [])) {
Expand All @@ -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 = { 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
}

Expand Down Expand Up @@ -165,15 +166,12 @@ export async function adaptSession<C extends Context = Context>(bot: QQBot<C>, 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'
Expand Down

0 comments on commit 142bfe4

Please sign in to comment.