48 lines
2.4 KiB
JavaScript
48 lines
2.4 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const execute = async (interaction, db, client) => {
|
|
if (!interaction.isCommand()) return;
|
|
await interaction.deferReply({ ephemeral: true }).catch(console.error);
|
|
|
|
db.get("SELECT * FROM badActors WHERE id = ?", [interaction.options.getUser("user").id], async (err, row) => {
|
|
if (err) {
|
|
console.error("Database error:", err);
|
|
return interaction.editReply({ content: "An error occurred while accessing the database.", ephemeral: true });
|
|
}
|
|
if (row) {
|
|
const user = interaction.options.getUser("user").id;
|
|
const confirmation = interaction.options.getString("confirmation");
|
|
|
|
if (confirmation !== "yes im absolutely sure") {
|
|
return interaction.editReply({ content: "You must type 'yes im absolutely sure' to confirm removal.", ephemeral: true });
|
|
}
|
|
|
|
db.run("DELETE FROM badActors WHERE id = ?", [user], function (err) {
|
|
if (err) {
|
|
console.error("Database error:", err);
|
|
return interaction.editReply({ content: "An error occurred while removing the user from the list.", ephemeral: true });
|
|
}
|
|
row.attachments = JSON.parse(row.attachments || "[]");
|
|
if (row.attachments && Array.isArray(row.attachments)) {
|
|
for (const filePath of row.attachments) {
|
|
fs.unlink(path.join(__dirname, "../../storage", filePath), (err) => {
|
|
if (err) {
|
|
console.error(`Failed to delete attachment: ${filePath}`, err);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
interaction.editReply({ content: `User <@${user}> has been removed from the bad actors list.`, ephemeral: true });
|
|
client.channels.fetch(process.env.ADMIN_LOG_CHANNEL).then(logChan => {
|
|
logChan.send({
|
|
content: `User <@${user}> has been removed from the bad actors list by <@${interaction.user.id}>.`
|
|
}).catch(console.error);
|
|
})
|
|
});
|
|
} else {
|
|
return interaction.editReply({ content: "That user is not listed as a bad actor.", ephemeral: true });
|
|
}
|
|
});
|
|
}
|
|
module.exports = { execute }; |