mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-06 06:10:49 +02:00
Serebii Scraper for Pokedex
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+40
-22
@@ -1,6 +1,7 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const pokedex = require('./pkdex.json');
|
||||
const snekfetch = require('snekfetch');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = class PokedexCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -14,35 +15,52 @@ module.exports = class PokedexCommand extends Command {
|
||||
description: 'Gives the pokedex entry for a Pokemon. (;pokedex Pikachu)',
|
||||
examples: [';pokedex Pikachu'],
|
||||
args: [{
|
||||
key: 'pokemon',
|
||||
key: 'index',
|
||||
prompt: 'What Pokémon would you like to get info on?',
|
||||
type: 'string',
|
||||
type: 'integer',
|
||||
validate: pokemon => {
|
||||
if (pokedex.name[pokemon.toLowerCase()]) {
|
||||
if (pokemon < 803 && pokemon > 0) {
|
||||
return true;
|
||||
}
|
||||
return 'Please enter a valid Pokémon from either Kanto or Johto.';
|
||||
return 'Please enter a pokedex number from 001-802';
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
run(message, args) {
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
}
|
||||
const pokemon = args.pokemon.toLowerCase();
|
||||
const embed = new RichEmbed()
|
||||
.setAuthor(`#${pokedex.index[pokemon]} ${pokedex.name[pokemon]}`, `http://www.serebii.net/pokedex-sm/icon/${pokedex.index[pokemon]}.png`)
|
||||
.setColor(0xFF0000)
|
||||
.setDescription(`${pokedex.species[pokemon]} Pokémon`)
|
||||
.setFooter('Pokédex - 001-251 Implemented', 'http://cdn.bulbagarden.net/upload/thumb/3/36/479Rotom-Pokédex.png/250px-479Rotom-Pokédex.png')
|
||||
.setThumbnail(`http://www.serebii.net/sunmoon/pokemon/${pokedex.index[pokemon]}.png`)
|
||||
.addField('Entry',
|
||||
pokedex.entry[pokemon])
|
||||
.addField('Type',
|
||||
pokedex.type[pokemon]);
|
||||
return message.embed(embed);
|
||||
async run(message, args) {
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
}
|
||||
const index = args.index;
|
||||
let dex = 'xy';
|
||||
let location = 'foox';
|
||||
let location2 = 'fooy';
|
||||
if (index > 721) {
|
||||
dex = 'sm';
|
||||
location = 'foosun';
|
||||
location2 = 'foomoon';
|
||||
}
|
||||
try {
|
||||
const response = await snekfetch
|
||||
.get(`http://www.serebii.net/pokedex-${dex}/${index}.shtml`);
|
||||
const $ = cheerio.load(response.text);
|
||||
const entry = $(`td.${location}`).eq(1).next().text();
|
||||
const entry2 = $(`td.${location2}`).eq(1).next().text();
|
||||
const embed = new RichEmbed()
|
||||
.setAuthor(`#${index}`, `http://www.serebii.net/pokedex-sm/icon/${index}.png`)
|
||||
.setColor(0xFF0000)
|
||||
.setFooter('Pokédex', 'http://cdn.bulbagarden.net/upload/thumb/3/36/479Rotom-Pokédex.png/250px-479Rotom-Pokédex.png')
|
||||
.setThumbnail(`http://www.serebii.net/sunmoon/pokemon/${index}.png`)
|
||||
.addField('**Entry 1:**',
|
||||
entry)
|
||||
.addField('**Entry 2:**',
|
||||
entry2);
|
||||
return message.embed(embed);
|
||||
}
|
||||
catch (err) {
|
||||
return message.say(':x: Error! Something went wrong!');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "25.3.0",
|
||||
"version": "25.4.0",
|
||||
"description": "A Discord Bot",
|
||||
"main": "shardingmanager.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user