diff --git a/.env.example b/.env.example index b2b0157e9..53514b2b1 100644 --- a/.env.example +++ b/.env.example @@ -42,3 +42,4 @@ MERRIAM_WEBSTER_API_KEY=1293a33-4731-34cb-69a3-178a39b7c23 GITHUB_USER=SwitchbladeBot GITHUB_REPOSITORY=switchblade GITHUB_BRANCH=master +HEARTHSTONE_RAPIDAPI_KEY=183320a28emsh45e274654308a94p1664b2jsn7440338857cf diff --git a/.gitignore b/.gitignore index 94e24f1dd..ede9195a9 100644 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,13 @@ typings/ # next.js build output .next +# yarn files +yarn.lock + +#prettier files +.prettierrc +.prettierignore + .vscode .idea/ diff --git a/src/apis/HearthStone.js b/src/apis/HearthStone.js new file mode 100644 index 000000000..bb42475ac --- /dev/null +++ b/src/apis/HearthStone.js @@ -0,0 +1,53 @@ +const { APIWrapper } = require('../') +const axios = require('axios') + +const endpoint = 'https://omgvamp-hearthstone-v1.p.rapidapi.com' + +module.exports = class HearthStoneAPI extends APIWrapper { + constructor () { + super({ + name: 'hearthstoneapi', + envVars: ['HEARTHSTONE_RAPIDAPI_KEY'] + }) + this.languages = ['ptBR,enUS'] + } + + // Get Card by Name + /** + * @param {string} name the name of the card + */ + + async getCardByName (name) { + const options = { + method: 'GET', + url: `${endpoint}/cards/${name}`, + headers: { + 'x-rapidapi-host': `${endpoint}`, + 'x-rapidapi-key': `${process.env.HEARTHSTONE_RAPIDAPI_KEY}` + } + } + return await axios(options) + .then((res) => res.data) + .catch((err) => console.error(err)) + } + + // Get Card by Id + /** + * @param {int} id the integer of the card + */ + + async getCardById (id, lang) { + const options = { + method: 'GET', + url: `${endpoint}/cards/${id}`, + params: { locale: `${lang}` }, + headers: { + 'x-rapidapi-host': `${endpoint}`, + 'x-rapidapi-key': `${process.env.HEARTHSTONE_RAPIDAPI_KEY}` + } + } + return await axios(options) + .then((res) => res.data) + .catch((err) => console.error(err)) + } +} diff --git a/src/commands/games/hearthstone.js b/src/commands/games/hearthstone.js new file mode 100644 index 000000000..aeb3f7fee --- /dev/null +++ b/src/commands/games/hearthstone.js @@ -0,0 +1,16 @@ +const { SubcommandListCommand } = require('../../') + +module.exports = class HearthStone extends SubcommandListCommand { + constructor (client) { + super( + { + name: 'hearthstone', + aliases: ['hstone'], + category: 'games', + requirements: { apis: ['hearthstoneapi'] }, + embedColor: '#00BFFF' + }, + client + ) + } +} diff --git a/src/commands/games/hearthstone/cardsById.js b/src/commands/games/hearthstone/cardsById.js new file mode 100644 index 000000000..2c3a9d1b6 --- /dev/null +++ b/src/commands/games/hearthstone/cardsById.js @@ -0,0 +1,41 @@ +const { Command, SwitchbladeEmbed } = require('../../../') + +module.exports = class HearthStoneCardCommands extends Command { + constructor (client) { + super( + { + name: 'cards', + aliases: ['cards', 'c'], + parent: 'hearthstone' + }, + client + ) + } + + async run ({ t, author, channel, prefix, language }, cardId) { + channel.startTyping() + const embed = new SwitchbladeEmbed(author) + const { embedColor } = this.parentCommand + try { + const { name, cardSet, type, faction, rarity, cost, atack, health, text, img } = await this.client.apis.hearthstoneapi.getCardsById(cardId) + channel.send( + embed.setAuthor(author) + .setColor(embedColor) + .setImage(img) + .setTitle(name) + .setDescriptionFromBlockArray([` -/ CardSet: ${cardSet} + -/ Type: ${type} + -/ Faction: ${faction} + -/ Rarity: ${rarity} + -/ Cost: ${cost} + -/ Atack: ${atack} + -/ Heallth: ${health} points + -/ Text `, + `${text}`]) + ) + } catch (e) { + channel.send(new SwitchbladeEmbed().setTitle('Card not Found !').setDescription('Search for a valid card Id !')).then(() => channel.stopTyping()) + } + channel.send(embed).then(() => channel.stopTyping()) + } +}