mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-13 15:58:06 +02:00
Neko Atsume Password Command
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
|
const { today, tomorrow } = require('../../util/Util');
|
||||||
const { GOOGLE_KEY, GOOGLE_CALENDAR_ID } = process.env;
|
const { GOOGLE_KEY, GOOGLE_CALENDAR_ID } = process.env;
|
||||||
|
|
||||||
module.exports = class HolidaysCommand extends Command {
|
module.exports = class HolidaysCommand extends Command {
|
||||||
@@ -21,8 +22,8 @@ module.exports = class HolidaysCommand extends Command {
|
|||||||
maxResults: 10,
|
maxResults: 10,
|
||||||
orderBy: 'startTime',
|
orderBy: 'startTime',
|
||||||
singleEvents: true,
|
singleEvents: true,
|
||||||
timeMax: this.tomorrow().toISOString(),
|
timeMax: tomorrow().toISOString(),
|
||||||
timeMin: this.today().toISOString(),
|
timeMin: today().toISOString(),
|
||||||
key: GOOGLE_KEY
|
key: GOOGLE_KEY
|
||||||
});
|
});
|
||||||
if (!body.items.length) return msg.say('There are no holidays today...');
|
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!`);
|
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "69.1.0",
|
"version": "69.2.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -72,6 +72,22 @@ class Util {
|
|||||||
return body.data.images[Math.floor(Math.random() * body.data.images.length)].link;
|
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) {
|
static cleanXML(text) {
|
||||||
return text
|
return text
|
||||||
.replace(/<br \/>/g, '')
|
.replace(/<br \/>/g, '')
|
||||||
|
|||||||
Reference in New Issue
Block a user