From 107fb6973011672ed1738190f502442eb88baade Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 20 Nov 2023 22:06:54 +0000 Subject: [PATCH] Create igdb class --- igdb.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 igdb.js diff --git a/igdb.js b/igdb.js new file mode 100644 index 0000000..81235cb --- /dev/null +++ b/igdb.js @@ -0,0 +1,32 @@ +export class igdb { + constructor() { + // make a new token every day + setInterval(() => { + this.makeClientCred(); + }, 86000000); + this.makeClientCred() + } + + makeClientCred() { + console.log("Making a token"); + + fetch( + `https://id.twitch.tv/oauth2/token?client_id=${process.env.igdbClientId}&client_secret=${process.env.igdbClientSecret}&grant_type=client_credentials`, + { + method: 'POST', + }, + ) + .then(r => r.json().then(data => ({ status: r.status, headers: r.headers, body: data }))) + .then(resp => { + if (resp.status != 200) { + console.log('Failed with ', resp.status, resp.body); + return; + } + process.env.igdbAccessToken = resp.body.access_token; + }) + .catch(err => { + console.error(err); + }) + .finally(); + } +} \ No newline at end of file