|
| 1 | +import { TwurpleOptions } from "@tacxou/nestjs_module_twurple" |
| 2 | +import { exchangeCode , RefreshingAuthProvider } from "@twurple/auth" |
| 3 | +import fs from 'fs/promises' |
| 4 | + |
| 5 | +export interface ConfigInstance { |
| 6 | + twurple: { |
| 7 | + options: TwurpleOptions |
| 8 | + } |
| 9 | +} |
| 10 | + |
| 11 | +// noinspection JSUnresolvedReference |
| 12 | +export default async (): Promise<ConfigInstance> => { |
| 13 | + // const tokenData = await getAppToken( |
| 14 | + // process.env['STREAMKITS_TWURPLE_CLIENTID'] ?? '', |
| 15 | + // process.env['STREAMKITS_TWURPLE_CLIENTSECRET'] ?? '', |
| 16 | + // ) |
| 17 | + // console.log(tokenData) |
| 18 | + // const tokenData = { |
| 19 | + // accessToken: '[ACCESS_TOKEN]', |
| 20 | + // refreshToken: '[REFRESH_TOKEN]', |
| 21 | + // expiresIn: 1, |
| 22 | + // obtainmentTimestamp: 0, |
| 23 | + // } |
| 24 | + |
| 25 | + const params = new URLSearchParams({ |
| 26 | + client_id: process.env.STREAMKITS_TWURPLE_CLIENTID!, |
| 27 | + redirect_uri: 'https://a1b2c3d4.ngrok-free.app', |
| 28 | + response_type: 'code', |
| 29 | + scope: [ |
| 30 | + 'chat:read', |
| 31 | + 'chat:edit', |
| 32 | + 'channel:read:redemptions' |
| 33 | + ].join(' ') |
| 34 | + }); |
| 35 | + |
| 36 | + const url = `https://id.twitch.tv/oauth2/authorize?${params}`; |
| 37 | + |
| 38 | + console.log(url); |
| 39 | + |
| 40 | + // const tokenData = await exchangeCode( |
| 41 | + // process.env['STREAMKITS_TWURPLE_CLIENTID'] ?? '', |
| 42 | + // process.env['STREAMKITS_TWURPLE_CLIENTSECRET'] ?? '', |
| 43 | + // '[CODE]', |
| 44 | + // 'https://a1b2c3d4.ngrok-free.app', |
| 45 | + // ) |
| 46 | + // console.log(tokenData) |
| 47 | + |
| 48 | + const tokenData = JSON.parse(await fs.readFile('./tokens.125328655.json', 'utf-8')) |
| 49 | + const authProvider = new RefreshingAuthProvider({ |
| 50 | + clientId: process.env['STREAMKITS_TWURPLE_CLIENTID'] ?? '', |
| 51 | + clientSecret: process.env['STREAMKITS_TWURPLE_CLIENTSECRET'] ?? '', |
| 52 | + }) |
| 53 | + authProvider.onRefresh(async (userId, newTokenData) => await fs.writeFile(`./tokens.${userId}.json`, JSON.stringify(newTokenData, null, 4), 'utf-8')) |
| 54 | + await authProvider.addUserForToken(tokenData, ['chat']) |
| 55 | + |
| 56 | + return { |
| 57 | + twurple: { |
| 58 | + options: { |
| 59 | + authProvider, |
| 60 | + features: { |
| 61 | + api: {}, |
| 62 | + chat: { |
| 63 | + channels: ['tacxtv'], |
| 64 | + logger: { |
| 65 | + minLevel: 'debug', |
| 66 | + } |
| 67 | + }, |
| 68 | + pubsub: {}, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + } |
| 73 | +} |
0 commit comments