Skip to content

Tuxhar01/Varys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Infinite Story Engine

A collaborative storytelling platform for Reddit where the community votes on what happens next. Built with Reddit Devvit, powered by AI.

๐ŸŽฏ Overview

The Infinite Story Engine transforms a Reddit post into an interactive story where:

  • Community members submit story prompts via comments
  • The most upvoted prompt wins
  • AI (GPT-4o + DALL-E 3) generates the next chapter with an illustration
  • The story is displayed in a beautiful book reader with page-flip animations

๐Ÿš€ Features

  • Community Voting: Native Reddit upvoting determines story direction
  • AI Generation: GPT-4o creates story continuations, DALL-E 3 generates illustrations
  • Immersive Reader: 3D page-flip animations in a webview book reader
  • Scheduled Jobs: Automatic deadline processing and content generation
  • Content Moderation: Banned word filtering and OpenAI moderation
  • Error Handling: Graceful fallbacks and comprehensive logging

๐Ÿ“‹ Prerequisites

  • Node.js 18+ and npm
  • Reddit Developer Account
  • OpenAI API Key (with GPT-4o and DALL-E 3 access)
  • Devvit CLI installed: npm install -g devvit

๐Ÿ› ๏ธ Installation

  1. Clone and Install Dependencies

    npm install
  2. Configure Devvit

    devvit login
  3. Build the Project

    npm run build
  4. Upload to Reddit

    npm run upload
  5. Install on Your Subreddit

    • Go to your subreddit's mod tools
    • Navigate to Apps
    • Install "Infinite Story Engine"
  6. Configure Settings

    • Set your OpenAI API key (required)
    • Customize story title, genre, and opening paragraph
    • Set voting duration (default: 60 minutes)
    • Add banned words for content moderation (optional)

๐Ÿ“ Project Structure

infinite-story-engine/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.tsx                 # App entry point
โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ””โ”€โ”€ index.ts            # TypeScript interfaces
โ”‚   โ”œโ”€โ”€ handlers/
โ”‚   โ”‚   โ”œโ”€โ”€ install.ts          # Installation handler
โ”‚   โ”‚   โ”œโ”€โ”€ scheduler.ts        # Deadline processing
โ”‚   โ”‚   โ””โ”€โ”€ webview.ts          # API routes
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ storage.ts          # Redis operations
โ”‚   โ”‚   โ”œโ”€โ”€ reddit.ts           # Reddit API wrapper
โ”‚   โ”‚   โ””โ”€โ”€ openai.ts           # OpenAI integration
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ””โ”€โ”€ validation.ts       # Content moderation
โ”‚   โ””โ”€โ”€ webview/
โ”‚       โ”œโ”€โ”€ App.tsx             # React root
โ”‚       โ”œโ”€โ”€ components/
โ”‚       โ”‚   โ”œโ”€โ”€ BookCover.tsx   # Cover page
โ”‚       โ”‚   โ””โ”€โ”€ StoryPage.tsx   # Story page
โ”‚       โ””โ”€โ”€ styles/
โ”‚           โ””โ”€โ”€ book.css        # 3D animations
โ”œโ”€โ”€ devvit.yaml                 # Devvit configuration
โ”œโ”€โ”€ tsconfig.json               # TypeScript config
โ””โ”€โ”€ package.json                # Dependencies

๐ŸŽฎ How It Works

1. Installation

  • App creates an initial story post with opening paragraph
  • Sets up Redis storage for story state
  • Schedules deadline job for voting window

2. Voting Phase

  • Users comment with story ideas
  • Community upvotes/downvotes prompts
  • Native Reddit voting mechanics

3. Deadline Processing

  • Scheduled job triggers at deadline
  • Fetches and filters comments
  • Selects winner (highest upvotes, earliest for ties)
  • Calls OpenAI APIs for text and image generation
  • Updates post with new chapter
  • Saves to Redis

4. Story Reader

  • Webview displays story as a book
  • Page-flip animations between chapters
  • Credits winning authors
  • Responsive design for mobile/desktop

๐Ÿ”ง Configuration

App Settings (Mod-Configurable)

Setting Type Default Description
openai_api_key Secret - Your OpenAI API key (required)
voting_duration_minutes Number 60 How long voting stays open
story_title String "The Infinite Story" Title of your story
story_genre String "Fantasy" Genre for AI context
opening_paragraph Text Default text First paragraph
banned_words String "" Comma-separated banned words

Redis Keys

  • story:{postId} - Story state and chapters
  • deadline:{postId} - Voting deadline timestamp
  • job:{postId} - Job processing status

๐ŸŽจ Customization

Styling

Edit src/webview/styles/book.css to customize:

  • Colors and fonts
  • Page layout
  • Animation timing
  • Responsive breakpoints

AI Prompts

Modify src/services/openai.ts:

  • System prompts for story generation
  • Image generation prompts
  • Temperature and creativity settings

Voting Logic

Adjust src/services/reddit.ts:

  • Winner selection algorithm
  • Comment filtering rules
  • Tie-breaking logic

๐Ÿ› Troubleshooting

Common Issues

"OpenAI API key not configured"

  • Ensure you've set the API key in app settings
  • Key must have access to GPT-4o and DALL-E 3

"No valid comments found"

  • App uses fallback prompt automatically
  • Check banned words aren't too restrictive

"Image generation failed"

  • App continues with text-only
  • Check OpenAI API quota and permissions

"Job already processed"

  • Idempotency check prevents duplicate processing
  • Safe to ignore if job completed successfully

Debugging

Enable verbose logging:

// In src/main.tsx
console.log('Debug info:', data);

Check Redis state:

devvit redis get story:{postId}

๐Ÿ“Š Performance

  • Webview Load: < 2s on 4G
  • AI Generation: < 30s (with 25s timeout)
  • Full Cycle: < 2 minutes (voting โ†’ generation โ†’ update)

๐Ÿ”’ Security

  • API keys stored in Devvit Secrets (never exposed to client)
  • Content sanitization on all user inputs
  • OpenAI moderation endpoint for inappropriate content
  • Banned word filtering
  • Rate limiting via OpenAI API

๐Ÿ“ Development

Local Development

npm run dev

Build

npm run build

Type Checking

npm run lint

Upload to Reddit

npm run upload

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

๐Ÿ“„ License

ISC License - See LICENSE file for details

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support

For issues and questions:

๐ŸŽฏ Roadmap

  • Multi-chapter support (extend beyond Day One)
  • Story branching (multiple paths)
  • User profiles and leaderboards
  • Export stories as PDFs
  • Custom illustration styles
  • Voice narration
  • Mobile app integration

Made with โค๏ธ for Reddit Hackathon 2026