mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Cache Pokemon Trainer Card IDs
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user