delete button for alerts
This commit is contained in:
13
index.js
13
index.js
@@ -81,6 +81,19 @@ const commandFolders = fs.readdirSync(foldersPath);
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, async interaction => {
|
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;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
const command = interaction.client.commands.get(interaction.commandName);
|
const command = interaction.client.commands.get(interaction.commandName);
|
||||||
if (!command) {
|
if (!command) {
|
||||||
|
|||||||
@@ -25,8 +25,16 @@ module.exports = async (client, torn, config) => {
|
|||||||
const then = new Date(state.itemAlertLast);
|
const then = new Date(state.itemAlertLast);
|
||||||
const twelveHours = 12 * 60 * 60 * 1000;
|
const twelveHours = 12 * 60 * 60 * 1000;
|
||||||
if (now.getTime() - then.getTime() > twelveHours) {
|
if (now.getTime() - then.getTime() > twelveHours) {
|
||||||
|
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||||
console.debug(`unpaidOC: Sending alert`);
|
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();
|
state.itemAlertLast = now.toISOString();
|
||||||
fs.writeFile('./state.json', JSON.stringify(state, null, 4), err => {if (err) {console.error(err)}});
|
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`); }
|
} else { console.debug(`noItemOC: Would send alert, but one was sent recently`); }
|
||||||
|
|||||||
@@ -65,8 +65,16 @@ module.exports = async (client, torn, config) => {
|
|||||||
const then = new Date(state.ocAlertLast);
|
const then = new Date(state.ocAlertLast);
|
||||||
const twelveHours = 12 * 60 * 60 * 1000;
|
const twelveHours = 12 * 60 * 60 * 1000;
|
||||||
if (now.getTime() - then.getTime() > twelveHours) {
|
if (now.getTime() - then.getTime() > twelveHours) {
|
||||||
|
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||||
console.debug(`unavailableOC: Sending alert`);
|
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();
|
state.ocAlertLast = now.toISOString();
|
||||||
fs.writeFile('./state.json', JSON.stringify(state, null, 4), err => {if (err) {console.error(err)}});
|
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`); }
|
} else { console.debug(`unavailableOC: Would send alert, but one was sent recently`); }
|
||||||
|
|||||||
@@ -47,8 +47,16 @@ module.exports = async (client, torn, config) => {
|
|||||||
const then = new Date(state.payoutAlertLast);
|
const then = new Date(state.payoutAlertLast);
|
||||||
const twelveHours = 12 * 60 * 60 * 1000;
|
const twelveHours = 12 * 60 * 60 * 1000;
|
||||||
if (now.getTime() - then.getTime() > twelveHours) {
|
if (now.getTime() - then.getTime() > twelveHours) {
|
||||||
|
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||||
console.debug(`unpaidOC: Sending alert`);
|
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();
|
state.payoutAlertLast = now.toISOString();
|
||||||
fs.writeFile('./state.json', JSON.stringify(state, null, 4), err => {if (err) {console.error(err)}});
|
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`); }
|
} else { console.debug(`unpaidOC: Would send alert, but one was sent recently`); }
|
||||||
|
|||||||
Reference in New Issue
Block a user