diff --git a/src/authorGen.js b/src/authorGen.js index 33be616..c5dd525 100644 --- a/src/authorGen.js +++ b/src/authorGen.js @@ -2,13 +2,24 @@ import Env from './env.js'; import axios from 'axios'; +let lastRequest = 0; const userCache = {}; -const getUser = async (id) => userCache[id] || (userCache[id] = (await axios.get(`https://discord.com/api/v9/users/${id}`, { - headers: { - 'Authorization': `Bot ${Env.discord}` +const getUser = async (id) => { + if (userCache[id]) return userCache[id]; + + while (performance.now() - 500 < lastRequest) { // Has been less than 500ms since last request + await new Promise((res) => setTimeout(res, 100)); } -})).data); + + lastRequest = performance.now(); + + return userCache[id] = (await axios.get(`https://discord.com/api/v9/users/${id}`, { + headers: { + 'Authorization': `Bot ${Env.discord}` + } + })).data; +} export default async (id) => { const user = await getUser(id); diff --git a/src/index.js b/src/index.js index cbbad83..59b6bde 100644 --- a/src/index.js +++ b/src/index.js @@ -222,7 +222,7 @@ for (const parentRepo of ModuleRepos) { manifestJson.images = await ImageCDN(manifestJson); - manifestJson.authors = await Promise.all(manifestJson.authors.map(async (x) => { + if (Array.isArray(manifestJson.authors)) manifestJson.authors = await Promise.all(manifestJson.authors.map(async (x) => { if (x.match(/^[0-9]{17,18}$/)) { return await authorGen(x); }