diff --git a/.gitignore b/.gitignore index 39b077c..fc61b86 100644 --- a/.gitignore +++ b/.gitignore @@ -126,7 +126,7 @@ dist .yarn/install-state.gz .pnp.* -storage/ +storage/* database.db snowflakes.* !storage/.gitkeep \ No newline at end of file diff --git a/commands.js b/commands.js index 0c117b6..dff6a21 100644 --- a/commands.js +++ b/commands.js @@ -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", diff --git a/interactions/commands/export.js b/interactions/commands/export.js new file mode 100644 index 0000000..33d5712 --- /dev/null +++ b/interactions/commands/export.js @@ -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 }; \ No newline at end of file diff --git a/storage/.gitkeep b/storage/.gitkeep new file mode 100644 index 0000000..e69de29