diff --git a/commands/search/dictionary.js b/commands/search/dictionary.js index b34d4874..eb7413be 100644 --- a/commands/search/dictionary.js +++ b/commands/search/dictionary.js @@ -29,6 +29,7 @@ module.exports = class DictionaryCommand extends Command { .query({ limit: 1, includeRelated: false, + useCanonical: true, api_key: WORDNIK_KEY }); if (!body.length) return msg.say('Could not find any results.'); diff --git a/commands/search/reverse-dictionary.js b/commands/search/reverse-dictionary.js new file mode 100644 index 00000000..aa8da39e --- /dev/null +++ b/commands/search/reverse-dictionary.js @@ -0,0 +1,43 @@ +const { Command } = require('discord.js-commando'); +const snekfetch = require('snekfetch'); +const { stripIndents } = require('common-tags'); +const { WORDNIK_KEY } = process.env; + +module.exports = class ReverseDictionaryCommand extends Command { + constructor(client) { + super(client, { + name: 'reverse-dictionary', + aliases: ['reverse-define', 'wordnik-reverse-define', 'wordnik-reverse-dictionary'], + group: 'search', + memberName: 'reverse-dictionary', + description: 'Responds with the closest word for a given definition.', + args: [ + { + key: 'definition', + prompt: 'What definition would you like to look up?', + type: 'string' + } + ] + }); + } + + async run(msg, { definition }) { + try { + const { body } = await snekfetch + .get('http://api.wordnik.com/v4/words.json/reverseDictionary') + .query({ + query: definition, + limit: 1, + api_key: WORDNIK_KEY + }); + if (!body.results) return msg.say('Could not find any results.'); + const data = body.results[0]; + return msg.say(stripIndents` + **${data.word}** + ${data.text} + `); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/search/thesaurus.js b/commands/search/thesaurus.js deleted file mode 100644 index e33b45ca..00000000 --- a/commands/search/thesaurus.js +++ /dev/null @@ -1,46 +0,0 @@ -const { Command } = require('discord.js-commando'); -const snekfetch = require('snekfetch'); -const { stripIndents } = require('common-tags'); -const { WORDNIK_KEY } = process.env; - -module.exports = class ThesaurusCommand extends Command { - constructor(client) { - super(client, { - name: 'thesaurus', - aliases: ['synonym', 'antonym', 'wordnik-thesaurus'], - group: 'search', - memberName: 'thesaurus', - description: 'Responds with the synonyms and antonyms of a word.', - args: [ - { - key: 'word', - prompt: 'What word would you like to look up?', - type: 'string', - parse: word => encodeURIComponent(word) - } - ] - }); - } - - async run(msg, { word }) { - try { - const { body } = await snekfetch - .get(`http://api.wordnik.com/v4/word.json/${word}/relatedWords`) - .query({ - relationshipTypes: 'synonym,antonym', - limitPerRelationshipType: 5, - api_key: WORDNIK_KEY - }); - if (!body.length) return msg.say('Could not find any results.'); - const synonyms = body.find(words => words.relationshipType === 'synonym'); - const antonyms = body.find(words => words.relationshipType === 'antonym'); - return msg.say(stripIndents` - **${word}** - __Synonyms:__ ${synonyms ? synonyms.words.join(', ') : '???'} - __Antonyms:__ ${antonyms ? antonyms.words.join(', ') : '???'} - `); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/package.json b/package.json index 3074953f..370b9272 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "54.3.0", + "version": "55.0.0", "description": "Your personal server companion.", "main": "XiaoBot.js", "scripts": {