diff --git a/packages/twitch/chat/src/twitch/lib/getChannels.ts b/packages/twitch/chat/src/twitch/lib/getChannels.ts index 90fefedc..dd296244 100644 --- a/packages/twitch/chat/src/twitch/lib/getChannels.ts +++ b/packages/twitch/chat/src/twitch/lib/getChannels.ts @@ -4,23 +4,26 @@ export async function getChannels(): Promise { console.log('[TWITCHSETUP] Running getChannels in chat listener') const isDevMode = process.env.NODE_ENV === 'development' + let users: string[] = [] if (isDevMode) { - const { data: users } = await supabase + const { data } = await supabase .from('users') .select('name') .in('name', process.env.DEV_CHANNELS?.split(',') ?? []) .order('followers', { ascending: false, nullsFirst: false }) - console.log('joining ', users?.length ?? 0, ' channels') - return users ? users.map((user) => `${user.name}`) : [] - } + users = data?.map((user) => user.name as string) ?? users + } else { + const { data } = await supabase + .from('users') + .select('name') + .not('name', 'in', `(${process.env.DEV_CHANNELS})`) + .order('followers', { ascending: false, nullsFirst: false }) - const { data: users } = await supabase - .from('users') - .select('name') - .order('followers', { ascending: false, nullsFirst: false }) + users = data?.map((user) => user.name as string) ?? users + } - console.log('joining ', users?.length ?? 0, ' channels') + console.log('joining', users.length, 'channels') - return users ? users.map((user) => `${user.name}`) : [] + return users } diff --git a/packages/twitch/events/src/twitch/lib/getAccountIds.ts b/packages/twitch/events/src/twitch/lib/getAccountIds.ts index 8c50fe01..22451a3b 100644 --- a/packages/twitch/events/src/twitch/lib/getAccountIds.ts +++ b/packages/twitch/events/src/twitch/lib/getAccountIds.ts @@ -1,20 +1,38 @@ import supabase from '../../db/supabase.js' -const dev_channelids = process.env.DEV_CHANNELIDS?.split(',') ?? [] export async function getAccountIds(): Promise { console.log('[TWITCHSETUP] Running getAccountIds') - if (process.env.NODE_ENV === 'development') { - if (!dev_channelids.length) throw new Error('Missing DEV_CHANNELIDS') - return dev_channelids - } + const devIds = process.env.DEV_CHANNELIDS?.split(',') ?? [] + const isDevMode = process.env.NODE_ENV === 'development' + let providerIds: string[] = [] + + if (isDevMode) { + if (!devIds.length) throw new Error('Missing DEV_CHANNELIDS') + + const { data } = await supabase + .from('users') + .select('id,accounts(providerAccountId)') + .in('name', process.env.DEV_CHANNELS?.split(',') ?? []) + .neq('accounts.requires_refresh', true) + .order('followers', { ascending: false, nullsFirst: false }) - const { data: users } = await supabase - .from('users') - .select('id') - .order('followers', { ascending: false, nullsFirst: false }) + providerIds = + data?.map((user) => user?.accounts?.[0]?.providerAccountId as string) ?? providerIds + } else { + const { data } = await supabase + .from('users') + .select('id,accounts(providerAccountId)') + .not('name', 'in', `(${process.env.DEV_CHANNELS})`) + .neq('accounts.requires_refresh', true) + .order('followers', { ascending: false, nullsFirst: false }) + + providerIds = + data?.map((user) => user?.accounts?.[0]?.providerAccountId as string) ?? providerIds + } - const accountIds: string[] = users?.map((user) => user.id as string) ?? [] + providerIds = providerIds.filter(Boolean) + console.log('joining', providerIds.length, 'channels') - return accountIds + return providerIds }