[AuthorGen] Add ratelimit, fix trying to use on authors not array
This commit is contained in:
parent
ea51962e77
commit
c349fd6ccc
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue