diff --git a/commands/search/wikia.js b/commands/search/wikia.js new file mode 100644 index 00000000..ba280454 --- /dev/null +++ b/commands/search/wikia.js @@ -0,0 +1,53 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); + +module.exports = class WikiaCommand extends Command { + constructor(client) { + super(client, { + name: 'wikia', + group: 'search', + memberName: 'wikia', + description: 'Searches a specified Wikia wiki for your query.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'wiki', + prompt: 'What is the subdomain of the wikia you want to search?', + type: 'string' + }, + { + key: 'query', + prompt: 'What would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + const { wiki, query } = args; + try { + const search = await snekfetch + .get(`http://${wiki}.wikia.com/api/v1/Search/List/`) + .query({ + query, + limit: 1, + namespaces: 0 + }); + const id = search.body.items[0].id; + const { body } = await snekfetch + .get(`http://${wiki}.wikia.com/api/v1/Articles/AsSimpleJson/`) + .query({ id }); + const embed = new MessageEmbed() + .setColor(0x002D54) + .setTitle(body.sections[0].title) + .setAuthor('Wikia', 'https://i.imgur.com/WzXWJka.png') + .setDescription(body.content[0].text) + .setThumbnail(body.sections[0].images[0]); + return msg.embed(embed); + } catch (err) { + return msg.say('No Results or Invalid Wiki.'); + } + } +}; diff --git a/package.json b/package.json index 13d33fc8..b1985dc5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "27.0.3", + "version": "27.1.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {