Skip to content

Commit

Permalink
fix crash when channel displayname is null
Browse files Browse the repository at this point in the history
  • Loading branch information
TychoTheTaco committed Sep 12, 2022
1 parent a5e9ef1 commit d241afa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 33 additions & 15 deletions src/twitch_drops_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d241afa

Please sign in to comment.