feature/verify-submit ()

Bot will check the roblox account linked to the user's discord account (via verify.eryn.io) when submitting a map. If the user does not own the model they are trying to submit they can't submit it.

Co-authored-by: Carter Penterman <carterpenterman@gmail.com>
Reviewed-on: 
Co-authored-by: fiveman1 <fiveman1@noreply@itzana.me>
Co-committed-by: fiveman1 <fiveman1@noreply@itzana.me>
This commit is contained in:
2022-07-12 02:09:07 +00:00
committed by itzaname
parent a2759ae0e4
commit 630b4f07b9
5 changed files with 39 additions and 1 deletions

@ -2,8 +2,35 @@ const { SlashCommandBuilder } = require('@discordjs/builders');
const { parse } = require("csv-parse/sync");
const fs = require('node:fs');
const noblox = require("noblox.js");
const axios = require("axios").default
async function robloxUserFromDiscord(id) {
if (isNaN(id)) return undefined;
try {
const res = await axios.get(`https://verify.eryn.io/api/user/${id}`)
return res.data.robloxId
} catch (error) {
return undefined;
}
}
async function robloxUsernameFromId(id) {
if (isNaN(id)) return undefined;
try {
const res = await axios.get(`https://users.roblox.com/v1/users/${id}`)
return res.data.name
} catch (error) {
return undefined;
}
}
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. Visit https://verify.eryn.io/";
await interaction.reply({content: msg, ephemeral: true});
return;
}
const game = interaction.options.getString("game");
let fname;
@ -26,6 +53,13 @@ async function execute(interaction) {
await interaction.reply({content: `(id: ${id}) is not a valid model ID.`, ephemeral: true});
return;
}
if (info.Creator.Id != userId) {
const assetUsername = await robloxUsernameFromId(info.Creator.Id);
const interactionUsername = await robloxUsernameFromId(userId);
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
}
} catch (error) {
console.log(error);
await interaction.reply({content: `There is a problem with this asset ID (id: ${id}).`, ephemeral: true});