Google Doodle Command

This commit is contained in:
Daniel Odendahl Jr
2017-10-21 01:54:40 +00:00
parent dc4cf18c91
commit 08007fa4e7
2 changed files with 47 additions and 1 deletions
+46
View File
@@ -0,0 +1,46 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
module.exports = class GoogleDoodleCommand extends Command {
constructor(client) {
super(client, {
name: 'google-doodle',
group: 'other',
memberName: 'google-doodle',
description: 'Responds with a Google doodle, either the latest or a random one from a specific month/year.',
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'month',
prompt: 'What month would you like to get doodles for?',
type: 'integer',
default: 'latest',
validate: month => {
if (month < 13 && month > 0) return true;
return 'Invalid month, please enter a number from 1-12.';
}
},
{
key: 'year',
prompt: 'What year would you like to get doodles for?',
type: 'integer',
default: ''
}
]
});
}
async run(msg, { month, year }) {
const latest = month === 'latest';
if (latest) month = new Date().getMonth() + 1;
if (!year) year = new Date().getFullYear();
try {
const { body } = await snekfetch.get(`https://www.google.com/doodles/json/${year}/${month}`);
if (!body.length) return msg.say('Could not find any results.');
const data = body[latest ? 0 : Math.floor(Math.random() * body.length)];
return msg.say(data.share_text, { files: [`https:${data.url}`] });
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "49.0.0",
"version": "49.1.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {