maptest-bot/commands/submissions.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-05-13 17:01:16 +00:00
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageAttachment } = require("discord.js");
const fs = require('node:fs');
const { submissions, commands } = require("../config/config.js")
2022-05-13 17:01:16 +00:00
async function execute(interaction) {
const game = interaction.options.getString("game");
const fname = submissions[game];
if (fname === undefined) {
2022-05-13 17:01:16 +00:00
await interaction.reply({content: "Invalid game specified!", ephemeral: true});
return;
}
if (!fs.existsSync(fname)) {
await interaction.reply(`No submissions exist yet for ${game}.`);
return;
}
const csv = fs.readFileSync(fname);
const file = new MessageAttachment(csv, fname);
await interaction.reply({files: [file]});
}
module.exports = {
data: new SlashCommandBuilder()
.setName('submissions')
.setDescription('View the submissions in .csv format')
.addStringOption(option =>
option.setName("game")
.setDescription("Select the maptest game")
.setRequired(true)
.addChoices(commands))
2022-05-13 17:01:16 +00:00
,
execute
};