FloatyPotato/snap-nexus-bot
Snap Nexus Bot
A specialized Discord bot for the Marvel Snap community that converts deck screenshots into copy-pasteable short codes in under 1.5 seconds.
Instead of using heavy, slow text-extraction Vision AI, this bot utilizes a high-speed Visual Search architecture. It dynamically crops card artwork from screenshot grids, generates CLIP embeddings, and queries a Pinecone vector database to find exact variant matches.
How It Works
- Layout Crop & Slice: The bot automatically analyzes the aspect ratio of the screenshot bounding box (detecting
2x6,3x4,4x3, or6x2grids) and crops out the card artwork slots in-memory usingsharp. - Embedding Generation: It sends the cropped image buffers to a custom Hugging Face Space running a FastAPI CLIP-ViT server to generate 512-dimension embeddings.
- Pinecone Vector Search: It queries a Pinecone vector index using the embeddings to find the nearest matching card variant.
- Deck Code Generation: The matched card IDs are resolved to game definition IDs and packaged into a standard base64 deck code.
Ways to Use It
- Server Commands: Include
!deckin a message with a screenshot, native forwarded message, or image URL. - Reactions: Add a 🔍 reaction to any message containing an image.
- Direct Messages: Send a screenshot directly to the bot for a private response.
Configuration
The bot requires the following variables (stored in a .env file for local development or as environment variables in your cloud dashboard):
Local Setup & Index Synchronization
- Clone the repository and install dependencies:
npm install- Create a
.envfile in the root directory and populate it with the configuration keys. - Populate the Pinecone database: Run the synchronization script to scan the MarvelSnap.pro CDN, generate CLIP embeddings for all card variants, and upsert them to Pinecone.
node sync_variants.js(Note: This creates local tracking files `known_variants.json` and `vectorized_variants.json` to allow incremental daily updates in under 2 seconds).
- Start the bot:
npm startDeployment
The project is configured to run 24/7 on Render's free tier.
- Create a new Web Service on Render and link this repository.
- Set the runtime to Node (or Docker if using the provided Dockerfile).
- Add the environment variables listed in the Configuration section.
