From fc8cc824786c9f2310dc9ef820da5d83a092c4de Mon Sep 17 00:00:00 2001 From: qwerinope Date: Sun, 13 Apr 2025 20:56:37 +0200 Subject: [PATCH] fix intent system --- src/lib/auth.ts | 10 ++++++---- src/lib/timeoutHelper.ts | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 4dd2155..9b86998 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -2,6 +2,8 @@ import { RefreshingAuthProvider, exchangeCode } from '@twurple/auth' import pb from './pocketbase' import { RecordModel } from 'pocketbase' +const INTENTS = ['channel:manage:moderators', 'moderation:read', 'moderator:manage:banned_users', 'channel:manage:polls', 'channel:read:polls'] + let ttvauth: RecordModel | undefined try { ttvauth = await pb.collection('ttvauth').getFirstListItem('main=true') @@ -35,10 +37,10 @@ async function firstAccess(main = true) { if ((main && !OAUTH_CODE) || (!main && !BROADCASTER_OAUTH_CODE)) { if (main) { console.error("No 'OAUTH_CODE' provided. To get the code, please visit this URL, authorize the bot and copy the 'code' from the return URL.") - console.error(`https://id.twitch.tv/oauth2/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=chat:read+chat:edit+moderator:manage:banned_users+moderation:read+channel:manage:polls+channel:read:polls`) + console.error(`https://id.twitch.tv/oauth2/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=chat:read+chat:edit+${INTENTS.join('+')}`) } else { console.error("No 'BROADCASTER_OAUTH_CODE' provided. To get the code, please make the broadcaster visit the following URL, and get them to return the 'code' from the return URL.") - console.error(`https://id.twitch.tv/oauth2/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=moderator:manage:banned_users+moderation:read+channel:manage:moderators+channel:manage:polls+channel:read:polls`) + console.error(`https://id.twitch.tv/oauth2/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=${INTENTS.join('+')}`) } process.exit(1) } @@ -69,7 +71,7 @@ await authProvider.addUserForToken({ refreshToken: auth.REFRESH_TOKEN, expiresIn: auth.EXPIRESIN, obtainmentTimestamp: auth.OBTAINMENTTIMESTAMP -}, ['chat', 'moderator:manage:banned_users', 'channel:manage:polls', 'channel:read:polls', 'channel:manage:moderators']) +}, ['chat', ...INTENTS]) authProvider.onRefresh(async (_id, newTokenData) => { auth.ACCESS_TOKEN = newTokenData.accessToken @@ -95,7 +97,7 @@ const broadcasterAuthProvider = broadcasterAuthData === undefined ? undefined : refreshToken: broadcasterAuthData.REFRESH_TOKEN, expiresIn: broadcasterAuthData.EXPIRESIN, obtainmentTimestamp: broadcasterAuthData.OBTAINMENTTIMESTAMP - }, ['moderator:manage:banned_users', 'moderation:read', 'channel:manage:moderators', 'channel:manage:polls', 'channel:read:polls']) + }, INTENTS) broadcasterAuthProvider.onRefresh(async (_id, newTokenData) => { broadcasterAuthData.ACCESS_TOKEN = newTokenData.accessToken diff --git a/src/lib/timeoutHelper.ts b/src/lib/timeoutHelper.ts index 713cf52..a9b53bd 100644 --- a/src/lib/timeoutHelper.ts +++ b/src/lib/timeoutHelper.ts @@ -83,7 +83,7 @@ function remodMod(broadcasterid: string, target: HelixUser, duration: number, ap } else { // If user is still timed out it doesn't try to remod the target try { await api.moderation.addModerator(broadcasterid, target) - } catch (err) { console.log(err) } // This triggers when the timeout got shortened. try/catch so no runtime error + } catch (err) {} // This triggers when the timeout got shortened. try/catch so no runtime error } }, duration + 3000) // callback gets called after duration of timeout + 3 seconds }