mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 14:00:22 +02:00
Google Doodle Command
This commit is contained in:
@@ -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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "49.0.0",
|
"version": "49.1.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Shard.js",
|
"main": "Shard.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user