Created
June 1, 2020 11:48
-
-
Save Neztore/64b8d8dc3fd89c0038c8b37da032b8f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fetch = require("node-fetch"); | |
| // Variables | |
| let noMade = 0; | |
| let cache = {}; | |
| let disabled = false; | |
| let since = Date.now(); | |
| // Clear your cache | |
| setInterval(function () { | |
| cache = {} | |
| }, 300000) | |
| // returns false for failure | |
| // Returns { error: { status: number, message: string } } for other error | |
| // Returns { robloxId: number, discordId: string } for successful retrieval | |
| async function getLink(discordId) { | |
| if (cache[discordId]) { | |
| return cache[discordId]; | |
| } | |
| if (disabled) return false; | |
| if (noMade >= 59 && (Date.now() - since) < 60000) { | |
| // If more than 60 made and within 60 seconds -- too fast | |
| console.log("Local ratelimit hit!") | |
| return false; | |
| } else if ( (Date.now() - since) > 60000) { | |
| noMade = 0 | |
| since = Date.now() | |
| } | |
| noMade++ | |
| const prom = await fetch(`https://verify.nezto.re/api/roblox/${discordId}`); | |
| const res = await prom.json(); | |
| if (res.error) { | |
| if (res.error.status === 429) { | |
| // Handle rate limit error | |
| console.error(`Hit ratelimit!`); | |
| disabled = true | |
| setTimeout(function () { | |
| disabled = false | |
| }, (res.error.retryAfter + 2)) | |
| } | |
| return res | |
| } else { | |
| const ret = { | |
| robloxId: res.robloxId, | |
| discordId: discordId, | |
| } | |
| cache[discordId] = ret; | |
| return ret; | |
| } | |
| } | |
| module.exports = getLink; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment