snekfetch 4.0.0

This commit is contained in:
Daniel Odendahl Jr
2018-02-26 22:10:01 +00:00
parent a4767134e5
commit 9aaf21913b
22 changed files with 45 additions and 40 deletions
+2 -1
View File
@@ -14,7 +14,8 @@ module.exports = class DoomsdayClockCommand extends Command {
async run(msg) {
try {
const { text } = await snekfetch.get('https://thebulletin.org/timeline');
const { raw } = await snekfetch.get('https://thebulletin.org/timeline');
const text = raw.toString();
const time = text.match(/IT IS (.+) MINUTES TO MIDNIGHT/)[0];
const desc = text.match(/<div class="body-text"><span class="timeline-year">(.+)<\/span>: (.+)<\/div>/);
return msg.say(stripIndents`
+3 -3
View File
@@ -33,8 +33,8 @@ module.exports = class TodayInHistoryCommand extends Command {
async run(msg, { month, day }) {
const date = month && day ? `/${month}/${day}` : '';
try {
const { text } = await snekfetch.get(`http://history.muffinlabs.com/date${date}`);
const body = JSON.parse(text);
const { raw } = await snekfetch.get(`http://history.muffinlabs.com/date${date}`);
const body = JSON.parse(raw.toString());
const events = body.data.Events;
const event = events[Math.floor(Math.random() * events.length)];
const embed = new MessageEmbed()
@@ -47,7 +47,7 @@ module.exports = class TodayInHistoryCommand extends Command {
event.links.map(link => `[${link.title}](${link.link.replace(/\)/g, '%29')})`).join(', '));
return msg.embed(embed);
} catch (err) {
if (err.status === 404 || err.status === 500) return msg.say('Invalid date.');
if (err.statusCode === 404 || err.statusCode === 500) return msg.say('Invalid date.');
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}