diff --git a/assets/json/fortune.json b/assets/json/fortune.json index 97bde34e..56b4c81c 100644 --- a/assets/json/fortune.json +++ b/assets/json/fortune.json @@ -105,5 +105,8 @@ "Ask yourself this question: \"Is my attitude worth catching?\"", "The evening promises romantic interests.", "Keep in mind that it's the journey and not the destination that counts.", - "You will be called upon to help a friend in trouble." + "You will be called upon to help a friend in trouble.", + "You will hear pleasant news.", + "Your power is in your ability to decide.", + "When two men in a business always agree, one of them is unnecessary." ] diff --git a/commands/events/word-of-the-day.js b/commands/events/word-of-the-day.js new file mode 100644 index 00000000..de08d770 --- /dev/null +++ b/commands/events/word-of-the-day.js @@ -0,0 +1,55 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const cheerio = require('cheerio'); +const { stripIndents } = require('common-tags'); +const { WEBSTER_KEY } = process.env; + +module.exports = class WordOfTheDayCommand extends Command { + constructor(client) { + super(client, { + name: 'word-of-the-day', + aliases: ['daily-word', 'wotd', 'word-of-day'], + group: 'search', + memberName: 'word-of-the-day', + description: 'Responds with today\'s word of the day.', + credit: [ + { + name: 'Merriam-Webster\'s Collegiate® Dictionary', + url: 'https://www.merriam-webster.com/', + reason: 'API', + reasonURL: 'https://dictionaryapi.com/products/api-collegiate-dictionary' + } + ] + }); + + this.cache = null; + } + + async run(msg) { + try { + const word = await this.fetchWordOfTheDay(); + let data; + if (this.cache.word === word) { + data = this.cache.data; + } else { + const { body } = await request + .get(`https://www.dictionaryapi.com/api/v3/references/collegiate/json/${word}`) + .query({ key: WEBSTER_KEY }); + data = body[0]; + this.cache = { word, data }; + } + return msg.say(stripIndents` + **${data.meta.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!`); + } + } + + async fetchWordOfTheDay() { + const { text } = await request.get('https://www.merriam-webster.com/word-of-the-day'); + const $ = cheerio.load(text); + return $('div[class="word-and-pronunciation"]').first().children().first().text(); + } +}; diff --git a/package.json b/package.json index e27ce49b..795b512e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "139.5.0", + "version": "139.6.0", "description": "Your personal server companion.", "main": "Xiao.js", "private": true,