Add a tweet for when a new stage has been posted

This commit is contained in:
Matt Isenhower
2017-11-25 14:42:29 -08:00
parent 9a9c8cdb66
commit ced0594c4f
3 changed files with 39 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ const ScheduleTweet = require('./twitter/ScheduleTweet');
const GearTweet = require('./twitter/GearTweet');
const SalmonRunTweet = require('./twitter/SalmonRunTweet');
const NewWeaponTweet = require('./twitter/NewWeaponTweet');
const NewStageTweet = require('./twitter/NewStageTweet');
const SplatfestTweet = require('./twitter/SplatfestTweet');
let tweets = [
@@ -11,6 +12,7 @@ let tweets = [
new GearTweet,
new SalmonRunTweet,
new NewWeaponTweet,
new NewStageTweet,
new SplatfestTweet('na'),
new SplatfestTweet('eu'),
new SplatfestTweet('jp'),

View File

@@ -0,0 +1,32 @@
const TwitterPostBase = require('./TwitterPostBase');
const { readJson } = require('../utilities');
const path = require('path');
const fs = require('fs');
const stagesPath = path.resolve('storage/stages.json');
const splatnetAssetPath = path.resolve('public/assets/splatnet');
class NewStageTweet extends TwitterPostBase {
getKey() { return 'newstage'; }
getName() { return 'New Stage'; }
getStages() {
return readJson(stagesPath);
}
getData() {
return this.getStages().find(s => s.first_seen == this.getDataTime());
}
getImage(data) {
return fs.readFileSync(splatnetAssetPath + data.image);
}
getText(data) {
let hours = (data.first_available - this.getDataTime()) / 60 / 60;
let duration = (hours == 1) ? '1 hour' : `${hours} hours`;
return `The first schedules for ${data.name} have been posted! Start playing the new stage in ${duration}. #splatoon2`;
}
}
module.exports = NewStageTweet;

View File

@@ -13,6 +13,10 @@ class ScheduleTweet extends TwitterPostBase {
return readData('schedules.json');
}
getStages() {
return readJson(stagesPath);
}
getData() {
return this.getSchedules().regular.find(s => s.start_time == this.getDataTime());
}
@@ -27,7 +31,7 @@ class ScheduleTweet extends TwitterPostBase {
getText(data) {
// Load known stages
let stages = readJson(stagesPath);
let stages = this.getStages();
for (let stage of [data.stage_a, data.stage_b]) {
let stageInfo = stages.find(s => s.id == stage.id);