Skip to content

Commit

Permalink
added support for google login
Browse files Browse the repository at this point in the history
  • Loading branch information
itskdhere committed Jan 12, 2023
1 parent 69fca46 commit 8914acc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
9 changes: 6 additions & 3 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
DISCORD_CLIENT_ID=
DISCORD_BOT_TOKEN=

# OpenAI Account Credentials
OPENAI_EMAIL=
OPENAI_PASSWORD=
# Account Login Credentials
EMAIL=
PASSWORD=

# Login Type, google / openai
LOGIN_TYPE=openai
37 changes: 24 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,27 @@ const commands = [

// Initialize OpenAI Session & New ChatGPT Thread
async function initOpenAI() {
const api = new ChatGPTAPIBrowser({
email: process.env.OPENAI_EMAIL,
password: process.env.OPENAI_PASSWORD
//isGoogleLogin: true
})

await api.initSession();

return api;
const loginType = process.env.LOGIN_TYPE;
if (loginType === 'openai') {
const api = new ChatGPTAPIBrowser({
email: process.env.EMAIL,
password: process.env.PASSWORD
});
await api.initSession();
return api;
}
else if (loginType === 'google') {
const api = new ChatGPTAPIBrowser({
email: process.env.EMAIL,
password: process.env.PASSWORD,
isGoogleLogin: true
});
await api.initSession();
return api;
}
else {
console.log('Not a valid loginType; use "google" or "openai" ');
}
}

// Initialize Discord Application Commands
Expand Down Expand Up @@ -104,6 +116,7 @@ async function main() {
async function ping_Interaction_Handler(interaction) {
const sent = await interaction.reply({ content: 'Pinging...', fetchReply: true });
interaction.editReply(`Websocket Heartbeat: ${interaction.client.ws.ping} ms. \nRoundtrip Latency: ${sent.createdTimestamp - interaction.createdTimestamp} ms`);
client.user.setActivity('/ask');
}

async function ask_Interaction_Handler(interaction) {
Expand All @@ -126,13 +139,12 @@ async function main() {
} else {
await interaction.editReply(content.response);
}
client.user.setActivity('/ask');
// TODO: send to DB
})
} catch (e) {
console.error(e);
}

client.user.setActivity('/ask');
}

function askQuestion(question, cb) {
Expand Down Expand Up @@ -172,8 +184,7 @@ setInterval(() => {
axios
.get('https://discord.com/api/v10')
.catch(error => {
if (error.response.status == 429)
{
if (error.response.status == 429) {
console.log("Discord Rate Limited");
console.warn("Status: " + error.response.status)
console.warn(error)
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@types/node": "^18.0.6",
"axios": "^1.2.1",
"chatgpt": "^3.3.1",
"chatgpt": "^3.3.13",
"discord.js": "^14.7.1",
"dotenv": "^16.0.3",
"node-fetch": "^3.2.6",
Expand Down

0 comments on commit 8914acc

Please sign in to comment.