Parse map models and validate them ()

The enhancements:
- Added map validation that checks for some common errors that maps have
- /take: Does map validation but will still take the map even if there are problems
- /take: Improved the help text and added links to the maptest places
- /submit: Does map validation and will not let you submit if there are problems
- /submissions: Now shows the map's display name and creator
- Added an ESLint config and tidied some things up
- Updated some of the packages

Reviewed-on: 
Co-authored-by: Carter Penterman <carterpenterman@gmail.com>
Co-committed-by: Carter Penterman <carterpenterman@gmail.com>
This commit is contained in:
2024-04-24 06:28:07 +00:00
committed by Quaternions
parent f8476577d6
commit 3a167cf686
8 changed files with 267 additions and 45 deletions

@ -1,17 +1,20 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const noblox = require("noblox.js");
const { cookies, commands } = require("../config/config.js");
const { AssetType, getAssetInfo } = require("../common.js");
const { cookies, commands, gamePlaces } = require("../config/config.js");
const { AssetType, getAssetInfo, validateMapAsset, getValidationMessage } = require("../common.js");
/**
* @param {import('discord.js').ChatInputCommandInteraction} interaction
*/
async function execute(interaction) {
const game = interaction.options.getString("game");
const game = interaction.options.getString("game", true);
const cookie = cookies[game];
if (cookie === undefined) {
await interaction.reply({content: "Invalid game specified!", ephemeral: true});
return;
}
const id = interaction.options.getInteger("asset_id");
const id = interaction.options.getInteger("asset_id", true);
await noblox.setCookie(cookie);
// Check that the bot doesn't already own this asset
if (await noblox.getOwnership(await noblox.getCurrentUser("UserID"), id, "Asset")) {
@ -46,16 +49,23 @@ async function execute(interaction) {
Creator: {
Id: assetInfo.creatorId
}
}
};
await noblox.buy({product: productInfo, price: 0});
await interaction.reply(
const buyPromise = noblox.buy({product: productInfo, price: 0});
const mapValidatePromise = validateMapAsset(id, game);
const message = await interaction.reply("⌛ Validating map...");
const validation = await mapValidatePromise;
const msg = getValidationMessage(validation, game, false);
await message.edit(msg);
await buyPromise;
await interaction.followUp(
`
Now that your map (id: ${id}) has been taken by the ${game} maptest bot you can load it into the ${game} maptest place. To load your map, join the game and say
\`\`\`
!map ${id}
\`\`\`Read what it says. If your map successfully loaded type !rtv and then choose your map.
If it did not load successfully, you can expand the chat to view the full error message by clicking and dragging on the edge of the chat.
Now that your [map (id: ${id})](<https://create.roblox.com/store/asset/${id}/>) has been taken by the bot you can load it into the [${game} maptest place](<${gamePlaces[game]}>).
To load your map, join the game and do \`!map ${id}\`. If your map successfully loaded, do \`!rtv\` and then choose your map.
Otherwise, you can expand the chat to view the full error message by clicking and dragging on the edge of the chat.
`
);
}