mirror of
https://github.com/matrixgpt/matrix-chatgpt-bot.git
synced 2024-09-28 20:15:56 +00:00
Merge branch 'main' into storage-fixes
This commit is contained in:
commit
d92ba25c18
@ -15,7 +15,7 @@
|
|||||||
"typecheck": "npx tsc"
|
"typecheck": "npx tsc"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chatgpt": "^3.3.1",
|
"chatgpt": "^3.3.6",
|
||||||
"dotenv": "^14.2.0",
|
"dotenv": "^14.2.0",
|
||||||
"matrix-bot-sdk": "^0.6.2",
|
"matrix-bot-sdk": "^0.6.2",
|
||||||
"puppeteer": "^19.4.1",
|
"puppeteer": "^19.4.1",
|
||||||
|
@ -20,12 +20,9 @@ export const dataPath = process.env.DATA_PATH as string;
|
|||||||
/** ChatGPT specific stuff */
|
/** ChatGPT specific stuff */
|
||||||
export const openAiEmail = process.env.OPENAI_EMAIL as string;
|
export const openAiEmail = process.env.OPENAI_EMAIL as string;
|
||||||
export const openAiPassword = process.env.OPENAI_PASSWORD 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) {
|
if(dataPath === undefined) {
|
||||||
console.error("DATA_PATH env variable is undefined");
|
console.error("DATA_PATH env variable is undefined");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@ -34,13 +31,17 @@ if(homeserverUrl === undefined) {
|
|||||||
console.error("MATRIX_HOMESERVER_URL env variable is undefined");
|
console.error("MATRIX_HOMESERVER_URL env variable is undefined");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
if(matrixBotUsername === undefined) {
|
if(accessToken === undefined) {
|
||||||
console.error("MATRIX_BOT_USERNAME env variable is undefined");
|
console.error("MATRIX_ACCESS_TOKEN env variable is undefined, set it to empty string to use username and password");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
if(matrixBotUsername === undefined) {
|
||||||
if(matrixBotPassword === undefined) {
|
console.error("MATRIX_BOT_USERNAME env variable is undefined, set it to empty string to use access token");
|
||||||
console.error("MATRIX_BOT_PASSWORD env variable is undefined");
|
|
||||||
process.exit(1);
|
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) {
|
if(matrixAutojoin === undefined) {
|
||||||
console.error("MATRIX_AUTO_JOIN env variable is undefined");
|
console.error("MATRIX_AUTO_JOIN env variable is undefined");
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
ICryptoStorageProvider,
|
ICryptoStorageProvider,
|
||||||
RustSdkCryptoStorageProvider,
|
RustSdkCryptoStorageProvider,
|
||||||
} from "matrix-bot-sdk";
|
} from "matrix-bot-sdk";
|
||||||
|
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { dataPath, openAiEmail, openAiPassword, isGoogleLogin, homeserverUrl, accessToken, matrixAutojoin, matrixBotPassword, matrixBotUsername, matrixEncryption } from './config.js'
|
import { dataPath, openAiEmail, openAiPassword, isGoogleLogin, homeserverUrl, accessToken, matrixAutojoin, matrixBotPassword, matrixBotUsername, matrixEncryption } from './config.js'
|
||||||
import { parseMatrixUsernamePretty } from './utils.js';
|
import { parseMatrixUsernamePretty } from './utils.js';
|
||||||
@ -31,8 +32,13 @@ if (matrixEncryption) {
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const botUsernameWithoutDomain = parseMatrixUsernamePretty(matrixBotUsername);
|
const botUsernameWithoutDomain = parseMatrixUsernamePretty(matrixBotUsername);
|
||||||
|
if (!accessToken){
|
||||||
const authedClient = await (new MatrixAuth(homeserverUrl)).passwordLogin(botUsernameWithoutDomain, matrixBotPassword);
|
const authedClient = await (new MatrixAuth(homeserverUrl)).passwordLogin(botUsernameWithoutDomain, matrixBotPassword);
|
||||||
const client = new MatrixClient(authedClient.homeserverUrl, authedClient.accessToken, storage);
|
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)
|
// use puppeteer to bypass cloudflare (headful because of captchas)
|
||||||
const chatGPT = new ChatGPTAPIBrowser({
|
const chatGPT = new ChatGPTAPIBrowser({
|
||||||
|
Loading…
Reference in New Issue
Block a user