From 234e398bbc727414cc26048a7cb7698803516bc0 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 25 Apr 2020 00:37:13 -0400 Subject: [PATCH] Paladins Command --- .env.example | 4 ++ README.md | 7 ++- assets/json/paladins.json | 18 +++++++ commands/search/paladins.js | 104 ++++++++++++++++++++++++++++++++++++ package.json | 2 +- 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 assets/json/paladins.json create mode 100644 commands/search/paladins.js diff --git a/.env.example b/.env.example index 3a35ff62..88e6b799 100644 --- a/.env.example +++ b/.env.example @@ -21,6 +21,10 @@ SILVER_FISH_EMOJI_ID= SILVER_FISH_EMOJI_NAME= PORTAL_EMOJI_ID= PORTAL_EMOJI_NAME= +FLANKER_EMOJI_ID= +FRONT_LINE_EMOJI_ID= +SUPPORT_EMOJI_ID= +DAMAGE_EMOJI_ID= # API Keys, IDs, and Secrets ALPHA_VANTAGE_KEY= diff --git a/README.md b/README.md index d6ada9a1..138e5019 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 404 +Total: 405 ### Utility: @@ -322,6 +322,7 @@ Total: 404 * **neopets-item:** Responds with information on a specific Neopets item. * **npm:** Responds with information on an NPM package. * **osu:** Responds with information on an osu! user. +* **paladins:** Responds with information on a Paladins player. * **periodic-table:** Finds an element on the periodic table. * **pokedex:** Searches the Pokédex for a Pokémon. * **recipe:** Searches for recipes based on your query. @@ -741,6 +742,8 @@ here. * temmie (English-to-Temmie Dictionary Data) - [Esther Verkest](https://www.facebook.com/Esther-Verkest-49667161749/) * sos (Image) +- [Evil Mojo Games](https://www.evilmojogames.com/) + * paladins ([Original "Paladins" Game](https://www.paladins.com/)) - [Face++ Cognitive Services](https://www.faceplusplus.com/) * face ([Face Detection API](https://www.faceplusplus.com/face-detection/)) - [FANDOM](https://www.fandom.com/) @@ -1002,6 +1005,8 @@ here. * osu ([API](https://github.com/ppy/osu-api/wiki)) - [PAC-MAN Party](http://pacman.com/en/pac-man-games/pac-man-party) * balloon-pop (Concept) +- [PaladinsGuru](https://paladins.guru/) + * paladins (API) - [PayPal](https://www.paypal.com/us/home) * donate (Donation Gathering) - [Perspective API](https://www.perspectiveapi.com/#/) diff --git a/assets/json/paladins.json b/assets/json/paladins.json new file mode 100644 index 00000000..5334f231 --- /dev/null +++ b/assets/json/paladins.json @@ -0,0 +1,18 @@ +{ + "Damage": { + "id": "damage", + "display": "Damage" + }, + "Flanker": { + "id": "kills", + "display": "Kills" + }, + "Front Line": { + "id": "objective_time", + "display": "Objective Time" + }, + "Support": { + "id": "healing", + "display": "Healing" + } +} diff --git a/commands/search/paladins.js b/commands/search/paladins.js new file mode 100644 index 00000000..d902c71c --- /dev/null +++ b/commands/search/paladins.js @@ -0,0 +1,104 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const request = require('node-superfetch'); +const moment = require('moment'); +const classStats = require('../../assets/json/paladins'); +const { FLANKER_EMOJI_ID, DAMAGE_EMOJI_ID, FRONT_LINE_EMOJI_ID, SUPPORT_EMOJI_ID } = process.env; + +module.exports = class PaladinsCommand extends Command { + constructor(client) { + super(client, { + name: 'paladins', + aliases: ['paladins-guru'], + group: 'search', + memberName: 'paladins', + description: 'Responds with information on a Paladins player.', + clientPermissions: ['EMBED_LINKS'], + credit: [ + { + name: 'Evil Mojo Games', + url: 'https://www.evilmojogames.com/', + reason: 'Original "Paladins" Game', + reasonURL: 'https://www.paladins.com/' + }, + { + name: 'PaladinsGuru', + url: 'https://paladins.guru/', + reason: 'API' + } + ], + args: [ + { + key: 'player', + prompt: 'What player would you like to get information on?', + type: 'string' + } + ] + }); + + this.champions = null; + } + + async run(msg, { player }) { + try { + const search = await this.search(player); + if (!search) return msg.say('Could not find any results.'); + const data = await this.fetchPlayer(id); + if (!this.champions) await this.fetchChampions(); + const champions = data.champions.map(champ => { + const champData = this.champions[champ.id]; + const classStat = classStats[champData.class]; + const emoji = this.classEmoji(champData.class); + return `${emoji} ${champData.name} (${champData[classStat.id]} ${classStat.display})`; + }); + const embed = new MessageEmbed() + .setColor(0x1E9BAD) + .setAuthor('Paladins Guru', 'https://i.imgur.com/iIAdriK.png', 'https://paladins.guru/') + .addField('❯ Name', data.name, true) + .addField('❯ ID', data.id, true) + .addField('❯ Level', data.level, true) + .addField('❯ Last Seen', moment.utc(data.seen).format('MM/DD/YYYY h:mm A'), true) + .addField('❯ Region', data.region, true) + .addField('❯ Team', data.team || 'Free Agent', true) + .addField('❯ Top 5 Champions', champions.slice(0, 5).join('\n')); + return msg.embed(embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + async search(query) { + const { body } = await request + .get('https://api.paladins.guru/v3/search') + .query({ + term: query, + type: 'Player' + }); + if (!body.length) return null; + return body[0]; + } + + async fetchPlayer(id) { + const { body } = await request.get(`https://api.paladins.guru/v3/profiles/${id}/summary`); + return body; + } + + async fetchChampions() { + if (this.champions) return this.champions; + const { body } = await request.get('https://api.paladins.guru/v3/champions/'); + this.champions = body; + setTimeout(() => { this.champions = null; }, 3.6e+6); + return body; + } + + classEmoji(className) { + let emojiID; + switch (className) { + case 'Flanker': emojiID = FLANKER_EMOJI_ID; break; + case 'Support': emojiID = SUPPORT_EMOJI_ID; break; + case 'Damage': emojiID = DAMAGE_EMOJI_ID; break; + case 'Front Line': emojiID = FRONT_LINE_EMOJI_ID; break; + } + return `<:${className.replace(/ /g, '')}:${emojiID}>` + } +}; diff --git a/package.json b/package.json index f66b07b7..5fd97ce8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "113.18.0", + "version": "113.19.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {