Skip to content

Commit

Permalink
feat: cambion
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Sep 22, 2020
1 parent 5d8b435 commit cd58ecb
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 17 deletions.
10 changes: 9 additions & 1 deletion src/CommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const trackableEvents = {
syndicates,
conclave,
deals,
cambion: ['cambion.fass', 'cambion.vome'],
cetus: ['cetus.day', 'cetus.night'],
ostrons: ['cetus.day', 'cetus.night', 'syndicate.ostrons'],
earth: ['earth.day', 'earth.night'],
Expand Down Expand Up @@ -168,6 +169,8 @@ const dyn = [
'solaris\\.cold\\.[0-9]?[0-9]',
'cetus\\.day\\.[0-1]?[0-9]?[0-9]?',
'cetus\\.night\\.[0-1]?[0-9]?[0-9]?',
'cambion\\.fass\\.[0-1]?[0-9]?[0-9]?',
'cambion\\.vome\\.[0-1]?[0-9]?[0-9]?',
...trackableEvents.rss,
...trackableEvents.events,
...rewardTypes,
Expand Down Expand Up @@ -212,6 +215,7 @@ const termToTrackable = (term) => {
const cetusCustomTimeRegex = new RegExp('cetus\\.(day|night)\\.[0-1]?[0-9]?[0-9]?', 'ig');
const earthCustomTimeRegex = new RegExp('earth\\.(day|night)\\.[0-1]?[0-9]?[0-9]?', 'ig');
const solarisCustomTimeRegex = new RegExp('solaris\\.(warm|cold)\\.[0-9]?[0-9]?', 'ig');
const cambionCustomTimeRegex = new RegExp('cambion\\.(fass|vome)\\.[0-1]?[0-9]?[0-9]?', 'ig');

const trackable = {
events: [],
Expand All @@ -220,7 +224,8 @@ const termToTrackable = (term) => {

if (cetusCustomTimeRegex.test(term)
|| earthCustomTimeRegex.test(term)
|| solarisCustomTimeRegex.test(term)) {
|| solarisCustomTimeRegex.test(term)
|| cambionCustomTimeRegex.test(term)) {
trackable.events = term;
return trackable;
}
Expand Down Expand Up @@ -1062,6 +1067,8 @@ const giveawayDefaults = {
},
};

const toTitleCase = str => str.toLowerCase().replace(/\b\w/g, l => l.toUpperCase());

/**
* Common functions for determining common functions
* @typedef {Object} CommonFunctions
Expand Down Expand Up @@ -1112,4 +1119,5 @@ module.exports = {
games,
giveawayDefaults,
markdinate,
toTitleCase,
};
29 changes: 29 additions & 0 deletions src/commands/Worldstate/Cambion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const Command = require('../../models/Command');
const CambionEmbed = require('../../embeds/CambionEmbed');
const { captures } = require('../../CommonFunctions');

class Cambion extends Command {
constructor(bot) {
super(bot, 'warframe.worldstate.cambion', 'cambion', 'Display the currently active Cambion info', 'WARFRAME');
this.regex = new RegExp(`^${this.call}s?\\s?(?:on\\s+${captures.platforms})?`, 'i');
}

async run(message, ctx) {
const platformParam = message.strippedContent.match(captures.platforms);
const platform = platformParam && platformParam.length ? platformParam[0] : ctx.platform;
const entrati = (await this.ws.get('syndicateMissions', platform, ctx.language))
.filter(m => m.syndicate === 'EntratiSyndicate');
const cambion = await this.ws.get('cambionCycle', platform, ctx.language);
if (entrati && entrati.length) {
[cambion.bounty] = entrati;
}

// make the embed
this.messageManager.embed(message, new CambionEmbed(this.bot, cambion), true, true);
return this.messageManager.statuses.SUCCESS;
}
}

module.exports = Cambion;
2 changes: 1 addition & 1 deletion src/commands/Worldstate/Solaris.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Solaris extends Command {
}

async run(message, ctx) {
const platformParam = message.strippedContent.match(/[pcsxb14]{2,3}/ig);
const platformParam = message.strippedContent.match(captures.platforms);
const platform = platformParam && platformParam.length ? platformParam[0] : ctx.platform;
const solaris = (await this.ws.get('syndicateMissions', platform, ctx.language)).filter(m => m.syndicate === 'Solaris United');
const vallis = await this.ws.get('vallisCycle', platform, ctx.language);
Expand Down
52 changes: 52 additions & 0 deletions src/embeds/CambionEmbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

const BaseEmbed = require('./BaseEmbed.js');

const {
timeDeltaToString, fromNow, assetBase, toTitleCase,
} = require('../CommonFunctions.js');

const fass = `${assetBase}/img/FassBanner.png`;
const vome = `${assetBase}/img/VomeBanner.png`;

const makeJobs = (mission) => {
if (mission && mission.jobs && mission.jobs.length) {
const tokens = [];
mission.jobs.forEach((job) => {
const totalStanding = job.standingStages.reduce((a, b) => a + b, 0);
const levels = job.enemyLevels.join(' - ');
const rewards = job.rewardPool instanceof Array ? job.rewardPool.join(' • ') : '';
tokens.push(`\u200B \\⬆ ${totalStanding} - ${job.type} (${levels})`);
if (job.rewardPool[0] && !job.rewardPool[0].startsWith('Pattern Mismatch.')) {
tokens.push(`\\💰 ${rewards}\n`);
}
});

tokens.push(`\n**Expires in ${mission.eta}**`);

return tokens.join('\n');
}
return undefined;
};

class CambionEmbed extends BaseEmbed {
constructor(bot, state) {
super();

this.title = `Cambion Drift Cycle - ${toTitleCase(state.active)}`;
this.color = state.active === 'fass' ? 0xC6733F : 0x415B9E;
this.thumbnail = {
url: state.active === 'fass' ? fass : vome,
};

const next = toTitleCase(state.active === 'fass' ? 'vome' : 'fass');

const nextCtd = `Time remaining until ${next}: ${timeDeltaToString(fromNow(new Date(state.expiry)))}`;
this.description = `${state.bounty ? makeJobs(state.bounty) : ''}\n\n${nextCtd}`;

this.footer.text = `${next} starts `;
this.timestamp = new Date(state.expiry);
}
}

module.exports = CambionEmbed;
42 changes: 28 additions & 14 deletions src/notifications/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function buildNotifiableData(newData, platform, notified) {
const data = {
acolytes: newData.persistentEnemies.filter(e => !notified.includes(e.pid)),
alerts: newData.alerts.filter(a => !a.expired && !notified.includes(a.id)),
baro: newData.voidTrader && !notified.includes(newData.voidTrader.id)
baro: newData.voidTrader && !notified.includes(`${newData.voidTrader.id}${newData.voidTrader.active ? '1' : '0'}`)
? newData.voidTrader
: undefined,
conclave: newData.conclaveChallenges
Expand Down Expand Up @@ -108,6 +108,8 @@ function buildNotifiableData(newData, platform, notified) {
cetusCycleChange: between(newData.cetusCycle.activation, platform),
earthCycleChange: between(newData.earthCycle.activation, platform),
vallisCycleChange: between(newData.vallisCycle.activation, platform),
cambionCycleChange: between(newData.cambionCycle.activation, platform),
cambionCycle: newData.cambionCycle,
cetusCycle: newData.cetusCycle,
earthCycle: newData.earthCycle,
vallisCycle: newData.vallisCycle,
Expand Down Expand Up @@ -178,9 +180,7 @@ class Notifier {
refreshRate = timeout;
}

/**
* Start the notifier
*/
/** Start the notifier */
async start() {
Object.entries(this.worldStates).forEach(([, ws]) => {
ws.on('newData', async (platform, newData) => {
Expand Down Expand Up @@ -220,6 +220,7 @@ class Notifier {
cetusCycle, earthCycle, vallisCycle, tweets, nightwave,
cetusCycleChange, earthCycleChange, vallisCycleChange,
featuredDeals, streams, popularDeals, primeAccess, updates, conclave,
cambionCycle, cambionCycleChange,
}) {
// Send all notifications
const cycleIds = [];
Expand Down Expand Up @@ -256,6 +257,9 @@ class Notifier {
cycleIds.push(
await this.sendVallisCycle(vallisCycle, platform, vallisCycleChange, notifiedIds),
);
cycleIds.push(
await this.sendCambionCycle(cambionCycle, platform, cambionCycleChange, notifiedIds),
);
this.sendUpdates(updates, platform);
this.sendAlerts(alerts, platform);
cycleIds.push(
Expand All @@ -272,7 +276,7 @@ class Notifier {
alreadyNotified.push(
...rawData.persistentEnemies.map(a => a.pid),
...cycleIds,
rawData.voidTrader.id,
`${rawData.voidTrader.id}${rawData.voidTrader.active ? '1' : '0'}`,
...rawData.fissures.map(f => f.id),
...rawData.invasions.map(i => i.id),
...rawData.news.map(n => n.id),
Expand All @@ -281,7 +285,6 @@ class Notifier {
rawData.sortie.id,
...rawData.syndicateMissions.map(m => m.id),
...rawData.flashSales.map(s => s.id),
rawData.voidTrader.id,
...rawData.dailyDeals.map(d => d.id),
...rawData.conclaveChallenges.map(cc => cc.id),
...rawData.weeklyChallenges.map(w => w.id),
Expand Down Expand Up @@ -349,10 +352,21 @@ class Notifier {
}
}

async sendCetusCycle(newCetusCycle, platform, cetusCycleChange, notifiedIds) {
const minutesRemaining = cetusCycleChange ? '' : `.${Math.round(fromNow(newCetusCycle.expiry) / 60000)}`;
const type = `cetus.${newCetusCycle.isDay ? 'day' : 'night'}${minutesRemaining}`;
const embed = new embeds.Cycle({ logger }, newCetusCycle);
async sendCambionCycle(newCycle, platform, cycleChange, notifiedIds) {
const minutesRemaining = cycleChange ? '' : `.${Math.round(fromNow(newCycle.expiry) / 60000)}`;
const type = `cambion.${newCycle.active}${minutesRemaining}`;
if (!notifiedIds.includes(type)) {
await this.broadcaster.broadcast(
new embeds.Cambion({ logger }, newCycle), platform, type,
);
}
return type;
}

async sendCetusCycle(newCycle, platform, cycleChange, notifiedIds) {
const minutesRemaining = cycleChange ? '' : `.${Math.round(fromNow(newCycle.expiry) / 60000)}`;
const type = `cetus.${newCycle.isDay ? 'day' : 'night'}${minutesRemaining}`;
const embed = new embeds.Cycle({ logger }, newCycle);
if (!notifiedIds.includes(type)) {
await this.broadcaster.broadcast(embed, platform, type);
}
Expand All @@ -379,12 +393,12 @@ class Notifier {
await Promise.all(newDarvoDeals.map(d => this.broadcaster.broadcast(new embeds.Darvo({ logger }, d, platform), platform, 'darvo')));
}

async sendEarthCycle(newEarthCycle, platform, earthCycleChange, notifiedIds) {
const minutesRemaining = earthCycleChange ? '' : `.${Math.round(fromNow(newEarthCycle.expiry) / 60000)}`;
const type = `earth.${newEarthCycle.isDay ? 'day' : 'night'}${minutesRemaining}`;
async sendEarthCycle(newCycle, platform, cycleChange, notifiedIds) {
const minutesRemaining = cycleChange ? '' : `.${Math.round(fromNow(newCycle.expiry) / 60000)}`;
const type = `earth.${newCycle.isDay ? 'day' : 'night'}${minutesRemaining}`;
if (!notifiedIds.includes(type)) {
await this.broadcaster.broadcast(
new embeds.Cycle({ logger }, newEarthCycle), platform, type,
new embeds.Cycle({ logger }, newCycle), platform, type,
);
}
return type;
Expand Down
1 change: 1 addition & 0 deletions src/notifications/NotifierUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const embeds = {
Alert: require('../embeds/AlertEmbed'),
Arbitration: require('../embeds/ArbitrationEmbed'),
Acolyte: require('../embeds/AcolyteEmbed'),
Cambion: require('../embeds/CambionEmbed'),
Conclave: require('../embeds/ConclaveChallengeEmbed'),
Darvo: require('../embeds/DarvoEmbed'),
Enemy: require('../embeds/EnemyEmbed'),
Expand Down
4 changes: 3 additions & 1 deletion src/resources/trackables.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
"nightwave.daily",
"nightwave.elite",
"nightwave.weekly",
"outposts"
"outposts",
"cambion.fass",
"cambion.vome"
],
"opts": [
"all",
Expand Down

0 comments on commit cd58ecb

Please sign in to comment.