LoL Champ Command

This commit is contained in:
Daniel Odendahl Jr
2017-10-21 21:10:24 +00:00
parent ddd9394d66
commit 578d79e4be
4 changed files with 102 additions and 9 deletions
@@ -0,0 +1,90 @@
const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { shorten } = require('../../util/Util');
const { RIOT_KEY } = process.env;
const buttons = ['Q', 'W', 'E', 'R'];
module.exports = class LeagueOfLegendsChampionCommand extends Command {
constructor(client) {
super(client, {
name: 'league-of-legends-champion',
aliases: ['lol-champion', 'champion', 'league-of-legends-champ', 'lol-champ', 'champ'],
group: 'search',
memberName: 'league-of-legends-champion',
description: 'Gets information on a League of Legends champion.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'champion',
prompt: 'What champion would you like to get information on?',
type: 'string',
parse: champion => champion.toLowerCase()
}
]
});
}
async run(msg, { champion }) {
try {
const search = await snekfetch
.get('https://na1.api.riotgames.com/lol/static-data/v3/champions')
.query({ api_key: RIOT_KEY });
const key = Object.keys(search.body.data).find(key => key.toLowerCase() === champion);
if (!key) return msg.say('Could not find any results.');
const { id } = search.body.data[key];
const { body } = await snekfetch
.get(`https://na1.api.riotgames.com/lol/static-data/v3/champions/${id}`)
.query({
api_key: RIOT_KEY,
tags: 'all'
});
const tips = [].concat(body.allytips, body.enemytips);
const embed = new MessageEmbed()
.setColor(0x002366)
.setAuthor('League of Legends', 'https://i.imgur.com/2JL4Rko.png')
.setTitle(`${body.name} ${body.title}`)
.setDescription(body.blurb)
.setThumbnail(`https://ddragon.leagueoflegends.com/cdn/${search.body.version}/img/champion/${body.image.full}`)
.addField(' Attack',
body.info.attack, true)
.addField(' Defense',
body.info.defense, true)
.addField(' Magic',
body.info.magic, true)
.addField(' Difficulty',
body.info.difficulty, true)
.addField(' HP',
`${body.stats.hp} (${body.stats.hpperlevel}/level)`, true)
.addField(' HP Regen',
`${body.stats.hpregen} (${body.stats.hpregenperlevel}/level)`, true)
.addField(' MP',
`${body.stats.mp} (${body.stats.mpperlevel}/level)`, true)
.addField(' MP Regen',
`${body.stats.mpregen} (${body.stats.mpregenperlevel}/level)`, true)
.addField(' Resource',
body.partype, true)
.addField(' Armor',
`${body.stats.armor} (${body.stats.armorperlevel}/level)`, true)
.addField(' Attack Damage',
`${body.stats.attackdamage} (${body.stats.attackdamageperlevel}/level)`, true)
.addField(' Attack Range',
body.stats.attackrange, true)
.addField(' Attack Speed Offset',
`${body.stats.attackspeedoffset} (${body.stats.attackspeedperlevel}/level)`, true)
.addField(' Crit',
`${body.stats.crit} (${body.stats.critperlevel}/level)`, true)
.addField(' Move Speed',
body.stats.movespeed, true)
.addField(' Spell Block',
`${body.stats.spellblock} (${body.stats.spellblockperlevel}/level)`, true)
.addField(' Passive',
shorten(`**${body.passive.name}**: ${body.passive.sanitizedDescription}`, 1000))
.addField(' Spells',
body.spells.map((spell, i) => `${spell.name} (${buttons[i]})`).join('\n'));
return msg.say(`Tip: ${tips[Math.floor(Math.random() * tips.length)]}`, { embed });
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -2
View File
@@ -1,7 +1,6 @@
const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { shorten } = require('../../util/Util');
const { GOOGLE_KEY } = process.env;
module.exports = class YouTubeCommand extends Command {
@@ -39,7 +38,7 @@ module.exports = class YouTubeCommand extends Command {
const embed = new MessageEmbed()
.setColor(0xDD2825)
.setTitle(data.snippet.title)
.setDescription(shorten(data.snippet.description))
.setDescription(data.snippet.description)
.setAuthor(`YouTube - ${data.snippet.channelTitle}`, 'https://i.imgur.com/kKHJg9Q.png')
.setURL(`https://www.youtube.com/watch?v=${data.id.videoId}`)
.setThumbnail(data.snippet.thumbnails.default.url);
+10 -6
View File
@@ -30,12 +30,14 @@ module.exports = class TranslateCommand extends Command {
prompt: `Which language would you like to translate to? Either ${list(Object.keys(codes), 'or')}.`,
type: 'string',
validate: target => {
if (codes[target.toLowerCase()] || Object.values(codes).includes(target)) return true;
const value = target.toLowerCase();
if (codes[value] || Object.values(codes).find(entry => entry.toLowerCase() === value)) return true;
return `Invalid target, please enter either ${list(Object.keys(codes), 'or')}.`;
},
parse: target => {
if (codes[target.toLowerCase()]) return target.toLowerCase();
return Object.keys(codes).find(key => codes[key] === target);
const value = target.toLowerCase();
if (codes[value]) return value;
return codes[Object.values(codes).find(entry => entry.toLowerCase() === value)];
}
},
{
@@ -44,12 +46,14 @@ module.exports = class TranslateCommand extends Command {
type: 'string',
default: '',
validate: base => {
if (codes[base.toLowerCase()] || Object.values(codes).includes(base)) return true;
const value = base.toLowerCase();
if (codes[value] || Object.values(codes).find(entry => entry.toLowerCase() === value)) return true;
return `Invalid base, please enter either ${list(Object.keys(codes), 'or')}.`;
},
parse: base => {
if (codes[base.toLowerCase()]) return base.toLowerCase();
return Object.keys(codes).find(key => codes[key] === base);
const value = base.toLowerCase();
if (codes[value]) return value;
return codes[Object.values(codes).find(entry => entry.toLowerCase() === value)];
}
}
]
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "49.1.0",
"version": "49.2.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {