Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

PR for merge new features of hearthstone #1371

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ typings/
# next.js build output
.next

# yarn files
yarn.lock

#prettier files
.prettierrc
.prettierignore

.vscode

.idea/
Expand Down
53 changes: 53 additions & 0 deletions src/apis/HearthStone.js
Original file line number Diff line number Diff line change
@@ -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))
}
}
16 changes: 16 additions & 0 deletions src/commands/games/hearthstone.js
Original file line number Diff line number Diff line change
@@ -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
)
}
}
41 changes: 41 additions & 0 deletions src/commands/games/hearthstone/cardsById.js
Original file line number Diff line number Diff line change
@@ -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 `,
Comment on lines +26 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locales?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

te amo, esqueci

`${text}`])
)
} catch (e) {
channel.send(new SwitchbladeEmbed().setTitle('Card not Found !').setDescription('Search for a valid card Id !')).then(() => channel.stopTyping())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

}
channel.send(embed).then(() => channel.stopTyping())
}
}