Skip to content

Commit

Permalink
hotfix: check for embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
everettsouthwick committed Aug 27, 2023
1 parent 88c2975 commit 3f2624b
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/utils/handleLinkResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ async function sendReplyModeMessage(messageOrInteraction, links, embeds) {
new ButtonBuilder().setCustomId('keep').setLabel('Keep').setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('delete').setLabel('Delete').setStyle(ButtonStyle.Danger),
)];
const options = { content: links.join('\n'), embeds: embeds.length ? embeds : undefined, components };
const options = { content: links.join('\n'), embeds: embeds.length ? embeds : undefined, components: embeds.length ? components : undefined };
const response = await messageOrInteraction.reply(options);

if (!isInteraction && !(await checkForEmbed(response, embeds))) return await response.delete();
if (!isInteraction) await response.edit({ components });
if (!isInteraction) {
try {
await checkForEmbed(response);
await response.edit({ components: components });
}
catch (e) {
await response.delete();
}
}

const collector = response.createMessageComponentCollector({ componentType: ComponentType.Button, time: 180000 });
collector.on('collect', async (i) => {
if (i.customId === 'keep') return collector.stop() && await response.edit({ components: [] });
if (i.user.id !== userId && !i.member.permissions.has(PermissionsBitField.Flags.ManageMessages)) return await i.reply({ content: 'You are not authorized to delete this message.', ephemeral: true });
await response.delete() && await collector.stop();
await collector.stop();
await response.delete();
});
collector.on('end', async () => await response.edit({ components: [] }).catch(() => {}));
}
Expand All @@ -49,10 +57,16 @@ async function sendAskModeMessage(message, links, embeds) {
async function checkForEmbed(message) {
if (message.content.includes('archive.today')) return Promise.resolve(true);
const startTime = Date.now();
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
const check = setInterval(() => {
if (message.embeds.length) return clearInterval(check) && resolve(true);
if (Date.now() - startTime > 10000) return clearInterval(check) && resolve(false);
if (message.embeds.length) {
clearInterval(check);
resolve(true);
}
if (Date.now() - startTime > 10000) {
clearInterval(check);
reject(false);
}
}, 200);
});
}
Expand Down

0 comments on commit 3f2624b

Please sign in to comment.