diff --git a/index.js b/index.js index 8efd310..bf4c72a 100644 --- a/index.js +++ b/index.js @@ -81,6 +81,19 @@ const commandFolders = fs.readdirSync(foldersPath); } client.on(Events.InteractionCreate, async interaction => { + if (interaction.isButton()) { + if (interaction.customId === 'delete_message') { + try { + await interaction.message.delete(); + console.debug('Interaction: Deleted message via button.'); + } catch (error) { + console.error('Interaction: Error deleting message:', error); + await interaction.reply({ content: 'There was an error trying to delete this message.', ephemeral: true }); + } + } + return; + } + if (!interaction.isChatInputCommand()) return; const command = interaction.client.commands.get(interaction.commandName); if (!command) { diff --git a/tasks/noItemOC.js b/tasks/noItemOC.js index 6639e8e..f4cda49 100644 --- a/tasks/noItemOC.js +++ b/tasks/noItemOC.js @@ -25,8 +25,16 @@ module.exports = async (client, torn, config) => { const then = new Date(state.itemAlertLast); const twelveHours = 12 * 60 * 60 * 1000; if (now.getTime() - then.getTime() > twelveHours) { + const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); console.debug(`unpaidOC: Sending alert`); - channel.send(message); + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('delete_message') + .setLabel('Click when sorted') + .setStyle(ButtonStyle.Success), + ); + channel.send({ content: message, components: [row] }); state.itemAlertLast = now.toISOString(); fs.writeFile('./state.json', JSON.stringify(state, null, 4), err => {if (err) {console.error(err)}}); } else { console.debug(`noItemOC: Would send alert, but one was sent recently`); } diff --git a/tasks/unavailableOC.js b/tasks/unavailableOC.js index ae466be..2b540dc 100644 --- a/tasks/unavailableOC.js +++ b/tasks/unavailableOC.js @@ -65,8 +65,16 @@ module.exports = async (client, torn, config) => { const then = new Date(state.ocAlertLast); const twelveHours = 12 * 60 * 60 * 1000; if (now.getTime() - then.getTime() > twelveHours) { + const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); console.debug(`unavailableOC: Sending alert`); - channel.send({ embeds: [embed] }); + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('delete_message') + .setLabel('Click when sorted') + .setStyle(ButtonStyle.Success), + ); + channel.send({ embeds: [embed], components: [row] }); state.ocAlertLast = now.toISOString(); fs.writeFile('./state.json', JSON.stringify(state, null, 4), err => {if (err) {console.error(err)}}); } else { console.debug(`unavailableOC: Would send alert, but one was sent recently`); } diff --git a/tasks/unpaidOC.js b/tasks/unpaidOC.js index 754c513..4f5a2d1 100644 --- a/tasks/unpaidOC.js +++ b/tasks/unpaidOC.js @@ -47,8 +47,16 @@ module.exports = async (client, torn, config) => { const then = new Date(state.payoutAlertLast); const twelveHours = 12 * 60 * 60 * 1000; if (now.getTime() - then.getTime() > twelveHours) { + const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); console.debug(`unpaidOC: Sending alert`); - channel.send({content: "# Unpaid Faction Crimes:", embeds: embeds }); + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('delete_message') + .setLabel('Click when sorted') + .setStyle(ButtonStyle.Success), + ); + channel.send({content: "# Unpaid Faction Crimes:", embeds: embeds, components: [row] }); state.payoutAlertLast = now.toISOString(); fs.writeFile('./state.json', JSON.stringify(state, null, 4), err => {if (err) {console.error(err)}}); } else { console.debug(`unpaidOC: Would send alert, but one was sent recently`); }