-
-
Notifications
You must be signed in to change notification settings - Fork 4k
fix: regression in allowedMentions when replying #10866
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
70d4718
fix: regression in allowedMentions
Qjuh 256a7a7
fix: lint
Qjuh 49fddd5
fix: jsdoc
Qjuh 7fe83be
tests: added a manual regression test
Qjuh af3dee3
fix: lint
Qjuh be1667e
fix: tests
Qjuh d01f69d
fix: tests
Qjuh da66cb6
fix: typo
Qjuh 190bb8b
fix: typings test
Qjuh 6e4a459
chore: bumo zlib-sync to not crash on mac
Qjuh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/lintstagedrc.schema.json", | ||
"*": "prettier --ignore-unknown --write", | ||
"{src/**,test/**,typings/**,scripts/**}.{mjs,js,ts}": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint --ext mjs,js,ts --fix" | ||
"{src/**,typings/**,scripts/**}.{mjs,js,ts}": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint --ext mjs,js,ts --fix" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
'use strict'; | ||
|
||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
const { setTimeout: sleep } = require('node:timers/promises'); | ||
const util = require('node:util'); | ||
const { fetch } = require('undici'); | ||
const { Client, GatewayIntentBits, AttachmentBuilder, EmbedBuilder, MessageFlags } = require('../src'); | ||
|
||
const client = new Client({ | ||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent], | ||
}); | ||
|
||
const buffer = l => | ||
fetch(l) | ||
.then(res => res.arrayBuffer()) | ||
.then(Buffer.from); | ||
const read = util.promisify(fs.readFile); | ||
const readStream = fs.createReadStream; | ||
|
||
const linkA = 'https://lolisafe.moe/iiDMtAXA.png'; | ||
const linkB = 'https://lolisafe.moe/9hSpedPh.png'; | ||
const fileA = path.join(__dirname, 'blobReach.png'); | ||
|
||
const embed = () => new EmbedBuilder(); | ||
const attach = (attachment, name) => new AttachmentBuilder(attachment, { name }); | ||
|
||
const tests = [ | ||
m => m.channel.send('x'), | ||
|
||
m => m.channel.send('x', { code: true }), | ||
m => m.channel.send('1', { code: 'js' }), | ||
m => m.channel.send('x', { code: '' }), | ||
Qjuh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
m => m.channel.send('x', { content: 'x', embeds: [{ description: 'a' }] }), | ||
m => m.channel.send({ embeds: [{ description: 'a' }] }), | ||
m => m.channel.send({ files: [{ attachment: linkA }] }), | ||
m => | ||
m.channel.send({ | ||
embeds: [{ description: 'a' }], | ||
files: [{ attachment: linkA, name: 'xyz.png' }], | ||
}), | ||
|
||
m => m.channel.send({ content: 'x', embeds: [embed().setDescription('a')] }), | ||
m => m.channel.send({ embeds: [embed().setDescription('a')] }), | ||
m => m.channel.send({ embeds: [embed().setDescription('a'), embed().setDescription('b')] }), | ||
|
||
m => m.channel.send({ content: 'x', files: [attach(linkA)] }), | ||
m => m.channel.send({ files: [linkA] }), | ||
m => m.channel.send({ files: [attach(linkA)] }), | ||
async m => m.channel.send({ files: [await buffer(linkA)] }), | ||
async m => m.channel.send({ files: [{ attachment: await buffer(linkA) }] }), | ||
m => m.channel.send({ files: [attach(linkA), attach(linkB)] }), | ||
|
||
m => m.channel.send({ embeds: [{ description: 'a' }] }).then(m2 => m2.edit('x')), | ||
m => m.channel.send({ embeds: [embed().setDescription('a')] }).then(m2 => m2.edit('x')), | ||
|
||
m => m.channel.send('x').then(m2 => m2.edit({ embeds: [{ description: 'a' }] })), | ||
m => m.channel.send('x').then(m2 => m2.edit({ embeds: [embed().setDescription('a')] })), | ||
|
||
m => m.channel.send({ embeds: [{ description: 'a' }] }).then(m2 => m2.edit({ embeds: [] })), | ||
m => m.channel.send({ embeds: [embed().setDescription('a')] }).then(m2 => m2.edit({ embeds: [] })), | ||
|
||
m => m.channel.send({ content: 'x', embeds: [embed().setDescription('a')], files: [attach(linkB)] }), | ||
m => m.channel.send({ content: 'x', files: [attach(linkA), attach(linkB)] }), | ||
|
||
m => m.channel.send({ embeds: [embed().setDescription('a')], files: [attach(linkB)] }), | ||
m => | ||
m.channel.send({ | ||
embeds: [embed().setImage('attachment://two.png')], | ||
files: [attach(linkB, 'two.png')], | ||
}), | ||
m => m.channel.send({ content: 'x', files: [attach(fileA)] }), | ||
m => m.channel.send({ files: [fileA] }), | ||
m => m.channel.send({ files: [attach(fileA)] }), | ||
async m => m.channel.send({ files: [await read(fileA)] }), | ||
|
||
m => m.channel.send({ content: 'x', files: [attach(readStream(fileA))] }), | ||
m => m.channel.send({ files: [readStream(fileA)] }), | ||
m => m.channel.send({ files: [{ attachment: readStream(fileA) }] }), | ||
|
||
m => m.reply({ content: 'x', allowedMentions: { repliedUser: false } }), | ||
m => m.reply({ content: 'x', allowedMentions: { repliedUser: true } }), | ||
m => m.reply({ content: 'x' }), | ||
m => m.reply({ content: `${m.author}`, allowedMentions: { repliedUser: false } }), | ||
m => m.reply({ content: `${m.author}`, allowedMentions: { parse: ['users'], repliedUser: false } }), | ||
m => m.reply({ content: `${m.author}`, allowedMentions: { parse: ['users'], repliedUser: true } }), | ||
m => m.reply({ content: `${m.author}` }), | ||
|
||
m => m.edit({ flags: MessageFlags.SuppressEmbeds }), | ||
m => m.edit({ flags: MessageFlags.SuppressEmbeds, allowedMentions: { repliedUser: false } }), | ||
|
||
m => | ||
m | ||
.reply({ content: 'x', allowedMentions: { repliedUser: false } }) | ||
.then(msg => msg.edit({ content: 'a', allowedMentions: { repliedUser: true } })), | ||
|
||
m => m.channel.send('Done!'), | ||
]; | ||
|
||
client.on('messageCreate', async message => { | ||
if (message.author.id !== process.env.OWNER) return; | ||
const match = message.content.match(/^do (.+)$/); | ||
if (match?.[1] === 'it') { | ||
/* eslint-disable no-await-in-loop */ | ||
for (const [i, test] of tests.entries()) { | ||
await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``); | ||
await test(message).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``)); | ||
await sleep(1_000); | ||
} | ||
/* eslint-enable no-await-in-loop */ | ||
} else if (match) { | ||
const n = parseInt(match[1]) || 0; | ||
const test = tests.slice(n)[0]; | ||
const i = tests.indexOf(test); | ||
await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``); | ||
await test(message).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``)); | ||
} | ||
}); | ||
|
||
client.login(); | ||
|
||
// eslint-disable-next-line no-console | ||
process.on('unhandledRejection', console.error); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.