Add /export
This commit is contained in:
parent
d3bce91ba1
commit
dd003a333a
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -126,7 +126,7 @@ dist
|
|||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
storage/
|
||||
storage/*
|
||||
database.db
|
||||
snowflakes.*
|
||||
!storage/.gitkeep
|
|
@ -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",
|
||||
|
|
26
interactions/commands/export.js
Normal file
26
interactions/commands/export.js
Normal 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
0
storage/.gitkeep
Normal file
Loading…
Reference in a new issue