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);
|
2023-12-01 00:38:01 +01:00
|
|
|
this.makeClientCred();
|
2023-11-20 23:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
makeClientCred() {
|
2023-12-01 00:38:01 +01:00
|
|
|
console.log('Making a token');
|
2023-11-20 23:06:54 +01:00
|
|
|
|
|
|
|
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 = {
|
2023-12-01 00:38:01 +01:00
|
|
|
igdb,
|
2023-11-27 00:02:34 +01:00
|
|
|
};
|