mjpin is a modular Node.js Discord bot designed to automate pinning Midjourney-generated images from Discord messages to your Pinterest boards. It supports multiple Pinterest accounts and includes features for workflow automation.
- /pin: Pin up to 10 images from Discord messages to a specified Pinterest board.
- /auth: Authenticate your Pinterest account with the bot using a secure OAuth2 flow.
- /sync: (Admin-only) Sync your Pinterest boards to make them available for pinning.
- /prompt: Generate a Midjourney prompt using OpenAI.
- /editprompt: (Admin-only) Edit the system prompt files used for prompt generation. Supports modular editing of individual prompt sections.
- Pin Rate Limiting: Prevents API spam by limiting pins to 100 per 24-hour period per Pinterest account.
- Multi-Account Support: Authenticate and use multiple Pinterest accounts.
src/index.js
: The main entry point for the bot.src/commands/
: Contains all the slash command handlers.src/services/
: Houses integration logic for third-party APIs like Pinterest and OpenAI.src/utils/
: Includes utility functions, such as the pin rate limiter.data/
: Contains modular prompt files used for generating Midjourney prompts. Any.txt
file in this directory will be automatically included in the system prompt.
The bot uses a modular prompt system where all .txt
files in the data/
directory are automatically combined to create the system prompt for OpenAI. This allows for easy customization and organization of different prompt components:
- Modular Editing: Use
/editprompt
to edit individual prompt files through Discord - Auto-Discovery: Any
.txt
file added to thedata/
directory will automatically be included - Character Limits: Each prompt file must be under 4000 characters for Discord modal editing
- Dynamic Loading: Prompt changes are automatically reloaded when files are edited
- Clone the repository:
git clone <repository-url> cd mjpin
- Install dependencies:
npm install
- Configure environment variables:
Copy the
.env.example
file to.env
and fill in the required API keys and tokens.cp .env.example .env
- Run the bot:
For development, you can run the bot directly:
For production, it's recommended to use a process manager like
node src/index.js
pm2
to keep the bot online:pm2 start src/index.js --name mjpin
All secrets and API keys are managed via the .env
file.
MJPIN_DISCORD_TOKEN
: Your Discord bot token.MJPIN_DISCORD_CLIENT_ID
: Your Discord application's client ID.MJPIN_PINTEREST_CLIENT_ID
: Your Pinterest application's client ID.MJPIN_PINTEREST_CLIENT_SECRET
: Your Pinterest application's client secret.MJPIN_PINTEREST_REDIRECT_URI
: The OAuth redirect URI for your Pinterest app (e.g.,http://your-server-ip:3000/pinterest/callback
).MJPIN_OPENAI_API_KEY
: Your OpenAI API key.MJPIN_GUILD_ID
: The Discord server (guild) ID where you will register the slash commands.MJPIN_ADMIN_USER_ID
: The Discord user ID of the bot administrator.MJPIN_LOG_CHANNEL_ID
: (Optional) A Discord channel ID for logging errors and important events.
Contributions are welcome. Please adhere to the existing code structure and principles of modularity and security.
Chris Huber — https://chubes.net