@ -4,7 +4,7 @@ const fs = require('node:fs');
|
||||
const noblox = require("noblox.js");
|
||||
const axios = require("axios").default;
|
||||
const { submissions, commands, cookies } = require("../config/config.js");
|
||||
const { AssetType, getAssetInfo } = require("../common.js");
|
||||
const { AssetType, getAssetInfo, SubmissionColumnsString, createSubmissionLine, getSubmissionLine } = require("../common.js");
|
||||
|
||||
async function robloxUserFromDiscord(id) {
|
||||
if (isNaN(id)) return undefined;
|
||||
@ -42,7 +42,7 @@ async function execute(interaction) {
|
||||
}
|
||||
|
||||
if (!fs.existsSync(fname)) {
|
||||
fs.writeFileSync(fname, "id,timestamp\n");
|
||||
fs.writeFileSync(fname, SubmissionColumnsString);
|
||||
}
|
||||
|
||||
const id = interaction.options.getInteger("asset_id");
|
||||
@ -71,24 +71,24 @@ async function execute(interaction) {
|
||||
return;
|
||||
}
|
||||
|
||||
const csv = fs.readFileSync(fname);
|
||||
const records = parse(csv, {delimiter: ',', fromLine: 2});
|
||||
const csvFile = fs.readFileSync(fname);
|
||||
const lines = parse(csvFile, {delimiter: ',', fromLine: 2});
|
||||
|
||||
let s = "id,timestamp\n";
|
||||
for (let record of records) {
|
||||
const rid = record[0];
|
||||
const rtimestamp = record[1];
|
||||
if (id === rid) {
|
||||
await interaction.reply({content: `This map (id: ${id}) was already submitted on <t:${rtimestamp}:d>.`, ephemeral: true});
|
||||
let csvString = SubmissionColumnsString;
|
||||
for (let lineStr of lines) {
|
||||
const line = getSubmissionLine(lineStr);
|
||||
|
||||
if (id === line.modelId) {
|
||||
await interaction.reply({content: `This map (id: ${id}) was already submitted on <t:${line.timestamp}:d>.`, ephemeral: true});
|
||||
return;
|
||||
}
|
||||
s += `${rid},${rtimestamp}\n`;
|
||||
|
||||
csvString += createSubmissionLine(line.modelId, line.timestamp, line.userId, line.username);
|
||||
}
|
||||
|
||||
const unix = Math.round(+new Date()/1000);
|
||||
s += `${id},${unix}\n`;
|
||||
|
||||
fs.writeFileSync(fname, s);
|
||||
const unixTimestamp = Math.round(+new Date()/1000);
|
||||
csvString += createSubmissionLine(id, unixTimestamp, userId, await robloxUsernameFromId(userId));
|
||||
fs.writeFileSync(fname, csvString);
|
||||
|
||||
await interaction.reply(`Map (id: ${id}) successfully submitted.`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user