No description
  • Python 93.3%
  • Shell 5.5%
  • Batchfile 1.1%
  • Dockerfile 0.1%
Find a file
Sebastiaan Koetsier c771f46126 feat(ai): persist per-channel chat history across restarts
Store each completed user/assistant turn in a new phreakbot_ai_history
table (PostgreSQL via the existing pool) and lazily restore a channel's
last history_turns messages into the in-memory context on the first
request after a restart, so conversations survive redeployments.

- Table is created at runtime with CREATE TABLE IF NOT EXISTS because
  scripts/init_db.py only applies the schema on an empty DB, so a new
  table in dbschema.psql would never reach the deployed database.
- All DB access is best-effort: if db_pool is None or a query fails it
  logs and continues with in-memory history, so a DB outage is not a
  regression.
- Adds 9 unit tests covering table ensure, load (order + idempotency),
  persist, and DB-unavailable/failure fallbacks.
2026-07-16 09:41:28 +02:00
contrib v0.1.28 - Comprehensive test suite with pytest, unit tests, integration tests, and module tests 2025-11-27 11:29:36 +08:00
docs docs(ai): implementation plan for tool-calling and loose addressing 2026-07-16 07:48:22 +02:00
modules feat(ai): persist per-channel chat history across restarts 2026-07-16 09:41:28 +02:00
phreakbot_core security: fix 9 vulnerabilities found in security audit 2026-06-23 13:29:32 +02:00
scripts fix: resolve podman db race condition and prevent infoitems from capturing karma patterns 2026-05-22 16:00:19 +02:00
tests feat(ai): persist per-channel chat history across restarts 2026-07-16 09:41:28 +02:00
.coveragerc v0.1.28 - Comprehensive test suite with pytest, unit tests, integration tests, and module tests 2025-11-27 11:29:36 +08:00
.env.example Release v0.1.30 - Critical Security Fixes 2026-04-14 10:00:25 +02:00
.gitignore chore: remove CLAUDE.md from repo and gitignore it 2026-06-23 13:37:48 +02:00
CHANGELOG.md fix(karma): ignore karma pattern from unregistered users, bump to v0.1.40 2026-07-09 16:01:50 +02:00
config.json.pydle.example fix(ai): cap reasoning with thinking_budget=4096 2026-07-16 09:31:29 +02:00
create-autovoice-table.sql Update autovoice module to use channel-based toggle 2025-07-07 12:21:07 +08:00
dbschema.psql Release v0.1.30 - Critical Security Fixes 2026-04-14 10:00:25 +02:00
docker-compose.yml security: fix 9 vulnerabilities found in security audit 2026-06-23 13:29:32 +02:00
Dockerfile Update dependencies, improve code, and reorganize scripts 2025-11-26 12:23:20 +08:00
install.py fix(install): merge with existing config instead of overwriting 2026-07-16 09:27:14 +02:00
LICENSE Initial release 2025-07-06 17:20:54 +08:00
phreakbot.py fix: resolve podman db race condition and prevent infoitems from capturing karma patterns 2026-05-22 16:00:19 +02:00
pytest.ini v0.1.28 - Comprehensive test suite with pytest, unit tests, integration tests, and module tests 2025-11-27 11:29:36 +08:00
README.md fix(karma): ignore karma pattern from unregistered users, bump to v0.1.40 2026-07-09 16:01:50 +02:00
requirements.txt v0.1.28 - Comprehensive test suite with pytest, unit tests, integration tests, and module tests 2025-11-27 11:29:36 +08:00
VERSION fix(karma): ignore karma pattern from unregistered users, bump to v0.1.40 2026-07-09 16:01:50 +02:00

PhreakBot (v0.1.40)

PhreakBot is a modular IRC bot written in Python.

Features

  • Modular design with easy-to-add modules
  • Permission system with owner, admin, and user levels
  • Quote database with search functionality
  • URL title and description fetching
  • Channel management (join, part, topic)
  • User registration and management
  • Auto-op functionality
  • CTCP version support
  • Robust error handling and logging
  • Frys-IX peering LAN member information with port speed, IP, and max prefix details
  • MAC address vendor lookup for both full and partial MAC addresses
  • Mass user registration and hostmask merging
  • ROA validation and routing information
  • Karma system with ++ and -- support
  • And more!

Installation

PhreakBot supports both Docker and Podman.

  1. Copy .env.example to .env and update the values:

    cp .env.example .env
    
  2. Start the bot:

    Using Docker:

    docker-compose up -d
    

    Using Podman:

    podman-compose up -d
    

For detailed Podman instructions and features, see docs/PODMAN.md.

Manual Installation

  1. Clone the repository
  2. Install the required dependencies: pip install -r requirements.txt
  3. Set up a PostgreSQL database
  4. Run the SQL in dbschema.psql to create the necessary tables
  5. Configure the bot by editing config/config.json
  6. Run the bot: python phreakbot.py

PhreakBot uses the pydle IRC library, which offers:

  • Better handling of IRC events
  • Improved connection stability
  • Enhanced support for custom commands like !item = value and !item?
  • More detailed logging
  • Asynchronous operation for better performance

Scripts

All utility scripts are located in the scripts/ directory. See scripts/README.md for detailed information about each script.

Configuration

Docker / Podman

Configure via environment variables in .env (see .env.example for defaults):

# PostgreSQL credentials — POSTGRES_PASSWORD is required, no default
POSTGRES_USER=phreakbot
POSTGRES_PASSWORD=changeme
POSTGRES_DB=phreakbot

# IRC configuration — TLS on port 6697 is the default
IRC_SERVER=irc.libera.chat
IRC_PORT=6697
IRC_NICKNAME=PhreakBot
IRC_CHANNEL=#phreakbot

Manual Installation

Edit config/config.json to configure the bot:

{
    "server": "irc.example.com",
    "port": 6697,
    "use_tls": true,
    "tls_verify": true,
    "nickname": "PhreakBot",
    "realname": "PhreakBot",
    "channels": ["#channel1", "#channel2"],
    "command_trigger": "!"
}

Setting Up Ownership

When the bot first starts, use the !owner claim command to claim ownership of the bot. This will grant you admin privileges and allow you to manage the bot.

Module Development

Modules are stored in the modules directory. Each module should have a config function that returns a dictionary with the following keys:

  • events: List of IRC events to listen for
  • commands: List of commands the module provides
  • permissions: List of permissions required to use the module
  • help: Help text for the module

For detailed information on how to create your own modules, see the Module Development Guide.

Security

  • IRC connections default to TLS on port 6697 (use_tls: true). Plaintext port 6667 is intentionally not the default.
  • POSTGRES_PASSWORD must be set explicitly — the bot refuses to start if it is empty.
  • URL fetching (!url, auto-title, !@) is protected against SSRF: all redirect hops are re-checked against a blocked-network list (RFC 1918, loopback, link-local, cloud metadata endpoints).
  • The !ip command only reports public IP addresses; private/reserved addresses are blocked from output.
  • The permission system enforces an allowlist of valid permission names; unknown values are rejected at write time.
  • Exception details are never sent to IRC channels; full errors are logged server-side only.

See CHANGELOG.md for the full history of security fixes.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.