mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 06:37:32 +02:00
Wikihow command
This commit is contained in:
@@ -21,7 +21,6 @@ module.exports = class SpoopyLinkCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { site }) {
|
async run(msg, { site }) {
|
||||||
if (/discord(\.gg|app\.com%2Finvite|\.me)%2F/gi.test(site)) return msg.say('Discord invites are safe!');
|
|
||||||
try {
|
try {
|
||||||
const { body } = await snekfetch.get(`https://spoopy.link/api/${site}`);
|
const { body } = await snekfetch.get(`https://spoopy.link/api/${site}`);
|
||||||
return msg.say(stripIndents`
|
return msg.say(stripIndents`
|
||||||
|
|||||||
@@ -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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "60.1.0",
|
"version": "60.2.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user