mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 14:19:56 +02:00
Data Dragon
This commit is contained in:
@@ -25,31 +25,18 @@ module.exports = class LeagueOfLegendsChampionCommand extends Command {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.version = null;
|
this.version = null;
|
||||||
this.champions = null;
|
this.client.setInterval(() => this.version = null, 3600000);
|
||||||
this.cache = new Map();
|
|
||||||
this.client.setInterval(() => this.cache.clear(), 3600000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { champion }) {
|
async run(msg, { champion }) {
|
||||||
if (champion === 'satan') champion = 'teemo';
|
if (champion === 'satan') champion = 'teemo';
|
||||||
try {
|
try {
|
||||||
let data;
|
if (!this.version) await this.fetchVersion();
|
||||||
if (!this.cache.has(champion)) {
|
const { body } = await snekfetch
|
||||||
if (!this.champions) await this.fetchChampions();
|
.get(`https://ddragon.leagueoflegends.com/cdn/${this.version}/data/en_US/champion.json`);
|
||||||
const name = Object.keys(this.champions).find(key => key.toLowerCase() === champion);
|
const name = Object.keys(body.data).find(key => key.toLowerCase() === champion);
|
||||||
if (!name) return msg.say('Could not find any results.');
|
if (!name) return msg.say('Could not find any results.');
|
||||||
const { id } = this.champions[name];
|
const data = body.data[name];
|
||||||
const { body } = await snekfetch
|
|
||||||
.get(`https://na1.api.riotgames.com/lol/static-data/v3/champions/${id}`)
|
|
||||||
.query({
|
|
||||||
api_key: RIOT_KEY,
|
|
||||||
tags: 'all'
|
|
||||||
});
|
|
||||||
data = body;
|
|
||||||
this.cache.set(champion, body);
|
|
||||||
} else {
|
|
||||||
data = this.cache.get(champion);
|
|
||||||
}
|
|
||||||
const tips = [].concat(data.allytips, data.enemytips);
|
const tips = [].concat(data.allytips, data.enemytips);
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor(0x002366)
|
.setColor(0x002366)
|
||||||
@@ -99,12 +86,11 @@ module.exports = class LeagueOfLegendsChampionCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchChampions() {
|
async fetchVersion() {
|
||||||
const { body } = await snekfetch
|
const { body } = await snekfetch
|
||||||
.get('https://na1.api.riotgames.com/lol/static-data/v3/champions')
|
.get('https://na1.api.riotgames.com/lol/static-data/v3/versions')
|
||||||
.query({ api_key: RIOT_KEY });
|
.query({ api_key: RIOT_KEY });
|
||||||
this.version = body.version;
|
this.version = body[0];
|
||||||
this.champions = body.data;
|
return this.version;
|
||||||
return body.data;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user