Skip to content

Commit

Permalink
Added Support for Pro Accounts. Added Decorations.
Browse files Browse the repository at this point in the history
  • Loading branch information
itskdhere committed Jan 23, 2023
1 parent f1e4b6a commit 07f4fca
Show file tree
Hide file tree
Showing 5 changed files with 458 additions and 104 deletions.
Binary file added ChatGPT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 19 additions & 9 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# Never Push The ".env" File To GitHub (Your Discord BOT and/or OpenAI Might Get Compromised)
# Never Push The ".env" File To GitHub (Your Discord BOT and/or OpenAI Account Might Get Compromised)

# ---------------------------------------:Environment Variables:------------------------------------
# --------------------------------------------------------------------------------------------------
# Discord BOT Credentials from "Discord Developer Portal"
DISCORD_CLIENT_ID=42069420694206942069
DISCORD_BOT_TOKEN=$uper$ecrectT0ken
DISCORD_CLIENT_ID=...
DISCORD_BOT_TOKEN=...

# Account Login Credentials
# For 'Google' login type provide the gmail and the google account password of the gmailID

# --------------------------------------------------------------------------------------------------
# For 'Google' login type provide the Gmail-ID and the google account password of the Gmail-ID
# For 'OpenAI' login type provide the email and password associated with your OpenAI account
EMAIL=username@provider.tld
PASSWORD=$uper$ecrectP@ssw0rd
EMAIL=...
PASSWORD=...


# --------------------------------------------------------------------------------------------------
# Login Type ( Value: 'google' or 'openai' )
LOGIN_TYPE=...


# Login Type,( Value: 'google' or 'openai' )
LOGIN_TYPE=openai
# --------------------------------------------------------------------------------------------------
# ChatGPT Account Type ( Value: 'free' or 'pro' )
ACCOUNT_TYPE=...
52 changes: 42 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import dotenv from 'dotenv'; dotenv.config();
import { ChatGPTAPIBrowser } from 'chatgpt';
import { Client, GatewayIntentBits, REST, Routes, Partials, ActivityType} from 'discord.js';
import axios from 'axios';
import chalk from 'chalk';
import figlet from 'figlet';
import gradient from 'gradient-string';

// Defines
const MAX_RESPONSE_LENGTH = 2000 // Discord Max 2000 Characters
Expand Down Expand Up @@ -31,15 +34,17 @@ const commands = [
// Initialize OpenAI Session & New ChatGPT Thread
async function initOpenAI() {
const loginType = process.env.LOGIN_TYPE;
if (loginType === 'openai') {
const accountType = process.env.ACCOUNT_TYPE;

if (loginType === 'openai' && accountType === 'free') {
const api = new ChatGPTAPIBrowser({
email: process.env.EMAIL,
password: process.env.PASSWORD
});
await api.initSession();
return api;
}
else if (loginType === 'google') {
else if (loginType === 'google' && accountType === 'free') {
const api = new ChatGPTAPIBrowser({
email: process.env.EMAIL,
password: process.env.PASSWORD,
Expand All @@ -48,8 +53,27 @@ async function initOpenAI() {
await api.initSession();
return api;
}
else if (loginType === 'openai' && accountType === 'pro') {
const api = new ChatGPTAPIBrowser({
email: process.env.EMAIL,
password: process.env.PASSWORD,
isProAccount: true
});
await api.initSession();
return api;
}
else if (loginType === 'google' && accountType === 'pro') {
const api = new ChatGPTAPIBrowser({
email: process.env.EMAIL,
password: process.env.PASSWORD,
isGoogleLogin: true,
isProAccount: true
});
await api.initSession();
return api;
}
else {
console.log('Not a valid loginType; use "google" or "openai" in .env file');
console.log(chalk.red('ChatGPT Error: Not a valid loginType or accountType'));
}
}

Expand All @@ -68,6 +92,14 @@ async function initDiscordCommands(api) {

// Main Function (Execution Starts Here)
async function main() {
console.log(gradient.pastel.multiline(figlet.textSync('ChatGPT', {
font: 'univers',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 100,
whitespaceBreak: true
})));

const chatGTP = await initOpenAI().catch(error => {
console.error(error)
process.exit()
Expand All @@ -88,8 +120,8 @@ async function main() {
});

client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
console.log('Connected to Discord Gateway');
console.log(`Logged in as ${client.user.tag}`);
console.log(chalk.greenBright('Connected to Discord Gateway'));
console.log(new Date())
client.user.setStatus('online');
client.user.setActivity('/ask');
Expand Down Expand Up @@ -143,14 +175,14 @@ async function main() {
// TODO: send to DB
})
} catch (e) {
console.error(e);
console.error(chalk.red(e));
}
}

function askQuestion(question, cb) {
let tmr = setTimeout((e) => {
cb("Oppss, something went wrong! (Timeout)")
console.error(e)
console.error(chalk.red(e))
}, 100000)

chatGTP.sendMessage(question, {
Expand All @@ -162,7 +194,7 @@ async function main() {
cb(response)
}).catch((err) => {
cb("Oppss, something went wrong! (Error)")
console.error("AskQuestion Error" + err)
console.error(chalk.red("AskQuestion Error:" + err))
})
}

Expand All @@ -174,7 +206,7 @@ async function main() {
}
}

client.login(process.env.DISCORD_BOT_TOKEN).catch(console.log);
client.login(process.env.DISCORD_BOT_TOKEN).catch(e => console.log(chalk.red(e)));
}

main() // Call Main function
Expand All @@ -192,4 +224,4 @@ setInterval(() => {
}
});

}, 60000); // Every 1 Minute
}, 30000); // Check Every 30 Second
Loading

0 comments on commit 07f4fca

Please sign in to comment.