Skip to content

Commit

Permalink
schedulers(liveStreams): filter invalid channels before request
Browse files Browse the repository at this point in the history
Signed-off-by: TRACTION <19631364+iamtraction@users.noreply.github.com>
  • Loading branch information
iamtraction committed Dec 1, 2023
1 parent 586a9f3 commit 8dd84b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/schedulers/liveStreams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import GuildModel from "../models/Guild.js";
import memcache from "../utils/memcache.js";
import * as requests from "../utils/requests.js";
import { COLORS } from "../utils/constants.js";
import { TWITCH_CHANNEL } from "../utils/regex.js";
import Settings from "../utils/settings.js";
import { TwitchStream } from "../types.js";

Expand Down Expand Up @@ -40,9 +41,10 @@ class LiveStreamNotificationScheduler extends Scheduler {

for (const guild of guildDocuments) {
// twitch streams
if (guild.twitchNotificationChannel && this.client.guilds.cache.get(guild.id).channels.cache.has(guild.twitchNotificationChannel) && guild.twitchNotificationUsers?.length) {
const twitchNotificationUsers = guild.twitchNotificationUsers.filter(u => TWITCH_CHANNEL.test(u));
if (guild.twitchNotificationChannel && this.client.guilds.cache.get(guild.id).channels.cache.has(guild.twitchNotificationChannel) && twitchNotificationUsers?.length) {
// get current live streams
const { body, statusCode } = await requests.get("https://api.twitch.tv/helix/streams/?user_login=" + guild.twitchNotificationUsers.join("&user_login="), {
const { body, statusCode } = await requests.get("https://api.twitch.tv/helix/streams/?user_login=" + twitchNotificationUsers.join("&user_login="), {
"authorization": "Bearer " + (this.client.settings as Settings).get("twitch").accessToken,
"client-id": (this.client.settings as Settings).get("twitch").clientId,
});
Expand Down

0 comments on commit 8dd84b9

Please sign in to comment.