Mayo Clinic Command

This commit is contained in:
Daniel Odendahl Jr
2018-10-12 00:40:11 +00:00
parent d085e16c3a
commit 72b5a89550
3 changed files with 65 additions and 2 deletions
+2 -1
View File
@@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with
Xiao is no longer available for invite. You can self-host the bot, or use her on
the [home server](https://discord.gg/sbMe32W).
## Commands (327)
## Commands (328)
### Utility:
* **eval:** Executes JavaScript code.
@@ -152,6 +152,7 @@ the [home server](https://discord.gg/sbMe32W).
* **kitsu-manga:** Searches Kitsu.io for your query, getting manga results.
* **know-your-meme:** Searches Know Your Meme for your query.
* **league-of-legends-champion:** Responds with information on a League of Legends champion.
* **mayo-clinic:** Searches Mayo Clinic for your query.
* **mdn:** Searches MDN for your query.
* **nasa:** Searches NASA's image archive for your query.
* **neopet:** Responds with the image of a specific Neopet.
+62
View File
@@ -0,0 +1,62 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const cheerio = require('cheerio');
const { MessageEmbed } = require('discord.js');
const { shorten } = require('../../util/Util');
module.exports = class MayoClinicCommand extends Command {
constructor(client) {
super(client, {
name: 'mayo-clinic',
aliases: ['disease', 'diagnose', 'diagnosis'],
group: 'search',
memberName: 'mayo-clinic',
description: 'Searches Mayo Clinic for your query.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
prompt: 'What disease would you like to search for?',
type: 'string'
}
]
});
}
async run(msg, { query }) {
try {
const location = await this.search(query);
if (!location) return msg.say('Could not find any results.');
const data = await this.fetchDisease(location);
const embed = new MessageEmbed()
.setColor(0x0044B3)
.setAuthor('Mayo Clinic', 'https://i.imgur.com/9zdulOS.jpg', 'https://www.mayoclinic.org/')
.setTitle(data.name)
.setDescription(shorten(data.description || 'No description available.'))
.setURL(data.url);
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async search(query) {
const { text } = await request
.get('https://www.mayoclinic.org/search/search-results')
.query({ q: query });
const $ = cheerio.load(text);
const location = $('ol.navlist').find('li.noimg').first().children().find('a').attr('href');
if (!location) return null;
return location;
}
async fetchDisease(location) {
const { text } = await request.get(location);
const $ = cheerio.load(text);
return {
name: $('h1').first().text().trim(),
url: location,
description: $('h2').first().next().text()
};
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "94.0.3",
"version": "94.1.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {