Merge branch 'main' into storage-fixes

This commit is contained in:
bertybuttface 2022-12-29 02:48:50 +00:00 committed by GitHub
commit d92ba25c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 14 deletions

View File

@ -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",

View File

@ -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");

View File

@ -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({