Cache Pokemon Trainer Card IDs

This commit is contained in:
Dragon Fire
2021-02-11 14:25:20 -05:00
parent 19b5d6f926
commit 742bf51ddf
2 changed files with 15 additions and 10 deletions
+14
View File
@@ -1,4 +1,5 @@
const request = require('node-superfetch');
const cheerio = require('cheerio');
const path = require('path');
const { removeDuplicates, firstUpperCase, delay } = require('../../util/Util');
const missingno = require('../../assets/json/missingno');
@@ -57,6 +58,7 @@ module.exports = class Pokemon {
this.rawMoveSet = null;
this.moveSet = data.missingno ? data.moveSet : [];
this.moveSetVersion = data.missingno ? data.moveSetVersion : null;
this.trainerCardID = null;
this.gameDataCached = data.missingno || false;
this.gameDataFetching = data.missingno || false;
this.missingno = data.missingno || false;
@@ -168,6 +170,18 @@ module.exports = class Pokemon {
return this.smogonTiers;
}
async fetchCardID() {
if (this.trainerCardID) return this.trainerCardID;
const { body } = await request
.post('https://pokecharms.com/trainer-card-maker/pokemon-panels')
.attach('number', this.id)
.attach('_xfResponseType', 'json');
const $ = cheerio.load(body.templateHtml);
const id = $('li[class="Panel"]').first().attr('data-id');
this.trainerCardID = id;
return id;
}
async fetchGameData() {
if (this.gameDataCached) return this;
if (this.gameDataFetching) {