Skip to content

chubes4/mjpin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mjpin Discord Bot

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.

Features

  • /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.

Project Structure

  • 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.

Prompt System

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 the data/ 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

Setup

  1. Clone the repository:
    git clone <repository-url>
    cd mjpin
  2. Install dependencies:
    npm install
  3. Configure environment variables: Copy the .env.example file to .env and fill in the required API keys and tokens.
    cp .env.example .env
  4. Run the bot: For development, you can run the bot directly:
    node src/index.js
    For production, it's recommended to use a process manager like pm2 to keep the bot online:
    pm2 start src/index.js --name mjpin

Environment Variables

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.

Contributing

Contributions are welcome. Please adhere to the existing code structure and principles of modularity and security.


Chris Huber — https://chubes.net

About

Discord bot for generating Midjourney prompts and posting to Pinterest.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published