Skip to content

Commit

Permalink
feat: acolyte depart tracking, earth tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Aug 16, 2018
1 parent b2cfb44 commit 947bb09
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/CommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const trackableEvents = {
conclave,
deals,
cetus: ['cetus.day', 'cetus.night'],
earth: ['earth.day', 'earth.night'],
};

const trackableItems = {
Expand All @@ -64,12 +65,13 @@ const trackableItems = {
*/
const termToTrackable = (term) => {
const cetusCustomTimeRegex = new RegExp('cetus\\.(day|night)\\.[0-1]?[0-9]?[0-9]?', 'ig');
const earthCustomTimeRegex = new RegExp('cetus\\.(day|night)\\.[0-1]?[0-9]?[0-9]?', 'ig');
const trackable = {
events: [],
items: [],
};

if (cetusCustomTimeRegex.test(term)) {
if (cetusCustomTimeRegex.test(term) || earthCustomTimeRegex.test(term)) {
trackable.events = term;
return trackable;
}
Expand Down Expand Up @@ -137,7 +139,7 @@ const trackablesFromParameters = (params) => {
return trackables;
};

const eventsOrItems = new RegExp(`cetus\\.day\\.[0-1]?[0-9]?[0-9]|cetus\\.night\\.[0-1]?[0-9]?[0-9]|${eventTypes.join('|')}|${rewardTypes.join('|')}|${opts.join('|')}`, 'ig');
const eventsOrItems = new RegExp(`earth\\.day\\.[0-1]?[0-9]?[0-9]|earth\\.night\\.[0-1]?[0-9]?[0-9]|cetus\\.day\\.[0-1]?[0-9]?[0-9]|cetus\\.night\\.[0-1]?[0-9]?[0-9]|${eventTypes.join('|')}|${rewardTypes.join('|')}|${opts.join('|')}`, 'ig');

const getRandomWelcome = () => welcomes[Math.floor(Math.random() * welcomes.length)];

Expand Down
5 changes: 2 additions & 3 deletions src/commands/Settings/Prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ class Prefix extends Command {
this.requiresAuth = true;
}

async run(message) {
async run(message, ctx) {
const prefix = message.strippedContent.match(this.regex)[1];
if (!prefix) {
const configuredPrefix = this.settings.getChannelPrefix(message.channel);
this.messageManager.embed(message, {
title: 'Usage',
type: 'rich',
color: 0x0000ff,
fields: [
{
name: `${configuredPrefix}${this.call} <prefix>`,
name: `${ctx.prefix}${this.call} <prefix>`,
value: 'Set the channel\'s custom prefix',
},
],
Expand Down
9 changes: 2 additions & 7 deletions src/embeds/EarthCycleEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ class EarthCycleEmbed extends BaseEmbed {
this.thumbnail = {
url: state.isCetus ? 'https://i.imgur.com/Ph337PR.png' : 'https://i.imgur.com/oR6Sskf.png',
};
this.fields = [
{
name: '_ _',
value: `Time remaining until ${state.isDay ? 'night' : 'day'}: ${timeDeltaToString(fromNow(new Date(state.expiry)))}`
+ `${state.bountyExpiry ? `\nBounties expire in ${timeDeltaToString(fromNow(new Date(state.bountyExpiry)))}` : ''}`,
},
];
this.description = `Time remaining until ${state.isDay ? 'night' : 'day'}: ${timeDeltaToString(fromNow(new Date(state.expiry)))}`
+ `${state.bountyExpiry ? `\nBounties expire in ${timeDeltaToString(fromNow(new Date(state.bountyExpiry)))}` : ''}`;
this.footer.text = `${state.isDay ? 'Night' : 'Day'} starts `;
this.timestamp = new Date(state.expiry);
}
Expand Down
18 changes: 15 additions & 3 deletions src/notifications/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Notifier {
const ids = await this.getNotifiedIds(platform, this.bot.shardId);
// Set up data to notify
const acolytesToNotify = newData.persistentEnemies
.filter(e => !ids.includes(e.pid) && e.isDiscovered);
.filter(e => !ids.includes(e.pid));
const alertsToNotify = newData.alerts
.filter(a => !ids.includes(a.id) && !a.expired);
const baroToNotify = newData.voidTrader && !ids.includes(newData.voidTrader.psId)
Expand Down Expand Up @@ -110,6 +110,7 @@ class Notifier {
const streamsToNotify = newData.news
.filter(n => !ids.includes(n.id) && n.stream && n.translations.en);
const cetusCycleChange = !ids.includes(newData.cetusCycle.id) && newData.cetusCycle.expiry;
const earthCycleChange = !ids.includes(`earthCycle${new Date(newData.earthCycle).getTime()}`) && newData.earthCycle.expiry;
// Concat all notified ids
notifiedIds = notifiedIds
.concat(newData.alerts.map(a => a.id))
Expand All @@ -124,7 +125,8 @@ class Notifier {
.concat(newData.sortie ? [newData.sortie.id] : [])
.concat(newData.syndicateMissions.map(m => m.id))
.concat(newData.voidTrader ? [`${newData.voidTrader.id}${newData.voidTrader.inventory.length}`] : [])
.concat([newData.cetusCycle.id]);
.concat([newData.cetusCycle.id])
.concat([`earthCycle${new Date(newData.earthCycle).getTime()}`]);

// Send all notifications
await this.updateNotified(notifiedIds, platform);
Expand Down Expand Up @@ -164,6 +166,7 @@ class Notifier {
newData.cetusCycle.bountyExpiry = ostron.expiry;
}
await this.sendCetusCycle(newData.cetusCycle, platform, cetusCycleChange);
await this.sendEarthCycle(newData.earthCycle, platform, earthCycleChange);
this.sendUpdates(updatesToNotify, platform);
await this.sendAlerts(alertsToNotify, platform);
}
Expand All @@ -190,7 +193,7 @@ class Notifier {
await Promise.all(newAcolytes.map(async a => this.broadcaster.broadcast(new EnemyEmbed(
this.bot,
[a], platform,
), platform, 'enemies', null, 3600000)));
), platform, `enemies${a.isDiscovered ? '' : '.departed'}`, null, 3600000)));
}

async sendAlerts(newAlerts, platform) {
Expand Down Expand Up @@ -367,6 +370,15 @@ class Notifier {
platform, type, null, fromNow(newCetusCycle.expiry),
);
}

async sendEarthCycle(newEarthCycle, platform, cetusCycleChange) {
const minutesRemaining = cetusCycleChange ? '' : `.${Math.round(fromNow(newEarthCycle.expiry) / 60000)}`;
const type = `earth.${newEarthCycle.isDay ? 'day' : 'night'}${minutesRemaining}`;
await this.broadcaster.broadcast(
new EarthCycleEmbed(this.bot, newEarthCycle),
platform, type, null, fromNow(newEarthCycle.expiry),
);
}
}

module.exports = Notifier;
6 changes: 5 additions & 1 deletion src/resources/trackables.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"deals.featured",
"deals.popular",
"enemies",
"enemies.departed",
"conclave.weeklies",
"conclave.dailies",
"syndicate.arbiters",
Expand All @@ -67,6 +68,8 @@
"streams",
"cetus.day",
"cetus.night",
"earth.day",
"earth.night",
"syndicate.ostrons",
"syndicate.assassins",
"operations",
Expand Down Expand Up @@ -175,7 +178,8 @@
"fissures.assault",
"fissures.evacuation",
"fissures",
"cetus"
"cetus",
"earth"
],
"fissures":[
"fissures.t1.excavation",
Expand Down
10 changes: 5 additions & 5 deletions src/settings/DatabaseQueries/SettingsQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ class SettingsQueries {
* Resets the custom prefix for this guild to the bot's globally configured prefix
* @param {Guild} guild The Discord guild for which to set the response setting
* @param {string} setting Name of the setting to set
* @param {string|boolean} val value of the setting to be set
* @param {string|boolean} value value of the setting to be set
* @returns {Promise}
*/
async setGuildSetting(guild, setting, val) {
async setGuildSetting(guild, setting, value) {
if (typeof setting === 'undefined' || typeof value === 'undefined') return false;
const promises = [];
guild.channels.array().forEach((channel) => {
promises.push(this.setChannelSetting(channel, setting, val));
guild.channels.forEach((channel) => {
promises.push(this.setChannelSetting(channel, setting, value));
});
return Promise.all(promises);
}
Expand All @@ -142,7 +142,7 @@ class SettingsQueries {
*/
async deleteGuildSetting(guild, setting) {
const promises = [];
guild.channels.array().forEach((channel) => {
guild.channels.forEach((channel) => {
promises.push(this.deleteChannelSetting(channel, setting));
});
return Promise.all(promises);
Expand Down

0 comments on commit 947bb09

Please sign in to comment.