Word of the day Command

This commit is contained in:
Dragon Fire
2021-05-15 18:00:49 -04:00
parent 78856d2e19
commit 7b6cd29039
3 changed files with 60 additions and 2 deletions
+4 -1
View File
@@ -105,5 +105,8 @@
"Ask yourself this question: \"Is my attitude worth catching?\"", "Ask yourself this question: \"Is my attitude worth catching?\"",
"The evening promises romantic interests.", "The evening promises romantic interests.",
"Keep in mind that it's the journey and not the destination that counts.", "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."
] ]
+55
View File
@@ -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();
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "139.5.0", "version": "139.6.0",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"private": true, "private": true,