Skip to content

Instantly share code, notes, and snippets.

@max3uc3
Last active February 3, 2017 14:26
Show Gist options
  • Save max3uc3/19954899fed48e97265863068ace462d to your computer and use it in GitHub Desktop.
Save max3uc3/19954899fed48e97265863068ace462d to your computer and use it in GitHub Desktop.
const text = require('./text.js')
const image = require('./image.js')
const helper = {
text: text,
image: image
}
module.exports = helper
const image = {
toImage: image => {
return {
type: 'image',
content: image
}
}
}
module.exports = image
/* EXEMPLES D UTILISATION DU HELPER */
const request = require('superagent')
import {text} from '../helper/helper.js'
import {image} from '../helper/helper.js'
const getInfoPokemon = (entity) => {
if (!entity) { return Promise.reject('Vous n\'avez donné aucun Pokémon')}
return new Promise(
function(resolve, reject) {
request.get('https://pokeapi.co/api/v2/pokemon/' + entity.raw.toLowerCase())
.end((err, res) => {
if (err) {
console.log(new Error().stack)
return reject("Le pokemon que vous avez demandé n'a pas été trouvé dans la base de données.")
}
const infosP = infoPokemonLayout(res.body)
resolve(infoPokemonLayout(res.body))
})
})
}
const infoPokemonLayout = (json) => {
const answer = [helper.text.toText(`:mag_right: ${json.name} infos`)]
const toAdd = json.types.map(elem => elem.type.name).join(' / ')
answer.push(helper.text.toText(`Type(s): ${toAdd}`))
if (json.sprites.front_default) {
answer.push(helper.image.toImage(json.sprites.front_default))
}
return answer
}
module.exports = getInfoPokemon
const text = {
toText: message => {
return {
type: 'text',
content: message
}
}
}
module.exports = text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment