2023-11-27 00:02:34 +01:00
|
|
|
class igdb {
|
2023-11-20 23:06:54 +01:00
|
|
|
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();
|
|
|
|
}
|
2023-11-27 00:02:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
igdb
|
|
|
|
};
|