Craig Discord Recorder Documentation

repository·master·Indexed 19 days ago

https://github.com/craigchat/craig

Documentation for Craig, a multi-track voice recorder for Discord that enables high-quality audio capture from voice channels. Includes guides on self-hosting, configuring the bot via JavaScript objects (covering Redis, sharding, and Discord connection via dexare), managing reward tiers, and using slash commands such as /join, /autorecord, /features, and /info.

Tokens
28.2K
Snippets
122
Records
138
Agent score
68%

What's inside Craig

  1. Install Craig using Docker

    master

    If you prefer using Docker, ensure Docker is running on your host machine, then build the image from the main repository directory:

    docker build -t craig .

    Note: If using Docker, you must update the DATABASE_URL in your install.config to use the Docker network bridge format:

    DATABASE_URL="postgresql://$POSTGRESQL_USER:$POSTGRESQL_PASSWORD@db:5432/$DATABASE_NAME?schema=public"
  2. Discord Bot Setup Guide

    master

    To connect your Craig instance to Discord, you must create a Discord Bot application and collect the following credentials:

    1. Application ID: Found under SETTINGS -> General Information. Maps to DISCORD_APP_ID in install.config.
    2. Bot Token: Found under SETTINGS -> Bot. Maps to DISCORD_BOT_TOKEN in install.config.
    3. Client ID: Found under SETTINGS -> OAuth2 -> General. Maps to CLIENT_ID in install.config.
    4. Client Secret: Found under SETTINGS -> OAuth2 -> General. Maps to CLIENT_SECRET in install.config.

    Required Redirect URI: In the Discord Developer Portal, navigate to SETTINGS -> OAuth2 -> General, click Add Redirect, and paste: http://localhost:3000/api/login

    Optional Development Guild: To test experimental slash commands in a specific server without affecting all servers, set the DEVELOPMENT_GUILD_ID in install.config and run yarn run sync:dev.

  3. Invite Craig to a Discord server

    master

    Once your instance is running, you can invite the bot to your server by constructing an OAuth2 URL. Replace CLIENT_ID with your actual Discord Bot Client ID:

    https://discord.com/oauth2/authorize?client_id=CLIENT_ID&permissions=68176896&scope=bot%20applications.commands

  4. Install Craig on Linux

    master

    To install Craig on a fresh Linux installation (tested on Ubuntu 22.04 and Kubuntu 23.10), follow these steps:

    1. Clone the source code using submodules:
      git clone --recurse-submodules https://github.com/CraigChat/craig.git
    2. Configure environment variables by copying the example config:
      cp ./install.config.example ./install.config
      Edit install.config with your Discord credentials (see Discord Bot Setup).
    3. Run the installation script from the main directory:
      ./install.sh
      The script requires sudo privileges to install dependencies (like redis, postgresql, ffmpeg, etc.) and configure the database. Errors and warnings are logged to install.log.
    git clone --recurse-submodules https://github.com/CraigChat/craig.git
    cp ./install.config.example ./install.config
    ./install.sh
  5. Configure tier-based access in Dropdown items

    master

    The Dropdown component can automatically disable items based on a user's tier level.

    1. Provide a tier prop to the Dropdown component representing the user's current level.
    2. Add a tierRequired property to specific DropdownItem objects.

    An item is considered disabled if:

    • item.disabled is true.
    • item.tierRequired is greater than the tier provided to the Dropdown (and tier is not -1).
    // If user tier is 0, 'Pro' will be disabled because it requires tier 1
    <Dropdown 
      tier={0} 
      items={[
        { title: 'Free', value: 'free' },
        { title: 'Pro', value: 'pro', tierRequired: 1 }
      ]} 
    />
  6. Use environment-specific configurations in slash-up

    master

    You can define different settings for different environments using the env property in slash-up.config.js. You can switch between these environments at runtime using the --env or -e CLI flag.

    For example, in a development environment, you might want to use the globalToGuild option. This option forces global commands to sync to a specific guild ID instead of globally, which is useful for faster testing.

    // In slash-up.config.js
    env: {
      development: {
        globalToGuild: process.env.DEVELOPMENT_GUILD_ID
      }
    }
    
    // Run with the flag:
    // slash-up --env development
  7. Configure install.config environment variables

    master

    The install.config file manages the core environment for your Craig instance.

    Required Variables

    • DISCORD_BOT_TOKEN: Your Discord bot token.
    • DISCORD_APP_ID: Your Discord application ID.
    • CLIENT_ID: Your OAuth2 Client ID.
    • CLIENT_SECRET: Your OAuth2 Client Secret.

    Suggested Changes for Self-Hosting

    • API_HOST: Change from 127.0.0.1 to 0.0.0.0 to allow access from other machines on your network (especially useful in Docker/headless environments).
    • API_HOMEPAGE: Set this to the IP address or domain name of your machine (e.g., http://192.168.0.10:5029) so that download links generated by Craig are functional.
  8. Initialize and connect the CraigBot

    master

    To start the bot, call the connect() function. This function performs several critical setup steps:

    1. Loads core modules (Logger, Slash, Sharding, Recorder, etc.).
    2. Registers default commands: eval, ping, kill, exec, load, unload, reload.
    3. Initializes internationalization (i18n).
    4. Registers all command files found in the configured commandsPath.
    5. Connects to Redis and the Discord gateway via Dexare.
    6. Connects to the Prisma database.
    7. Starts the InfluxDB cron job.

    To shut down the bot gracefully, call disconnect(), which closes the Discord connection, Sentry, Prisma, and Redis.

    import { connect, disconnect } from './bot';
    
    // Start the bot
    await connect();
    
    // ... run bot ...
    
    // Graceful shutdown
    await disconnect();
  9. Deploy Craig using Docker Compose

    master

    Craig can be deployed using a docker-compose.yml file that orchestrates three main services: db (PostgreSQL), redis, and the craig application itself.

    Service Dependencies

    • The craig service depends on the db service being service_healthy and the redis service being service_started.
    • The db service uses a healthcheck via pg_isready to ensure the database is ready before the application starts.

    Port Mapping

    • Craig Application: Maps ports 3000 and 5029 to the host.
    • PostgreSQL: Maps port 5432 to the host.
    • Redis: Maps port 6379 to the host.

    Volumes and Persistence

    • db_data: Persists PostgreSQL data.
    • craig_rec: Persists application records at /app/rec inside the container.
    • ./install.config: The application expects a local install.config file to be mounted as read-only at /app/install.config.
    services:
      db:
        image: postgres
        environment:
          POSTGRES_PASSWORD: craig
          POSTGRES_DB: craig
          POSTGRES_USER: craig
        ports:
          - "5432:5432"
        volumes:
          - 'db_data:/var/lib/postgresql/data'
      redis:
        image: redis
        ports:
          - "6379:6379"
      craig:
        build: .
        ports:
          - "3000:3000"
          - "5029:5029"
        depends_on:
          db:
            condition: service_healthy
          redis:
            condition: service_started
        volumes:
          - 'craig_rec:/app/rec'
          - './install.config:/app/install.config:ro'
    
    volumes:
      db_data:
      craig_rec:
  10. Troubleshoot HTTPS/Localhost download issues

    master

    Craig automatically serves download pages via https://. If you are running on localhost, browsers may block the download because they lack a signed certificate for https://localhost.

    Workaround: Manually change the protocol from https:// to http:// in your browser address bar.

    Example:

    • Change https://localhost:5029/rec/RECORDING_ID
    • To http://localhost:5029/rec/RECORDING_ID