diff --git a/README.md b/README.md index 02542ff7..4a56e295 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (301) +## Commands (302) ### Utility: * **eval:** Executes JavaScript code. @@ -137,6 +137,7 @@ on the [home server](https://discord.gg/sbMe32W). * **imgur:** Searches Imgur for your query. * **itunes:** Searches iTunes for your query. * **jisho:** Defines a word, but with Japanese. +* **kh-wiki**: Searches the Kingdom Hearts Wiki for your query. * **kickstarter:** Searches Kickstarter for your query. * **league-of-legends-champion:** Responds with information on a League of Legends champion. * **map:** Responds with a map of a specific location. diff --git a/commands/search/kh-wiki.js b/commands/search/kh-wiki.js new file mode 100644 index 00000000..a89e7726 --- /dev/null +++ b/commands/search/kh-wiki.js @@ -0,0 +1,54 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const request = require('node-superfetch'); +const { shorten } = require('../../util/Util'); + +module.exports = class KhWikiCommand extends Command { + constructor(client) { + super(client, { + name: 'kh-wiki', + aliases: ['kingdom-hearts-wiki', 'kh-wiki-article', 'kingdom-hearts-wiki-article'], + group: 'search', + memberName: 'kh-wiki', + description: 'Searches the Kingdom Hearts Wiki for your query.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What article would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await request + .get('https://www.khwiki.com/api.php') + .query({ + action: 'query', + prop: 'extracts|pageimages', + format: 'json', + titles: query, + exintro: '', + explaintext: '', + pithumbsize: 150, + redirects: '', + formatversion: 2 + }); + const data = body.query.pages[0]; + if (data.missing) return msg.say('Could not find any results.'); + const embed = new MessageEmbed() + .setColor(0x0679BC) + .setTitle(data.title) + .setAuthor('Kingdom Hearts Wiki', 'https://i.imgur.com/OZhrA41.jpg', 'https://www.khwiki.com/') + .setThumbnail(data.thumbnail ? data.thumbnail.source : null) + .setURL(`https://www.khwiki.com/${encodeURIComponent(query).replace(/\)/g, '%29')}`) + .setDescription(shorten(data.extract.replace(/.+\n\n/, '').replace(/\n/g, '\n\n'))); + return msg.embed(embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 2503fcdd..01127020 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "90.3.7", + "version": "90.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {