Skip to content

Commit

Permalink
Merge pull request #6 from everettsouthwick/feature/button-on-embed
Browse files Browse the repository at this point in the history
change logic to allow deletion of bot message
  • Loading branch information
everettsouthwick authored Jul 4, 2023
2 parents 0ca4948 + 0fc9609 commit c1b161c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/commands/context/utility/embed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { ContextMenuCommandBuilder, ApplicationCommandType } = require('discord.js');
const replaceLink = require('../../../utils/linkReplacer.js');
const { sendReplyModeMessage } = require('../../../utils/handleLinkMessage.js');

module.exports = {
data: new ContextMenuCommandBuilder()
Expand All @@ -8,8 +9,7 @@ module.exports = {
async execute(interaction) {
const { links } = replaceLink(interaction.targetMessage.content);
if (links.length > 0) {
// If there are multiple links, join them with a newline for readability
interaction.reply(links.join('\n'));
sendReplyModeMessage(interaction.targetMessage, links);
}
else {
interaction.reply('No valid link was found.');
Expand Down
2 changes: 1 addition & 1 deletion src/events/messageCreate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Events } = require('discord.js');
const handleLinkMessage = require('../utils/handleLinkMessage.js');
const { handleLinkMessage } = require('../utils/handleLinkMessage.js');

module.exports = {
name: Events.MessageCreate,
Expand Down
19 changes: 12 additions & 7 deletions src/utils/handleLinkMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const sendReplaceModeMessage = async (message, fullMessage) => {
const sendReplyModeMessage = async (message, links) => {
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Delete original message')
.setLabel('Delete')
.setStyle(ButtonStyle.Danger);

const cancel = new ButtonBuilder()
Expand All @@ -32,7 +32,7 @@ const sendReplyModeMessage = async (message, links) => {
await confirmation.update({ components: [] });

if (confirmation.customId === 'confirm') {
await message.delete();
await response.delete();
}
} catch (e) {
// Do nothing
Expand Down Expand Up @@ -61,19 +61,19 @@ const sendManualModeMessage = async (message, links) => {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60000 });
if (confirmation.customId === 'confirm') {
sendReplyModeMessage(message, links);
await confirmation.update({ content: `The link has been embedded.`, components: [] });
await confirmation.update({ components: [] });
await response.delete();
} else if (confirmation.customId === 'cancel') {
await confirmation.update({ content: `The link will not be embedded.`, components: [] });
await confirmation.update({ components: [] });
await response.delete();
}
} catch (e) {
await response.edit({ content: 'Confirmation not received in 1 minute, cancelling.', components: [] });
await response.edit({ components: [] });
await response.delete();
}
};

module.exports = async (message) => {
const handleLinkMessage = async (message) => {
const { fullMessage, links } = replaceLink(message.content);
if (links.length > 0) {
getGuildMode(message.guildId, async (mode) => {
Expand All @@ -88,4 +88,9 @@ module.exports = async (message) => {
}
});
}
};
}

module.exports = {
sendReplyModeMessage,
handleLinkMessage
};

0 comments on commit c1b161c

Please sign in to comment.