[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';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
let lastRequest = 0;
|
||||||
const userCache = {};
|
const userCache = {};
|
||||||
|
|
||||||
const getUser = async (id) => userCache[id] || (userCache[id] = (await axios.get(`https://discord.com/api/v9/users/${id}`, {
|
const getUser = async (id) => {
|
||||||
headers: {
|
if (userCache[id]) return userCache[id];
|
||||||
'Authorization': `Bot ${Env.discord}`
|
|
||||||
|
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) => {
|
export default async (id) => {
|
||||||
const user = await getUser(id);
|
const user = await getUser(id);
|
||||||
|
|
|
@ -222,7 +222,7 @@ for (const parentRepo of ModuleRepos) {
|
||||||
|
|
||||||
manifestJson.images = await ImageCDN(manifestJson);
|
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}$/)) {
|
if (x.match(/^[0-9]{17,18}$/)) {
|
||||||
return await authorGen(x);
|
return await authorGen(x);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue