Wikihow command

This commit is contained in:
Daniel Odendahl Jr
2017-12-28 20:51:55 +00:00
parent ae95c670b8
commit 3373c8be86
3 changed files with 46 additions and 2 deletions
-1
View File
@@ -21,7 +21,6 @@ module.exports = class SpoopyLinkCommand extends Command {
}
async run(msg, { site }) {
if (/discord(\.gg|app\.com%2Finvite|\.me)%2F/gi.test(site)) return msg.say('Discord invites are safe!');
try {
const { body } = await snekfetch.get(`https://spoopy.link/api/${site}`);
return msg.say(stripIndents`
+45
View File
@@ -0,0 +1,45 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
module.exports = class WikihowCommand extends Command {
constructor(client) {
super(client, {
name: 'wikihow',
aliases: ['wikihow-article', 'how-to'],
group: 'search',
memberName: 'wikihow',
description: 'Searches Wikihow for your query.',
args: [
{
key: 'query',
prompt: 'What article would you like to search for?',
type: 'string',
parse: query => query.replace(/^(how to)/i, '')
}
]
});
}
async run(msg, { query }) {
try {
const { body } = await snekfetch
.get('https://www.wikihow.com/api.php')
.query({
action: 'query',
prop: 'info',
format: 'json',
titles: query,
inprop: 'url'
});
const data = body.query.pages[Object.keys(body.query.pages)[0]];
if (data.missing) return msg.say('Could not find any results.');
return msg.say(stripIndents`
How to ${data.title}
${data.fullurl}
`);
} 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": "60.1.0",
"version": "60.2.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {