From e2e980bc47ad2506f0c88d9dc3dc16b1996e6b84 Mon Sep 17 00:00:00 2001 From: Angels-dev Date: Thu, 15 Aug 2024 22:27:11 +0200 Subject: [PATCH] Fix token twitch non refresh pour notifications --- package.json | 2 +- src/events/client/ready.ts | 2 +- src/utils/twitch.ts | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0b1ce5e..e979c7e 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bot_tamiseur", "description": "Listen to music and use fun commands with your friends!", - "version": "3.0.1", + "version": "3.0.2", "author": { "name": "Zachary Guénot" }, diff --git a/src/events/client/ready.ts b/src/events/client/ready.ts index cbe081f..7df9d9f 100755 --- a/src/events/client/ready.ts +++ b/src/events/client/ready.ts @@ -92,7 +92,7 @@ export default { } // Handle notification messages - else if (data.metadata.message_type === 'notification') Twitch.notification(client_id, channel_access_token, data, guild) + else if (data.metadata.message_type === 'notification') Twitch.notification(client_id, client_secret, channel_access_token, data, guild) } catch (error) { console.error(chalk.magenta(`[Twitch] {${guild.name}} ` + error)) } } }) .on('error', error => console.error(chalk.magenta(`[Twitch] {${guild.name}} ` + error))) diff --git a/src/utils/twitch.ts b/src/utils/twitch.ts index 3364617..eb01cc7 100644 --- a/src/utils/twitch.ts +++ b/src/utils/twitch.ts @@ -93,7 +93,7 @@ export async function getUserInfo (client_id: string, access_token: string, type }).catch(error => { console.error(error.response.data) }) } -export async function notification (client_id: string, channel_access_token: string, data: NotificationData, guild: Guild) { +export async function notification (client_id: string, client_secret: string, channel_access_token: string, data: NotificationData, guild: Guild) { if (!guild) return console.log(chalk.magenta('[Twitch] Can\'t find guild !')) let { subscription, event } = data.payload @@ -111,6 +111,10 @@ export async function notification (client_id: string, channel_access_token: str let liveMessageInterval + // Check if the channel access token is still valid before connecting + channel_access_token = await checkChannel(client_id, client_secret, channel_access_token, guild) as string + if (!channel_access_token) return console.log(chalk.magenta(`[Twitch] {${guild.name}} Can't refresh channel access token !`)) + if (subscription.type === 'stream.online') { console.log(chalk.magenta(`[Twitch] {${guild.name}} Stream from ${event.broadcaster_user_name} is now online, sending Discord message...`))