mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 22:32:52 +02:00
Today Date Specification
This commit is contained in:
+43
-15
@@ -6,25 +6,53 @@ module.exports = class TodayCommand extends Command {
|
|||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'today',
|
name: 'today',
|
||||||
|
aliases: ['event'],
|
||||||
group: 'random',
|
group: 'random',
|
||||||
memberName: 'today',
|
memberName: 'today',
|
||||||
description: 'Responds with a random event that occurred today sometime in history.',
|
description: 'Responds with an event that occurred today in history, or on a specific day.',
|
||||||
clientPermissions: ['EMBED_LINKS']
|
clientPermissions: ['EMBED_LINKS'],
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
key: 'month',
|
||||||
|
prompt: 'Which month do you want events for?',
|
||||||
|
type: 'integer',
|
||||||
|
default: '',
|
||||||
|
validate: (month) => {
|
||||||
|
if (month < 13 && month > 0) return true;
|
||||||
|
else return 'Please enter a valid month.';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'day',
|
||||||
|
prompt: 'Which day do you want events for?',
|
||||||
|
type: 'integer',
|
||||||
|
default: '',
|
||||||
|
validate: (day) => {
|
||||||
|
if (day < 32 && day > 0) return true;
|
||||||
|
else return 'Please enter a valid day.';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg) {
|
async run(msg, args) {
|
||||||
const { text } = await snekfetch
|
const { month, day } = args;
|
||||||
.get('http://history.muffinlabs.com/date');
|
try {
|
||||||
const body = JSON.parse(text);
|
const { text } = await snekfetch
|
||||||
const events = body.data.Events;
|
.get(`http://history.muffinlabs.com/date${month && day ? `/${month}/${day}` : ''}`);
|
||||||
const event = events[Math.floor(Math.random() * events.length)];
|
const body = JSON.parse(text);
|
||||||
const embed = new MessageEmbed()
|
const events = body.data.Events;
|
||||||
.setColor(0x9797FF)
|
const event = events[Math.floor(Math.random() * events.length)];
|
||||||
.setURL(body.url)
|
const embed = new MessageEmbed()
|
||||||
.setTitle(`On this day (${body.date})...`)
|
.setColor(0x9797FF)
|
||||||
.setTimestamp()
|
.setURL(body.url)
|
||||||
.setDescription(`${event.year}: ${event.text}`);
|
.setTitle(`On this day (${body.date})...`)
|
||||||
return msg.embed(embed);
|
.setTimestamp()
|
||||||
|
.setDescription(`${event.year}: ${event.text}`);
|
||||||
|
return msg.embed(embed);
|
||||||
|
} catch (err) {
|
||||||
|
return msg.say(`An error occurred: \`${err.message}\`. You likely entered an invalid date.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "27.2.0",
|
"version": "27.2.1",
|
||||||
"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