Kingdom Hearts Wiki Command

This commit is contained in:
Daniel Odendahl Jr
2018-09-08 00:43:03 +00:00
parent 680f79f1ea
commit 00816cd853
3 changed files with 57 additions and 2 deletions
+2 -1
View File
@@ -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.
+54
View File
@@ -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!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "90.3.7",
"version": "90.4.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {