Skip to content

Repository files navigation

Cortex — Discord Daily Summary Bot

A production-ready Discord bot that aggregates messages from configured channels, summarizes them via local Ollama, and DMs you daily and weekly.

Features

  • Daily summary — Messages from configured channels summarized and sent via DM at a scheduled time
  • Weekly summary — Last 7 days of daily summaries aggregated into a weekly digest
  • 7-day retention — Summaries stored in SQLite for weekly rollup; old data pruned automatically

Requirements

  • Python 3.11+
  • Ollama running locally with a model (e.g. ollama pull llama3.2)
  • Discord bot token and server access for the channels you want to monitor

Setup

  1. Create a Discord application and bot

  2. Invite the bot to your servers with "Read Message History" and "Send Messages" (for DMs)

  3. Install Ollama and pull a model: ollama pull llama3.2

  4. Copy .env.example to .env and fill in values:

    cp .env.example .env
  5. Run with Docker:

    docker-compose up -d

    Or run locally:

    python -m venv .venv
    source .venv/bin/activate  # or `.\\.venv\\Scripts\\activate` on Windows
    pip install -r requirements.txt
    python -m src.main

Configuration

Variable Description
DISCORD_TOKEN Bot token
DISCORD_USER_ID Your Discord user ID (recipient of summaries)
CHANNEL_IDS Comma-separated channel IDs to monitor
OLLAMA_HOST Ollama API URL (use http://host.docker.internal:11434 in Docker to reach host Ollama)
OLLAMA_MODEL Model name (e.g. llama3.2, mistral)
SUMMARY_UTC_HOUR Hour for daily summary (0–23)
SUMMARY_UTC_MINUTE Minute for daily summary
SUMMARY_WEEKLY_DAY Day of week for weekly summary (0=Mon, 6=Sun)
SUMMARY_WEEKLY_UTC_HOUR Hour for weekly summary
SUMMARY_WEEKLY_UTC_MINUTE Minute for weekly summary

Limitations

  • Bot must be in the server and have Read Message History in each monitored channel
  • Ollama must be reachable from the container (e.g. host.docker.internal on Mac/Windows)
  • Only the last 500 messages per channel per run are collected

Troubleshooting: "Failed to connect to Ollama" in Docker

If Cortex runs in Docker and cannot reach Ollama:

  1. Ollama must listen on all interfaces — By default Ollama binds to 127.0.0.1, which is unreachable from a container. On the host, start Ollama with:

    OLLAMA_HOST=0.0.0.0 ollama serve

    Or set OLLAMA_HOST=0.0.0.0 in your shell before running ollama serve. If Ollama runs as a service, configure it to listen on 0.0.0.0.

  2. Use the right OLLAMA_HOST in .env — Inside the container, localhost refers to the container, not your machine. In .env set:

    OLLAMA_HOST=http://host.docker.internal:11434
    

    (Mac/Windows Docker Desktop). On Linux, host.docker.internal is not defined by default — add to docker-compose.yml under the service:

    extra_hosts:
      - "host.docker.internal:host-gateway"
  3. Verify Ollama is reachable — On the host: curl http://localhost:11434/api/tags. From inside the container:

    docker exec cortex curl -s http://host.docker.internal:11434/api/tags

    A JSON response means Ollama is reachable.

Ollama as a systemd service (Linux, runs in background, survives reboot)

If Ollama is not installed or you want a proper systemd service:

  1. Install Ollama (if needed):

    curl -fsSL https://ollama.com/install.sh | sh

    This creates the ollama user and installs the systemd unit.

  2. Stop any running Ollama so port 11434 is free:

    sudo systemctl stop ollama
    pkill ollama   # fallback if not managed by systemd
  3. Configure Ollama to listen on all interfaces (required for Docker). Use an override file so updates do not overwrite your config:

    sudo mkdir -p /etc/systemd/system/ollama.service.d
    printf '[Service]\nEnvironment="OLLAMA_HOST=0.0.0.0"\n' | sudo tee /etc/systemd/system/ollama.service.d/override.conf
  4. Reload, enable, and start:

    sudo systemctl daemon-reload
    sudo systemctl enable ollama
    sudo systemctl start ollama
  5. Verify — Ollama should listen on 0.0.0.0:11434:

    ss -tlnp | grep 11434
    # Expected: 0.0.0.0:11434 (not 127.0.0.1)
    curl -s http://localhost:11434/api/tags
  6. Pull a model (once):

    ollama pull llama3.2

Useful commands:

  • sudo systemctl status ollama — check status
  • sudo systemctl restart ollama — restart after config changes
  • sudo journalctl -u ollama -f — follow logs

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages