mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 06:42:51 +02:00
Word of the day Command
This commit is contained in:
@@ -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."
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -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
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user