Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Discord 适配器解码消息时,未转义文本中的 < > & #325

Open
DGCK81LNN opened this issue Oct 31, 2024 · 0 comments
Open

Comments

@DGCK81LNN
Copy link

DGCK81LNN commented Oct 31, 2024

相关代码:

if (data.content) {
message.content = data.content
.replace(/<@[!&]?(.+?)>/g, (_, id) => {
if (data.mention_roles.includes(id)) {
return h('at', { role: id }).toString()
} else {
const user = data.mentions?.find(u => u.id === id || `${u.username}#${u.discriminator}` === id)
return h.at(id, { name: user?.username }).toString()
}
})
.replace(/<a?:(.*):(.+?)>/g, (_, name, id) => {
const animated = _[1] === 'a'
return h('face', { id, name, animated, platform }, [
h.image(`https://cdn.discordapp.com/emojis/${id}.webp?quality=lossless`),
]).toString()
})
.replace(/@everyone/g, () => h('at', { type: 'all' }).toString())
.replace(/@here/g, () => h('at', { type: 'here' }).toString())
.replace(/<#(.+?)>/g, (_, id) => {
const channel = data.mention_channels?.find(c => c.id === id)
return h.sharp(id, { name: channel?.name }).toString()
})
}

b8399e47636ba7f7da19db34e39dbf59_720

897c056e24140fa3b5f146365ba7713a_720

@DGCK81LNN DGCK81LNN changed the title Bug: Discord 适配器解码消息时,未转义文本中的 < > Bug: Discord 适配器解码消息时,未转义文本中的 < > & Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant