mirror of
https://github.com/matrixgpt/matrix-chatgpt-bot.git
synced 2024-09-20 16:15:41 +00:00
Use matrix access token if we have it, print one if we don't.
This commit is contained in:
parent
9bd97b2453
commit
c5793ec12b
@ -18,21 +18,21 @@ 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 = Boolean(process.env.IS_GOOGLE_LOGIN) as boolean;
|
||||||
|
|
||||||
if(accessToken === undefined) {
|
|
||||||
console.error("MATRIX_ACCESS_TOKEN env variable is undefined");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
if(homeserverUrl === undefined) {
|
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);
|
|
||||||
}
|
|
||||||
if(matrixBotPassword === undefined) {
|
|
||||||
console.error("MATRIX_BOT_PASSWORD env variable is undefined");
|
|
||||||
process.exit(1);
|
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(openAiEmail === undefined) {
|
if(openAiEmail === undefined) {
|
||||||
console.error("OPENAI_EMAIL env variable is undefined");
|
console.error("OPENAI_EMAIL env variable is undefined");
|
||||||
|
11
src/index.ts
11
src/index.ts
@ -4,7 +4,7 @@ import {
|
|||||||
RichConsoleLogger,
|
RichConsoleLogger,
|
||||||
// RustSdkCryptoStorageProvider,
|
// RustSdkCryptoStorageProvider,
|
||||||
} from "matrix-bot-sdk";
|
} from "matrix-bot-sdk";
|
||||||
import { openAiEmail, openAiPassword, isGoogleLogin, homeserverUrl, matrixBotPassword, matrixBotUsername } from './config.js'
|
import { openAiEmail, openAiPassword, isGoogleLogin, homeserverUrl, accessToken, matrixBotPassword, matrixBotUsername } from './config.js'
|
||||||
import { parseMatrixUsernamePretty } from './utils.js';
|
import { parseMatrixUsernamePretty } from './utils.js';
|
||||||
import { handleRoomEvent } from './handlers.js';
|
import { handleRoomEvent } from './handlers.js';
|
||||||
import { ChatGPTAPIBrowser } from 'chatgpt'
|
import { ChatGPTAPIBrowser } from 'chatgpt'
|
||||||
@ -26,8 +26,13 @@ const storage = new SimpleFsStorageProvider("./storage/bot.json");
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const botUsernameWithoutDomain = parseMatrixUsernamePretty(matrixBotUsername);
|
const botUsernameWithoutDomain = parseMatrixUsernamePretty(matrixBotUsername);
|
||||||
const authedClient = await (new MatrixAuth(homeserverUrl)).passwordLogin(botUsernameWithoutDomain, matrixBotPassword);
|
if (!accessToken){
|
||||||
const client = new MatrixClient(authedClient.homeserverUrl, authedClient.accessToken, storage);
|
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)
|
// 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