Neko Atsume Password Command

This commit is contained in:
Daniel Odendahl Jr
2018-03-18 14:37:33 +00:00
parent d59c4d44af
commit aabc1cda51
4 changed files with 88 additions and 18 deletions
+3 -17
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { today, tomorrow } = require('../../util/Util');
const { GOOGLE_KEY, GOOGLE_CALENDAR_ID } = process.env;
module.exports = class HolidaysCommand extends Command {
@@ -21,8 +22,8 @@ module.exports = class HolidaysCommand extends Command {
maxResults: 10,
orderBy: 'startTime',
singleEvents: true,
timeMax: this.tomorrow().toISOString(),
timeMin: this.today().toISOString(),
timeMax: tomorrow().toISOString(),
timeMin: today().toISOString(),
key: GOOGLE_KEY
});
if (!body.items.length) return msg.say('There are no holidays today...');
@@ -31,19 +32,4 @@ module.exports = class HolidaysCommand extends Command {
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;
}
};
+68
View File
@@ -0,0 +1,68 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
const { list, duration, tomorrow } = require('../../util/Util');
const { GOLD_FISH_EMOJI_ID, SILVER_FISH_EMOJI_ID } = process.env;
const locales = ['en', 'jp'];
module.exports = class NekoAtsumePasswordCommand extends Command {
constructor(client) {
super(client, {
name: 'neko-atsume-password',
group: 'events',
memberName: 'neko-atsume-password',
description: 'Responds with today\'s Neko Atsume password.',
args: [
{
key: 'locale',
prompt: `What locale do you want to use? Either ${list(locales, 'or')}.`,
type: 'string',
default: 'en',
validate: locale => {
if (locales.includes(locale.toLowerCase())) return true;
return `Invalid locale, please enter either ${list(locales, 'or')}.`;
},
parse: locale => locale.toLowerCase()
}
]
});
}
async run(msg, { locale }) {
try {
const data = await this.fetchPassword(locale);
return msg.say(stripIndents`
The current Neko Atsume password is **${data.password}**.
It will expire in **${duration(data.expires - data.date)}**.
${data.gold} ${this.goldFish}
${data.silver} ${this.silverFish}
`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async fetchPassword(locale) {
const { text } = await snekfetch
.get(`http://hpmobile.jp/app/nekoatsume/neko_daily${locale !== 'jp' ? `_${locale}` : ''}.php`);
const data = text.split(',');
const date = new Date();
date.setUTCHours(date.getUTCHours() + 9);
return {
password: data[1],
silver: data[2],
gold: data[3],
date,
expires: tomorrow(9)
};
}
get goldFish() {
return GOLD_FISH_EMOJI_ID ? `<gold_fish:${GOLD_FISH_EMOJI_ID}>` : 'Gold Fish';
}
get silverFish() {
return SILVER_FISH_EMOJI_ID ? `<silver_fish:${SILVER_FISH_EMOJI_ID}>` : 'Silver Fish';
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "69.1.0",
"version": "69.2.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+16
View File
@@ -72,6 +72,22 @@ class Util {
return body.data.images[Math.floor(Math.random() * body.data.images.length)].link;
}
today(timeZone) {
const now = new Date();
if (timeZone) now.setUTCHours(now.getUTCHours() + timeZone);
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
now.setMilliseconds(0);
return now;
}
tomorrow(timeZone) {
const today = Util.today(timeZone);
today.setDate(today.getDate() + 1);
return today;
}
static cleanXML(text) {
return text
.replace(/<br \/>/g, '')