# calc — IRC Bot A single-file IRC bot in C. Features a key-value store backed by SQLite3, weather lookups via wttr.in, and AI-powered replies. ## Features - **Key-Value Store**: Persist facts, notes, or any data with `calc key = value` - **Weather**: Current conditions and 3-day forecasts via `wttr.in` - **AI Queries**: Ask questions via `!ai` or by addressing the bot; powered by `opencode` - **Chat Greetings**: Responds to `hi`, `hello`, `hey`, `bye`, and more - **TLS**: Secure connections via OpenSSL - **Rate Limiting**: Per-nick protection against spam - **Single File**: Easy to deploy and modify ## Requirements - `gcc` (or any C99 compiler) - `libssl-dev` (OpenSSL) - `libdl` (dynamic linker) - `libsqlite3` (loaded at runtime via `dlopen`) - `curl` (for weather lookups) - `opencode` (for AI queries — see `calc.c:229` to configure path) ## Build ```sh make ``` Set custom compiler or flags: ```sh make CC=clang CFLAGS="-O2 -Wall -Wextra" ``` ## Usage ```sh ./calc [options] ``` ### Options | Option | Description | |---|---| | `-ssl` | Enable TLS (auto-enabled on ports 6697/7000) | | `-noverify` | Skip TLS certificate verification | | `-server ` | IRC server (default: `irc.libera.chat`) | | `-port

` | Port (default: `6697`) | | `-pass

` | Server password | | `-nick ` | Nickname (default: `calc`) | | `-join ` | Auto-join channels, comma-separated (default: `#calctest`) | | `-h` | Show help | ### Example ```sh ./calc -ssl -nick mybot -join "#mychan,#myotherchan" ``` ## IRC Commands | Command | Description | |---|---| | `calc ` | Look up a stored value | | `calc = ` | Store a value (key is lowercased) | | `!ping` | Responds with `pong` | | `!weather [city]` | Current weather (default: Berlin) | | `!forecast [city]` | 3-day forecast (default: Berlin) | | `!ai ` | Ask the AI a question | | `!quit` / `!die` | Shut down the bot | | `: hi` | Greeting response | | `: ` | Ask the bot anything (AI) | ## Installation ```sh make install ``` Installs to `$(PREFIX)/bin` (default: `/usr/local/bin`). Override the prefix: ```sh make install PREFIX=$HOME/.local ``` ## Database Data is stored in `calc.db` (SQLite3) in the working directory. The bot creates two tables: - `calc` — key-value pairs with nick and timestamp metadata - `ai_pending` — single-row table for managing in-flight AI queries ## Architecture `calc` uses a single `poll()` loop with a 100ms timeout. AI queries fork a child process that runs the `opencode` CLI; the parent picks up the result on the next poll iteration. SQLite3 is loaded at runtime via `dlopen` to avoid a compile-time dependency. ## License MIT - see LICENSE file.