Skip to content

vhrita/musa-bot

Repository files navigation

๐ŸŽต Musa Bot - The Music Fairy

Musa - Fairy of Music
Musa, the Fairy of Music from Winx Club

๐Ÿ’ซ About Musa

Musa is inspired by the music fairy from Winx Club, bringing magical musical experiences to Discord servers. Originally created for the WINX Discord channel (established in 2016), Musa has been the soundtrack companion for a tight-knit gaming community of friends for nearly a decade.

Named after the fairy of music herself, Musa embodies the spirit of bringing people together through the power of music, just like how the WINX server has connected friends through gaming and conversation since 2016.

๐Ÿ“œ Legacy Version: The original Python implementation has been preserved in the legacy branch for historical reference.

โœจ Modern Architecture & Features

๐ŸŽฏ Built with TypeScript

  • Type Safety: Full TypeScript implementation for robust development
  • Modern Node.js: Latest practices and ES2022+ features
  • Enhanced Performance: Optimized memory management and async processing
  • Scalable Design: Modular architecture with proper separation of concerns

๐Ÿ”„ Advanced Capabilities

  • Multi-Source Architecture: Intelligent music source prioritization and fallback
  • Advanced Voice Management: Robust connection handling with automatic recovery
  • Rich Discord Integration: Beautiful themed embeds with Musa's musical personality
  • Comprehensive Logging: Detailed event tracking and structured error handling
  • Configuration Management: Flexible environment-based configuration system
  • Docker Support: Full containerization with optimized production builds

๐Ÿ—๏ธ Technical Architecture

๐ŸŽผ Intelligent Multi-Source Music System

  • ๐ŸŽต YouTube (Priority 1) - Vast music library with advanced search
  • ๐Ÿ“ป Radio Stations (Priority 2) - Live streaming for continuous music
  • ๐Ÿ“š Internet Archive (Priority 3) - High-quality audio archives

๐Ÿ›ก๏ธ Smart Quality Filtering

  • Intelligent file size analysis and validation
  • Creator validation to avoid low-quality uploads
  • Duration optimization for optimal listening experience
  • Automatic filtering of non-music content

๐ŸŽจ Musa's Musical Personality

  • Purple Theme: Consistent purple color scheme (๐ŸŸฃ #8B5DBC)
  • Musical Language: Commands respond with rhythm and music metaphors
  • Fairy Magic: Sparkles, notes, and magical elements throughout
  • Warm Personality: Friendly, encouraging responses with musical flair

๐Ÿš€ Quick Start

๐Ÿ“‹ Prerequisites

  • Node.js 18+
  • npm or yarn
  • Discord Bot Token
  • FFmpeg (for audio processing)

๐Ÿ› ๏ธ Installation

  1. Clone the repository:
git clone https://github.com/vhrita/musa-bot.git
cd musa-bot
  1. Install dependencies:
npm install
  1. Configure environment:
cp .env.template .env
# Edit .env with your Discord token and preferences
  1. Build and start:
# Development mode
npm run dev

# Production build
npm run build
npm start

๐Ÿณ Docker Deployment (Recommended)

Production Deployment

# Using docker-compose (recommended)
docker-compose up -d

# Or build and run manually
docker build -t musa-bot .
docker run -d --name musa-bot-container --env-file .env musa-bot

Development with Debugging

# Build debug image
docker build -f Dockerfile.debug -t musa-bot-debug .

# Run with debugging enabled (port 9229)
docker run --rm -p 9229:9229 --env-file .env -v $(pwd)/logs:/app/logs musa-bot-debug

๐Ÿ“ Project Structure

musa-bot/
โ”œโ”€โ”€ ๐ŸŽญ src/
โ”‚   โ”œโ”€โ”€ commands/           # Slash commands
โ”‚   โ”œโ”€โ”€ events/            # Discord event handlers
โ”‚   โ”œโ”€โ”€ services/          # Music services & management
โ”‚   โ”œโ”€โ”€ types/             # TypeScript type definitions
โ”‚   โ”œโ”€โ”€ utils/             # Utility functions
โ”‚   โ”œโ”€โ”€ config/            # Configuration management
โ”‚   โ””โ”€โ”€ index.ts           # Main application entry
โ”œโ”€โ”€ ๐Ÿ—๏ธ dist/               # Compiled JavaScript (generated)
โ”œโ”€โ”€ ๐Ÿ”ง .env                # Environment configuration
โ”œโ”€โ”€ ๐Ÿ“Š logs/               # Application logs
โ”œโ”€โ”€ ๐Ÿช cookies/            # YT-DLP cookies (if using YouTube)
โ”œโ”€โ”€ ๐Ÿ“ฆ package.json        # Dependencies & scripts
โ”œโ”€โ”€ โš™๏ธ tsconfig.json       # TypeScript configuration
โ”œโ”€โ”€ ๐Ÿณ Dockerfile          # Production container
โ”œโ”€โ”€ ๐Ÿงช Dockerfile.debug    # Development container
โ””โ”€โ”€ ๐Ÿ™ docker-compose.yml  # Production orchestration

๐ŸŽต Commands Overview

๐ŸŽผ Music Commands

  • /play <query|url>
    • Query: searches across sources (YouTube/YouTube Music) and adds the best match
    • URL YouTube/YouTube Music: plays the video directly (with rich metadata)
    • URL Spotify (track): fetches metadata via Spotify API and plays the matching version on YouTube
  • /playlist <url> [limit] [offset] [source]
    • Adds an entire playlist from YouTube/YouTube Music/Spotify
    • Immediate firstโ€‘track flush: playback starts as soon as the first resolved item is added
    • Batch ingestion (tunable), dedupe optional, progress updates and โ€œcontinueโ€ hint with offset
  • /radio <genre> - Add curated radio stations by genre
  • /queue - Display current playlist with rich UI (now + next tracks)
  • /skip - Skip to next track
  • /pause / /resume - Playback control
  • /stop - Stop music and clear queue
  • /shuffle - Randomize playlist order (re-evaluates prefetch)

๐ŸŽจ Visual Features

  • Purple Embeds: Musa's signature color scheme
  • Musical Emojis: Notes, instruments, and fairy elements
  • Service Icons: Visual indicators for different music sources
  • Rich Information: Duration, artist, queue position, and more

โš™๏ธ Configuration

The bot follows 12โ€‘factor config with a validated schema (Zod). See full, upโ€‘toโ€‘date configuration and defaults here:

  • docs/BOT_CONFIG.md
  • youtube-resolver/README.md (for the Raspberry Pi resolver)

Key highlights (new):

  • Spotify
    • ENABLE_SPOTIFY=true
    • SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET (Client Credentials)
    • SPOTIFY_TIMEOUT_SECONDS (default 12), SPOTIFY_MARKET (default US)
  • Playlist ingestion tuning
    • YT_PLAYLIST_BATCH (default 100)
    • SPOTIFY_PLAYLIST_BATCH (default 50)
    • SPOTIFY_RESOLVE_CONCURRENCY (default 4)
    • DEDUPE_PLAYLIST (default true)
  • Resolver/YouTube
    • RESOLVER_URL to use the external resolver
    • COOKIES_PATH/YTDLP_COOKIES to enable age-restricted access and richer metadata (thumbnails)

๐ŸŽฏ Gaming Community Legacy

Since 2016, Musa has been the musical heartbeat of the WINX Discord server, providing:

  • Ambient Gaming Music: Perfect background tracks for gaming sessions
  • Community Bonding: Shared musical experiences that bring friends together
  • Nostalgia Factor: Soundtrack to countless memories and adventures
  • Reliability: Nearly a decade of faithful service to the gaming community

๐Ÿ”ฎ Continuous Evolution

Musa continues to evolve while maintaining her core mission: bringing friends together through music. Built with modern TypeScript architecture, she's designed for reliability, performance, and extensibility.

Whether it's providing the perfect soundtrack for an epic gaming session or discovering new music together, Musa remains the magical musical companion for the WINX community and beyond.

๐ŸŽต Fun Fact: Nearly a decade of faithful service to the gaming community, now with modern technology ensuring many more years of magical musical experiences!

๐Ÿ› ๏ธ Development

๐Ÿ“š Tech Stack

  • TypeScript - Type-safe development
  • Discord.js v14 - Discord API wrapper
  • @discordjs/voice - Voice connection handling
  • Winston - Logging framework
  • Axios - HTTP client for API calls
  • ESLint - Code linting and formatting

๐Ÿงช Development Scripts

npm run dev        # Development with hot reload
npm run build      # Production build
npm run start      # Start production build
npm run lint       # Run ESLint
npm run lint:fix   # Fix linting issues
npm test           # Run tests (when implemented)

๐Ÿ“š Additional Docs

  • docs/BOT_CONFIG.md โ€” Bot environment variables, defaults and behavior
  • youtube-resolver/README.md โ€” Resolver usage, security and configuration
  • docs/TODO.md โ€” Backlog and followโ€‘ups

๐Ÿงฉ Resolver Notes (YouTube)

  • The resolver prefers YouTube Music when supported by yt-dlp. If the installed yt-dlp doesn't support the ytmusicsearchN: pseudo-URL, the resolver automatically disables this preference and falls back to ytsearch (YouTube) without spamming errors.
  • For richer metadata (including thumbnails) the resolver avoids --flat-playlist for searches, and supports cookies via COOKIES_PATH.

๐ŸŽ›๏ธ Playlist Ingestion UX

  • The first track is flushed immediately for quick playback start; subsequent items are added in batches (see env tuning above).
  • When the queue hits MAX_QUEUE_SIZE, the bot shows a friendly message with how to continue using /playlist and the suggested offset.
  • Dedupe option avoids adding duplicates within the same ingestion when enabled.

๐Ÿณ Docker Development

# Production testing
docker-compose up --build

# Debug mode
docker build -f Dockerfile.debug -t musa-bot-debug .
docker run --rm -p 9229:9229 --env-file .env musa-bot-debug

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Follow TypeScript and ESLint conventions
  4. Test your changes thoroughly
  5. Submit a pull request

Musa - Fairy of Music
"In the power of music, we find the magic that connects us all"
- Inspired by Musa, Fairy of Music ๐ŸŽตโœจ

Built with โค๏ธ in TypeScript

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •