Skip to content

Commit

Permalink
Adds ChatGPT command
Browse files Browse the repository at this point in the history
Adds /chatgpt command

* Queries OpenAI using official npm package
* Adds util for rate limiting commands
* Extract util for parsing boolean from parseInput util
  • Loading branch information
mikeyaworski committed Jun 22, 2023
1 parent ad35c75 commit 938c64a
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ YOUTUBE_API_KEY=...
SPOTIFY_CLIENT_ID=...
SPOTIFY_CLIENT_SECRET=...

# ChatGPT
OPENAI_SECRET_KEY=...
# 2 requests every 60 seconds
CHATGPT_USER_LIMIT=2,60
CHATGPT_GUILD_LIMIT=10,60
# in seconds
CHATGPT_CONVERSATION_TIME_LIMIT=600

# Slash Commands in development. Remove this during deployment.
SLASH_COMMANDS_GUILD_ID=...

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Optional variables:
- `WEBHOOK_SECRET`, which will only be used for the `/webhooks` API route. By default, this route is unused and is generally only useful if you would like a third party (e.g. IFTTT) to send messages via webhooks.
- `YOUTUBE_API_KEY`, which is used to fetch playlist videos for the player commands.
- `SPOTIFY_CLIENT_ID` and `SPOTIFY_CLIENT_SECRET`, which are used to fetch playlist tracks for the player commands.
- `OPENAI_SECRET_KEY`, `CHATGPT_USER_LIMIT`, `CHATGPT_GUILD_LIMIT` and `CHATGPT_CONVERSATION_TIME_LIMIT` are used to fetch queries from ChatGPT.

```
# Use "production" when deploying
Expand All @@ -43,6 +44,14 @@ YOUTUBE_API_KEY=...
SPOTIFY_CLIENT_ID=...
SPOTIFY_CLIENT_SECRET=...
# ChatGPT
OPENAI_SECRET_KEY=...
# 2 requests every 60 seconds
CHATGPT_USER_LIMIT=2,60
CHATGPT_GUILD_LIMIT=10,60
# in seconds
CHATGPT_CONVERSATION_TIME_LIMIT=10
# Create your own webhook secret if you intend to use the webhook API routes and want them protected
WEBHOOK_SECRET=...
Expand Down
2 changes: 2 additions & 0 deletions docs/General-Instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@

1. [Optional] Go to https://developer.spotify.com/dashboard/applications, create a project and note your client ID & client secret. This is used to fetch Spotify playlist information with the Player commands.

1. [Optional] Go to https://platform.openai.com/account/api-keys and create a secret key. This is used for the `OPENAI_SECRET_KEY` environment variable, and is necessary to use the `/chatgpt` command.

At this point, you should have all of the environment variables needed to deploy the bot, except for the database URL.
125 changes: 119 additions & 6 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@
"lodash.uniq": "^4.5.0",
"node-cache": "^5.1.2",
"node-notifier": "^9.0.0",
"openai": "^3.3.0",
"p-limit": "^3.1.0",
"pg": "^8.5.1",
"play-dl": "^1.9.6",
"rate-limiter-flexible": "^2.4.1",
"sequelize": "^6.28.0",
"socket.io": "^4.5.1",
"spotify-url-info": "^2.2.3",
Expand Down
2 changes: 2 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ReactionRoles from './utilities/reaction-roles';
import Reminders from './utilities/reminders';
import Timers from './utilities/timers';
import Say from './utilities/say';
import ChatGPT from './utilities/chatgpt';

import Chess from './chess';

Expand Down Expand Up @@ -46,6 +47,7 @@ const commands = [
Reminders,
Timers,
Say,
ChatGPT,

// Player
Play,
Expand Down
Loading

0 comments on commit 938c64a

Please sign in to comment.