Fix some things

This commit is contained in:
Daniel Odendahl Jr
2019-05-16 14:29:39 +00:00
parent 7a86c80c23
commit e6e38fb4e4
7 changed files with 16 additions and 71 deletions
+8 -13
View File
@@ -1,20 +1,20 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { stripIndents } = require('common-tags');
const { WORDNIK_KEY } = process.env;
const { WEBSTER_KEY } = process.env;
module.exports = class DefineCommand extends Command {
constructor(client) {
super(client, {
name: 'define',
aliases: ['dictionary', 'wordnik'],
aliases: ['dictionary', 'webster'],
group: 'search',
memberName: 'define',
description: 'Defines a word.',
credit: [
{
name: 'Wordnik API',
url: 'https://developer.wordnik.com/'
name: 'Merriam-Webster\'s Collegiate® Dictionary',
url: 'https://dictionaryapi.com/products/api-collegiate-dictionary'
}
],
args: [
@@ -31,18 +31,13 @@ module.exports = class DefineCommand extends Command {
async run(msg, { word }) {
try {
const { body } = await request
.get(`http://api.wordnik.com/v4/word.json/${word}/definitions`)
.query({
limit: 1,
includeRelated: false,
useCanonical: true,
api_key: WORDNIK_KEY
});
.get(`https://www.dictionaryapi.com/api/v3/references/collegiate/json/${word}`)
.query({ key: WEBSTER_KEY });
if (!body.length) return msg.say('Could not find any results.');
const data = body[0];
return msg.say(stripIndents`
**${data.word}**
(${data.partOfSpeech || 'unknown'}) ${data.text}
**${data.stems[0]}** (${data.fl})
${data.shortdef.map((definition, i) => `(${i + 1}) ${definition}`).join('\n')}
`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);