From ec367c4ac96d3ac33c605365eb943c62f3e4e452 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 15 Apr 2017 03:04:45 +0000 Subject: [PATCH] Neopet Searchable by name --- commands/search/neopet.js | 30 ++++++++++++++++++++++++------ package.json | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/commands/search/neopet.js b/commands/search/neopet.js index f449e16c..6d44ef97 100644 --- a/commands/search/neopet.js +++ b/commands/search/neopet.js @@ -1,4 +1,6 @@ const { Command } = require('discord.js-commando'); +const request = require('superagent'); +const cheerio = require('cheerio'); module.exports = class NeopetCommand extends Command { constructor(client) { @@ -6,21 +8,37 @@ module.exports = class NeopetCommand extends Command { name: 'neopet', group: 'search', memberName: 'neopet', - description: 'Gives a Neopet\'s image, searchable by ID. (;neopet rjwlsb8k)', - examples: [';neopet rjwlsb8k'], + description: 'Gives a Neopet\'s image, searchable by name. (;neopet Pikachu53535)', + examples: [';neopet Pikachu53535'], args: [{ key: 'pet', - prompt: 'What pet ID would you like to get the image of?', + prompt: 'What pet would you like to get the image of?', type: 'string' }] }); } - run(message, args) { + 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('ATTACH_FILES')) return message.say(':x: Error! I don\'t have the Attach Files Permission!'); + } + const pet = args.pet; + try { + const response = await request + .get('http://www.sunnyneo.com/petimagefinder.php') + .query({ + name: pet, + size: 5, + mood: 1 + }); + const $ = cheerio.load(response.text); + const link = $('textarea').first().text(); + if (!link) return message.say(':x: Error! Pet not found!'); + return message.say(link); + } + catch (err) { + return message.say(':x: Error! Something went wrong!'); } - const petID = args.pet; - return message.say(`http://pets.neopets.com/cp/${petID}/1/5.png`); } }; diff --git a/package.json b/package.json index c1da4148..7a504dcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "24.3.3", + "version": "24.4.0", "description": "A Discord Bot", "main": "shardingmanager.js", "scripts": {