Add /export

This commit is contained in:
Christopher Cookman 2025-06-21 06:07:10 -06:00
parent d3bce91ba1
commit dd003a333a
4 changed files with 33 additions and 1 deletions

2
.gitignore vendored
View file

@ -126,7 +126,7 @@ dist
.yarn/install-state.gz
.pnp.*
storage/
storage/*
database.db
snowflakes.*
!storage/.gitkeep

View file

@ -77,6 +77,12 @@ const globalCommands = [
}
]
},
{
name: "export",
description: "Export the list of bad actors as a JSON file",
type: 1 // CHAT_INPUT type
},
{
name: "serverconfig",
description: "Configure server settings for bad actor management",

View file

@ -0,0 +1,26 @@
const Discord = require('discord.js');
const path = require('path');
const execute = async (interaction, db, client) => {
if (!interaction.isCommand()) return;
await interaction.deferReply({ flags: Discord.MessageFlags.Ephemeral }).catch(console.error);
db.get("SELECT * FROM badActors", async (err, row) => {
if (row) {
const now = new Date();
const pad = (n) => n.toString().padStart(2, '0');
const filename = `badActors-${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}-utc${pad(now.getUTCHours())}-${pad(now.getUTCMinutes())}.json`;
let attachments = [
{
name: filename,
attachment: Buffer.from(JSON.stringify(row, null, 2), 'utf8')
}
];
interaction.editReply({ attachments, flags: Discord.MessageFlags.Ephemeral });
} else {
interaction.editReply({ content: "Somehow... the list is empty", ephemeral: true });
}
});
}
module.exports = { execute };

0
storage/.gitkeep Normal file
View file