From d241afaff472b116761863bb88bfbe2d8b5c1deb Mon Sep 17 00:00:00 2001 From: Tycho Bellers Date: Sun, 11 Sep 2022 22:19:23 -0400 Subject: [PATCH] fix crash when channel displayname is null --- src/index.tsx | 2 +- src/twitch_drops_bot.ts | 48 ++++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 07db2db..f6c8ad4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -657,7 +657,7 @@ async function main() { ignoredGameIds: config["ignored_games"], attemptImpossibleDropCampaigns: config["attempt_impossible_campaigns"], watchStreamsWhenNoDropCampaignsActive: config["watch_streams_when_no_drop_campaigns_active"], - broadcasterIds: config["broadcasters"] + broadcasterIds: config.broadcasters }); setUpNotifiers(bot, config); diff --git a/src/twitch_drops_bot.ts b/src/twitch_drops_bot.ts index 98cdeec..955213a 100644 --- a/src/twitch_drops_bot.ts +++ b/src/twitch_drops_bot.ts @@ -378,25 +378,40 @@ export class TwitchDropsBot extends EventEmitter { await page.setCookie(...cookies); // Convert all game IDs/names to IDs - const games = options?.gameIds ?? []; - const gameIds: string[] = []; - for (const game of games) { - if (isInteger(game)) { - gameIds.push(game); - } else { - const id = await client.getGameIdFromName(game); - if (id) { - logger.debug(`Matched game name "${game}" to ID "${id}"`); - gameIds.push(id); + if (options?.gameIds) { + const games = options?.gameIds ?? []; + const gameIds: string[] = []; + for (const game of games) { + if (isInteger(game)) { + gameIds.push(game); } else { - logger.error("Failed to find game ID from name: " + game); + const id = await client.getGameIdFromName(game); + if (id) { + logger.debug(`Matched game name "${game}" to ID "${id}"`); + gameIds.push(id); + } else { + logger.error("Failed to find game ID from name: " + game); + } } } - } - if (options?.gameIds) { options.gameIds = gameIds; } + // Convert Twitch URLs to broadcaster usernames + if (options?.broadcasterIds) { + const broadcasters = options?.broadcasterIds ?? []; + const broadcasterUsernames = []; + for (const broadcaster of broadcasters) { + const match = broadcaster.match(/^https?:\/\/www\.twitch\.tv\/(.+)$/); + if (match) { + broadcasterUsernames.push(match[1]); + } else { + broadcasterUsernames.push(broadcaster); + } + } + options.broadcasterIds = broadcasterUsernames; + } + return new TwitchDropsBot(page, client, options); } @@ -586,7 +601,7 @@ export class TwitchDropsBot extends EventEmitter { for (let i = 0; i < this.#broadcasterIds.length; ++i) { if (campaign.allow && campaign.allow.isEnabled && campaign.allow.channels) { for (const channel of campaign.allow.channels) { - if (channel.displayName.toLowerCase() === this.#broadcasterIds[i].toLowerCase()) { + if (channel.displayName && channel.displayName.toLowerCase() === this.#broadcasterIds[i].toLowerCase()) { return i; } } @@ -903,7 +918,10 @@ export class TwitchDropsBot extends EventEmitter { } logger.info("stream: " + streamUrl); - const dropProgressComponent = new DropProgressComponent({requireProgress: false, exitOnClaim: false}); + const dropProgressComponent = new DropProgressComponent({ + requireProgress: false, + exitOnClaim: false + }); const components: Component[] = [ dropProgressComponent,