diff --git a/package.json b/package.json index 2216b1a..4669e63 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "typecheck": "npx tsc" }, "dependencies": { - "chatgpt": "^3.3.1", + "chatgpt": "^3.3.6", "dotenv": "^14.2.0", "matrix-bot-sdk": "^0.6.2", "puppeteer": "^19.4.1", diff --git a/src/config.ts b/src/config.ts index 43c1b7a..509cc5a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,12 +20,9 @@ export const dataPath = process.env.DATA_PATH as string; /** ChatGPT specific stuff */ export const openAiEmail = process.env.OPENAI_EMAIL as string; export const openAiPassword = process.env.OPENAI_PASSWORD as string; -export const isGoogleLogin = Boolean(process.env.IS_GOOGLE_LOGIN) as boolean; +export const isGoogleLogin = process.env.IS_GOOGLE_LOGIN && process.env.IS_GOOGLE_LOGIN.toLowerCase() === "true"; + -if(accessToken === undefined) { - console.error("MATRIX_ACCESS_TOKEN env variable is undefined"); - process.exit(1); -} if(dataPath === undefined) { console.error("DATA_PATH env variable is undefined"); process.exit(1); @@ -34,13 +31,17 @@ if(homeserverUrl === undefined) { console.error("MATRIX_HOMESERVER_URL env variable is undefined"); process.exit(1); } -if(matrixBotUsername === undefined) { - console.error("MATRIX_BOT_USERNAME env variable is undefined"); - process.exit(1); -} -if(matrixBotPassword === undefined) { - console.error("MATRIX_BOT_PASSWORD env variable is undefined"); +if(accessToken === undefined) { + console.error("MATRIX_ACCESS_TOKEN env variable is undefined, set it to empty string to use username and password"); process.exit(1); + if(matrixBotUsername === undefined) { + console.error("MATRIX_BOT_USERNAME env variable is undefined, set it to empty string to use access token"); + process.exit(1); + } + if(matrixBotPassword === undefined) { + console.error("MATRIX_BOT_PASSWORD env variable is undefined, set it to empty string to use access token"); + process.exit(1); + } } if(matrixAutojoin === undefined) { console.error("MATRIX_AUTO_JOIN env variable is undefined"); diff --git a/src/index.ts b/src/index.ts index 3802964..feabb23 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { ICryptoStorageProvider, RustSdkCryptoStorageProvider, } from "matrix-bot-sdk"; + import * as path from "path"; import { dataPath, openAiEmail, openAiPassword, isGoogleLogin, homeserverUrl, accessToken, matrixAutojoin, matrixBotPassword, matrixBotUsername, matrixEncryption } from './config.js' import { parseMatrixUsernamePretty } from './utils.js'; @@ -31,8 +32,13 @@ if (matrixEncryption) { async function main() { const botUsernameWithoutDomain = parseMatrixUsernamePretty(matrixBotUsername); - const authedClient = await (new MatrixAuth(homeserverUrl)).passwordLogin(botUsernameWithoutDomain, matrixBotPassword); - const client = new MatrixClient(authedClient.homeserverUrl, authedClient.accessToken, storage); + if (!accessToken){ + const authedClient = await (new MatrixAuth(homeserverUrl)).passwordLogin(botUsernameWithoutDomain, matrixBotPassword); + console.log(authedClient.homeserverUrl + " token: \n" + authedClient.accessToken) + console.log("Set MATRIX_ACCESS_TOKEN to above token, MATRIX_ACCESS_USERNAME and MATRIX_ACCESS_PASSWORD can now be blank") + return; + } + const client = new MatrixClient(homeserverUrl, accessToken, storage); // use puppeteer to bypass cloudflare (headful because of captchas) const chatGPT = new ChatGPTAPIBrowser({