Log errors to a channel and also fix/improve error handling

This commit is contained in:
2024-04-25 12:33:55 -05:00
parent 1a1019b37b
commit 9cb8c24e58
7 changed files with 95 additions and 52 deletions

@ -32,15 +32,14 @@ async function robloxUsernameFromId(id) {
async function execute(interaction) {
const userId = await robloxUserFromDiscord(interaction.user.id);
if (!userId) {
const msg = "You don't have a Roblox account linked with your Discord account. Use !link with the rbhop dog bot to link your account.";
await interaction.reply({content: msg, ephemeral: true});
await interaction.editReply("🚫 You don't have a Roblox account linked with your Discord account. Use !link with the rbhop dog bot to link your account.");
return;
}
const game = interaction.options.getString("game", true);
const game = interaction.options.getString("game", true);
const fname = submissions[game];
if (fname === undefined) {
await interaction.reply({content: "Invalid game specified!", ephemeral: true});
await interaction.editReply("🚫 Invalid game specified!");
return;
}
@ -51,28 +50,39 @@ async function execute(interaction) {
const id = interaction.options.getInteger("asset_id", true);
await noblox.setCookie(cookies[game]);
// Check that the bot owns this model
if (!(await noblox.getOwnership(await noblox.getCurrentUser("UserID"), id, "Asset"))) {
const msg = `The ${game} maptest bot's inventory does not contain this asset (id: ${id}). You must use the /take command first.`;
await interaction.reply({content: msg, ephemeral: true});
try {
// Check that the bot owns this model
if (!(await noblox.getOwnership(await noblox.getCurrentUser("UserID"), id, "Asset"))) {
const msg = `🚫 The ${game} maptest bot's inventory does not contain this asset (id: ${id}). You must use the /take command first.`;
await interaction.editReply(msg);
return;
}
} catch (error) {
if (error.message !== "400 The specified Asset does not exist!") {
throw error;
}
await interaction.editReply(`🚫 This asset does not exist (id: ${id}).`);
return;
}
const assetInfo = await getAssetInfo(id);
if (assetInfo.typeId !== AssetType.Model) {
await interaction.editReply(`🚫 This asset (id: ${id}) is not a model. Your map must be a model.`);
return;
}
if (assetInfo.creatorId !== userId) {
const assetUsernamePromise = robloxUsernameFromId(assetInfo.creatorId);
const interactionUsernamePromise = robloxUsernameFromId(userId);
const assetUsername = await assetUsernamePromise;
const interactionUsername = await interactionUsernamePromise;
const msg = `The account linked to your Discord (${interactionUsername}) is not the owner of this model (${assetUsername}), so you cannot submit it.`;
await interaction.reply({content: msg, ephemeral: true});
return;
}
// Shouldn't really be possible but who knows...
if (assetInfo.typeId !== AssetType.Model) {
await interaction.reply({content: `This asset (id: ${id}) is not a model. Your map must be a model.`, ephemeral: true});
const msg = `🚫 The account linked to your Discord (${interactionUsername}) is not the owner of this model (${assetUsername}), so you cannot submit it.`;
await interaction.editReply(msg);
return;
}
const csvFile = fs.readFileSync(fname);
const lines = parse(csvFile, {delimiter: ',', fromLine: 2});
@ -80,14 +90,11 @@ async function execute(interaction) {
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});
await interaction.editReply(`🚫 This map (id: ${id}) was already submitted on <t:${line.timestamp}:d>.`);
return;
}
}
// Show "Bot is thinking..."
await interaction.deferReply();
// Validate and send the validation result
const validation = await validateMapAsset(id, game);
const msg = getValidationMessage(validation, game, true);