diff --git a/commands/events/holidays.js b/commands/events/holidays.js new file mode 100644 index 00000000..944a09a2 --- /dev/null +++ b/commands/events/holidays.js @@ -0,0 +1,49 @@ +const { Command } = require('discord.js-commando'); +const snekfetch = require('snekfetch'); +const { GOOGLE_KEY, GOOGLE_CALENDAR_ID } = process.env; + +module.exports = class HolidaysCommand extends Command { + constructor(client) { + super(client, { + name: 'holidays', + aliases: ['google-calendar'], + group: 'events', + memberName: 'holidays', + description: 'Responds with today\'s holidays.' + }); + } + + async run(msg) { + try { + const { body } = await snekfetch + .get(`https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(GOOGLE_CALENDAR_ID)}/events`) + .query({ + maxResults: 10, + orderBy: 'startTime', + singleEvents: true, + timeMax: this.tomorrow().toISOString(), + timeMin: this.today().toISOString(), + key: GOOGLE_KEY + }); + if (!body.items.length) return msg.say('There are no holidays today...'); + return msg.say(body.items.map(holiday => holiday.summary).join('\n')); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + today() { + const now = new Date(); + now.setHours(0); + now.setMinutes(0); + now.setSeconds(0); + now.setMilliseconds(0); + return now; + } + + tomorrow() { + const today = this.today(); + today.setDate(today.getDate() + 1); + return today; + } +}; diff --git a/commands/search/kickstarter.js b/commands/search/kickstarter.js index cd813213..ec02a2ee 100644 --- a/commands/search/kickstarter.js +++ b/commands/search/kickstarter.js @@ -40,9 +40,9 @@ module.exports = class KickstarterCommand extends Command { .setDescription(shorten(data.blurb)) .setThumbnail(data.photo ? data.photo.full : null) .addField('❯ Goal', - `${data.currency_symbol}${data.goal}`, true) + `$${data.goal}`, true) .addField('❯ Pledged', - `${data.currency_symbol}${data.pledged}`, true) + `$${data.pledged}`, true) .addField('❯ Backers', data.backers_count, true) .addField('❯ Creator', diff --git a/package.json b/package.json index 10338bc2..2eaf5beb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "66.3.0", + "version": "66.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/util/Util.js b/util/Util.js index 7881ed1b..b6d4192e 100644 --- a/util/Util.js +++ b/util/Util.js @@ -51,10 +51,6 @@ class Util { return arr; } - static formatNumber(number, dollar = false) { - return `${dollar ? '$' : ''}${number.toLocaleString('en-US', { maximumFractionDigits: 2 })}`; - } - static cleanXML(text) { return text .replace(/
/g, '')