Skip to content

Commit

Permalink
fix: de-dupe platforms, spot-load user data
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Mar 19, 2021
1 parent c832209 commit fde50be
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/CommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const isVulgarCheck = new RegExp('(n[i!1]gg[e3]r|n[i!1]gg[ua]|h[i!1]tl[e3]r|n[a@
* Allowed platforms
* @type {Array.<string>}
*/
const platforms = ['pc', 'ps4', 'xb1', 'swi']
.concat((process.env.PLATFORMS || '').split(',').filter(p => p));
const platforms = Array.from(new Set(['pc', 'ps4', 'xb1', 'swi']
.concat((process.env.PLATFORMS || '').split(',').filter(p => p))));

/**
* Games to enable.
Expand Down
4 changes: 2 additions & 2 deletions src/embeds/TwitchEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class TwitchEmbed extends BaseEmbed {
this.url = `https://www.twitch.tv/${streamData.user_login}`;

this.image = {
url: streamData.thumbnail_url
url: `${streamData.thumbnail_url
.replace('{width}', '1280')
.replace('{height}', '720'),
.replace('{height}', '720')}?${Date.now()}`,
};

this.color = 6570405;
Expand Down
9 changes: 5 additions & 4 deletions src/notifications/twitch/TwitchMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,18 @@ class TwitchMonitor extends EventEmitter {
return success;
}

async #spotLoadGame (gameId) {
async spotLoadGame(gameId) {
this.#handleGameList(await TwitchApi.fetchGames([gameId]));
return this.#gameData[gameId];
}

async #spotLoadStream (channel) {
async spotLoadStream(channel) {
return this.#handleStreamList(await TwitchApi.fetchStreams([channel]));
}

async #spotLoadUser (user) {
return this.#handleUserList(await TwitchApi.fetchUsers([user]));
async spotLoadUser(user) {
await this.#handleUserList(await TwitchApi.fetchUsers([user]));
return this.#userData[user];
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/notifications/twitch/TwitchNotifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ class TwitchNotifier {
}
logger.info('Ready', 'Twitch');

this.#monitor.on('live', (streamData) => {
this.#monitor.on('live', async (streamData) => {
if (this.enabled) {
if (!streamData.user.display_name) {
streamData.user = await this.#monitor.spotLoadUser(streamData.user_name);
}

const embed = new TwitchEmbed(streamData);
let id = `${streamData.user_login}.live`;
// add warframe type filtering for ids...
Expand All @@ -61,6 +65,7 @@ class TwitchNotifier {
id = `${streamData.user_login}.other.live`;
}
}

for (const platform of this.#activePlatforms) {
this.#broadcaster.broadcast(embed, platform, id);
}
Expand Down

0 comments on commit fde50be

Please sign in to comment.