From 22d7125fed85908a56dcfb9533bcbdcb79d01988 Mon Sep 17 00:00:00 2001 From: Tobiah Date: Tue, 20 Oct 2020 18:43:56 +0000 Subject: [PATCH] fix(notifier): add awaits on send --- src/notifications/Broadcaster.js | 27 ++++++++++++++------------- src/notifications/Notifier.js | 32 ++++++++++++++++---------------- src/settings/MessageManager.js | 7 ++++++- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/notifications/Broadcaster.js b/src/notifications/Broadcaster.js index bbced645e..821df5118 100644 --- a/src/notifications/Broadcaster.js +++ b/src/notifications/Broadcaster.js @@ -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); } } } diff --git a/src/notifications/Notifier.js b/src/notifications/Notifier.js index bc77ac482..23c592b21 100644 --- a/src/notifications/Notifier.js +++ b/src/notifications/Notifier.js @@ -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), ); @@ -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), ); diff --git a/src/settings/MessageManager.js b/src/settings/MessageManager.js index c7ef3aa60..6575af138 100644 --- a/src/settings/MessageManager.js +++ b/src/settings/MessageManager.js @@ -12,6 +12,8 @@ const defMsgOpts = { message: undefined, }; +const lookupWebhooks = process.env.LOOKUP_WEBHOOKS === 'true'; + /** * MessageManager for.... sending messages and deleting them and stuff */ @@ -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) {