Skip to content

Commit

Permalink
fix(notifier): add awaits on send
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Oct 20, 2020
1 parent e764289 commit 22d7125
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
27 changes: 14 additions & 13 deletions src/notifications/Broadcaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ class Broadcaster {
.getAgnosticNotifications(type, platform, items, { shard, shards: this.shards });
for (const result of channels) {
const ctx = await this.settings.getCommandContext(result.channelId);
if (embed.locale && ctx.language.toLowerCase() !== embed.locale.toLowerCase()) {
continue;
}
const localeMatch = !(embed.locale
&& ctx.language.toLowerCase() !== embed.locale.toLowerCase());

const guild = Object.entries(guilds)
.filter(([, g]) => g.channels.includes(result.channelId))[0][1];
try {
const prepend = await this.settings.getPing(guild, (items || []).concat([type]));
if (!embed.embeds) {
await this.webhook(ctx, { text: prepend, embed: this.wrap(embed, ctx) });
} else {
await this.webhook(ctx, { text: prepend, embed });
if (localeMatch) {
const guild = Object.entries(guilds)
.filter(([, g]) => g.channels.includes(result.channelId))[0][1];
try {
const prepend = await this.settings.getPing(guild, (items || []).concat([type]));
if (!embed.embeds) {
await this.webhook(ctx, { text: prepend, embed: this.wrap(embed, ctx) });
} else {
await this.webhook(ctx, { text: prepend, embed });
}
} catch (e) {
logger.error(e);
}
} catch (e) {
logger.error(e);
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/notifications/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,26 +228,26 @@ class Notifier {
logger.silly('[N] sending new data...');
await this.sendAcolytes(acolytes, platform);
if (baro) {
this.sendBaro(baro, platform);
await this.sendBaro(baro, platform);
}
if (conclave && conclave.length > 0) {
this.sendConclaveDailies(conclave, platform);
await this.sendConclaveDailies(conclave, platform);
await this.sendConclaveWeeklies(conclave, platform);
}
if (tweets && tweets.length > 0) {
this.sendTweets(tweets, platform);
await this.sendTweets(tweets, platform);
}
this.sendDarvo(dailyDeals, platform);
this.sendEvent(events, platform);
this.sendFeaturedDeals(featuredDeals, platform);
this.sendFissures(fissures, platform);
this.sendNews(news, platform);
this.sendStreams(streams, platform);
this.sendPopularDeals(popularDeals, platform);
this.sendPrimeAccess(primeAccess, platform);
this.sendInvasions(invasions, platform);
this.sendSortie(sortie, platform);
this.sendSyndicates(syndicateM, platform);
await this.sendDarvo(dailyDeals, platform);
await this.sendEvent(events, platform);
await this.sendFeaturedDeals(featuredDeals, platform);
await this.sendFissures(fissures, platform);
await this.sendNews(news, platform);
await this.sendStreams(streams, platform);
await this.sendPopularDeals(popularDeals, platform);
await this.sendPrimeAccess(primeAccess, platform);
await this.sendInvasions(invasions, platform);
await this.sendSortie(sortie, platform);
await this.sendSyndicates(syndicateM, platform);
cycleIds.push(
await this.sendCetusCycle(cetusCycle, platform, cetusCycleChange, notifiedIds),
);
Expand All @@ -260,8 +260,8 @@ class Notifier {
cycleIds.push(
await this.sendCambionCycle(cambionCycle, platform, cambionCycleChange, notifiedIds),
);
this.sendUpdates(updates, platform);
this.sendAlerts(alerts, platform);
await this.sendUpdates(updates, platform);
await this.sendAlerts(alerts, platform);
cycleIds.push(
await this.sendSentientOutposts(rawData.sentientOutposts, platform, notifiedIds),
);
Expand Down
7 changes: 6 additions & 1 deletion src/settings/MessageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const defMsgOpts = {
message: undefined,
};

const lookupWebhooks = process.env.LOOKUP_WEBHOOKS === 'true';

/**
* MessageManager for.... sending messages and deleting them and stuff
*/
Expand Down Expand Up @@ -329,10 +331,13 @@ class MessageManager {
logger.error(`Could not finish adding webhook for ${ctx.channel}`);
return false;
}
// eslint-disable-next-line no-param-reassign
ctx.webhook = webhook;
return this.webhook(ctx, { text, embed });
}
if (!lookupWebhooks) {
logger.error(`Could not obtain webhook for ${ctx.channel.id}`);
return false;
}
logger.debug(`Leveraging worker route for obtaining webhook... ${ctx.channel.id}`);
let webhook = await this.client.getWebhook(ctx.channel);
if (webhook && webhook.id && webhook.token) {
Expand Down

0 comments on commit 22d7125

Please sign in to comment.