This repository has been archived by the owner on Jan 19, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 219
PR for merge new features of hearthstone #1371
Open
midhatdrops
wants to merge
4
commits into
SwitchbladeBot:dev
Choose a base branch
from
midhatdrops:feature/hearthstone
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e208d5
Added HearthStone Api Wrapper and configured envs and git ignore files
midhatdrops b17063f
Added HearthStone command and get cards by id
midhatdrops 4c2910a
Merge branch 'SwitchbladeBot:dev' into feature/hearthstone
midhatdrops 90e1ba4
Added feature of searching cards by id
midhatdrops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 `, | ||
`${text}`]) | ||
) | ||
} catch (e) { | ||
channel.send(new SwitchbladeEmbed().setTitle('Card not Found !').setDescription('Search for a valid card Id !')).then(() => channel.stopTyping()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
} | ||
channel.send(embed).then(() => channel.stopTyping()) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locales?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
te amo, esqueci