-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitch.js
54 lines (44 loc) · 1.28 KB
/
twitch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'dotenv/config'
import { ApiClient } from '@twurple/api'
import { ClientCredentialsAuthProvider } from '@twurple/auth'
import { EventSubListener, ReverseProxyAdapter } from '@twurple/eventsub'
import { GuildConfigs } from './db.js'
const authProvider = new ClientCredentialsAuthProvider(
process.env.TWITCH_ID,
process.env.TWITCH_SECRET
)
const api = new ApiClient({ authProvider })
export async function getTwUserId (twName) {
const twUser = await api.users.getUserByName(twName)
return twUser.id
}
const listener = new EventSubListener({
apiClient: api,
adapter: new ReverseProxyAdapter({
hostName: 'ventbot.computer.navy',
port: process.env.ADAPTER_PORT
}),
secret: process.env.VENTSUB_SECRET
})
await listener.listen()
export async function getTwStreamSubs (twUserId, funcs) {
try {
console.log(`getting twitch subscriptions for ${twUserId}`)
// const twUserId = (await GuildConfigs.findOne({
// where: { ownerId: dscUserId }
// })).id
return {
startSub: await listener.subscribeToStreamOnlineEvents(
twUserId,
funcs.startFunc
),
endSub: await listener.subscribeToStreamOfflineEvents(
twUserId,
funcs.endFunc
)
}
} catch (e) {
console.error(e)
}
}
export default listener