Skip to content

Commit

Permalink
fix: get ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Sep 4, 2023
1 parent 2dfa33b commit 8d6e574
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
23 changes: 13 additions & 10 deletions packages/twitch/chat/src/twitch/lib/getChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ export async function getChannels(): Promise<string[]> {
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
}
40 changes: 29 additions & 11 deletions packages/twitch/events/src/twitch/lib/getAccountIds.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
import supabase from '../../db/supabase.js'

const dev_channelids = process.env.DEV_CHANNELIDS?.split(',') ?? []
export async function getAccountIds(): Promise<string[]> {
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
}

0 comments on commit 8d6e574

Please sign in to comment.