diff --git a/README.md b/README.md index 94f6f31..567964f 100644 --- a/README.md +++ b/README.md @@ -1,76 +1,147 @@ -I wrote this bot in one night, while I'm recovering from two level cervical spinal surgery, CDA Cervical Discectomy and Disc Arthroplasty. Expect a lot of bugs. +# ๐Ÿ„ Funguy Bot -# Matrix Bot +A modular, security-focused Matrix chat bot built with [`simplematrixbotlib`](https://simple-matrix-bot-lib.readthedocs.io/), written in Python. Features a plugin architecture, in-process cron scheduling, per-room plugin management, rate limiting, and a full suite of recon, encoding, and utility commands. -Matrix Bot is a Python-based chat bot designed to work with Matrix, an open network for secure, decentralized communication. This bot is built using the `simplematrixbotlib` library and provides various commands and functionalities for interacting with Matrix rooms. +> Written during recovery from cervical spinal surgery (CDA โ€“ Cervical Discectomy and Disc Arthroplasty). Expect bugs โ€” please report them! -## Features +--- -- Modular architecture: Commands are implemented as separate plugins, making it easy to add or modify functionality. -- Command handling: The bot listens for specific commands prefixed with `!` and responds accordingly. -- Plugin system: Each command is implemented as a separate plugin module, allowing for easy customization and extension. -- Extensible: Users can add new commands by creating additional plugin modules. +## ๐Ÿ“‹ Table of Contents -## Automatic Installation -Run the installation script -1. `./install-funguy.sh` +- [Features](#-features) +- [Requirements](#-requirements) +- [Installation](#-installation) +- [Configuration](#-configuration) +- [Running the Bot](#-running-the-bot) +- [Core Admin Commands](#-core-admin-commands) +- [Plugin Reference](#-plugin-reference) +- [Rate Limiting](#-rate-limiting) +- [Security Notes](#-security-notes) +- [Support](#-support) +- [Credits](#-credits) -2. Launch the bot: -`sudo systemctl start funguybot` +--- -## Manual Installation +## โœจ Features -1. Create python venv -`python3 -m venv venv` -`source venv/bin/activate` +- **Modular plugin system** โ€“ each command lives in its own `plugins/*.py` file; add or remove features without touching core code +- **Runtime plugin management** โ€“ load, unload, enable, or disable plugins per-room with no restart required +- **In-process cron scheduler** โ€“ schedule any bot command to fire automatically (APScheduler + SQLite, no system crontab needed) +- **Rate limiting** โ€“ non-admin users are capped at 3 commands per 5-second window; admins are always exempt +- **SSRF protection** โ€“ all outbound network plugins validate that targets resolve to public IPs only +- **Admin/moderator access control** โ€“ a dedicated `admin_user` is set in config; moderation commands require power level โ‰ฅ 50 +- **Live configuration** โ€“ settings can be changed at runtime with `!set`/`!saveconf` without restarting -2. Clone the repository: -`git clone https://gitlab.com/Eggzy/funguybot.git` +--- -3. Apply the patch -`cp api.py.patch simplematrixbotlib` -`git apply api.py.patch` +## ๐Ÿ“ฆ Requirements -4. Install dependencies: -`cd simplematrixbotlib && pip install .` -`cd ../ && pip install -r requirements.txt` +- Python 3.9+ +- A Matrix homeserver account for the bot +- `fortune` package installed on the host (`sudo apt install fortune`) if using `fortune.py` +- `dict` / WordNet installed on the host (`sudo apt install dict dict-wn`) if using `dictionary.py` +- Optional API keys for certain plugins (see [Configuration](#-configuration)) -5. If you use the Goodreads quote plugin (quote.py): +--- -`pip install playwright beautifulsoup4 lxml` -`playwright install chromium` +## ๐Ÿš€ Installation -6. Set up environment variables: -Create/Edit `.env` file in the root directory of the bot and add the following variables: +**1. Clone the repository** -``` -MATRIX_URL="https://matrix.org" (or another homeserver) -MATRIX_USER="" -MATRIX_PASS="" -OPENWEATHER_API_KEY="" # Optional: For weather plugin - -SMTP_SERVER = "example.com`" -SMTP_PORT = 465 -SMTP_USER = "name@domain.tld" -SMTP_PASSWORD = "somepassword" - -OPENWEATHER_API_KEY= -SHODAN_KEY= -DNSDUMPSTER_KEY= -LASTFM_API_KEY= -YOUTUBE_API_KEY= - -INFERMATIC_API= -INFERMATIC_MODEL= -OMDB_API_KEY= -GNEWS_API_KEY= +```bash +git clone https://gitlab.com/Eggzy/funguybot.git +cd funguybot ``` -7. Create systemd.service -Create `/etc/systemd/system/funguybot.service` -Replace `$working_directory` with your bot install path +**2. Create and activate a Python virtual environment** +```bash +python3 -m venv venv +source venv/bin/activate ``` + +**3. Install dependencies** + +```bash +pip3 install -r requirements.txt +``` + +**4. (Optional) Install Playwright for the Goodreads quote plugin (`quote.py`)** + +```bash +pip3 install playwright beautifulsoup4 lxml +playwright install chromium +``` + +**5. Configure the bot** โ€” create your `.env` and `funguy.conf` files (see [Configuration](#-configuration)) + +**6. Set up and start the systemd service** (see [Running the Bot](#-running-the-bot)) + +--- + +## โš™๏ธ Configuration + +### Environment Variables (`.env`) + +Create a `.env` file in the bot's root directory. Only the three Matrix variables are required; all API keys are optional. + +```env +# โ”€โ”€ Required โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +MATRIX_URL="https://matrix.org" # Your homeserver URL +MATRIX_USER="@yourbot:matrix.org" # Bot's Matrix ID +MATRIX_PASS="your_password" # Bot's password + +# โ”€โ”€ Logging (optional, default: INFO) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +LOG_LEVEL=INFO # DEBUG | INFO | WARNING | ERROR | CRITICAL + +# โ”€โ”€ Plugin API Keys (all optional) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +OPENWEATHER_API_KEY= # weather.py +SHODAN_KEY= # shodan.py +DNSDUMPSTER_KEY= # dnsdumpster.py +LASTFM_API_KEY= # lastfm.py +YOUTUBE_API_KEY= # youtube-search.py +INFERMATIC_API= # infermatic-text.py +INFERMATIC_MODEL= # infermatic-text.py โ€“ model name string +OMDB_API_KEY= # imdb.py +GNEWS_API_KEY= # news.py + +# โ”€โ”€ SMTP (optional, for notification plugins) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +SMTP_SERVER=mail.example.com +SMTP_PORT=465 +SMTP_USER=bot@example.com +SMTP_PASSWORD=yourpassword +``` + +### Bot Configuration (`funguy.conf`) + +Create `funguy.conf` in the bot's root directory. This is a TOML file consumed by `simplematrixbotlib` and the `config.py` plugin. + +```toml +[simplematrixbotlib.config] +admin_user = "@youradmin:matrix.org" # Full Matrix ID of the admin +prefix = "!" # Single-character command prefix +join_on_invite = true +encryption_enabled = false +emoji_verify = false +ignore_unverified_devices = true +store_path = "./store/" + +# Pre-disable plugins per room (optional) +[plugins.disabled] +# "!yourroom:matrix.org" = ["pluginname1", "pluginname2"] +``` + +All writable options can also be changed live by the admin using `!set` (see [config.py](#configpy--live-configuration-admin-only)). + +--- + +## ๐Ÿค– Running the Bot + +### Systemd Service (Recommended) + +Create `/etc/systemd/system/funguybot.service`, replacing the `$variables` with your actual paths and user: + +```ini [Unit] Description=Funguy Bot Service After=network.target @@ -88,101 +159,678 @@ SyslogIdentifier=funguybot [Install] WantedBy=multi-user.target -EOF ``` -8. Launch Fungy -``` +```bash systemctl daemon-reload systemctl enable funguybot systemctl start funguybot ``` -# ๐Ÿ„ Funguy Bot Commands ๐Ÿ„ +### Direct Launch -## Available Plugins - -The bot includes the following plugins: - -- **admin.py**: Full room moderation โ€“ multi-word name support -- **arxiv.py**: arXiv academic paper search -- **bitcoin.py**: Current Bitcoin price -- **common.py**: Shared utilities for FunguyBot plugins. -- **config.py**: Admin-only configuration commands (preserves disabled plugins) -- **cron.py**: In-process cron scheduler (room-aware, no system crontab) -- **date.py**: Show current date and time -- **ddg.py**: DuckDuckGo search plugin -- **dictionary.py**: Look up word definitions using system dictionary -- **dns.py**: DNS reconnaissance (SSRF-safe) -- **dnsdumpster.py**: DNSDumpster domain reconnaissance -- **encode.py**: Comprehensive CyberChef-like encoding and analysis toolkit -- **exploitdb.py**: Exploit-DB search -- **fortune.py**: Random fortune message -- **geo.py**: IP geolocation lookup -- **hackernews.py**: Hacker News integration -- **hashid.py**: Hash type identifier -- **headers.py**: HTTP security header analysis -- **help.py**: Plugin for dynamically aggregating help from all loaded plugins. -- **imdb.py**: IMDb lookup via OMDb API -- **infermatic-text.py**: AI text generation via Infermatic API -- **isup.py**: Check if a site is up -- **joke.py**: Get random jokes from the Official Joke API -- **karma.py**: Room karma tracking system (display names only, no Matrix IDs) -- **lastfm.py**: Last.fm music stats with aligned code block output -- **loadplugin.py**: Load/unload plugins at runtime -- **news.py**: News headlines via GNews API -- **plugins.py**: List all loaded plugins with count -- **proxy.py**: Working SOCKS5 proxy finder -- **quote.py**: Fetch Goodreads quotes -- **roomstats.py**: Per-user room statistics -- **shodan.py**: Shodan.io reconnaissance -- **sslscan.py**: SSL/TLS security scanner -- **stable-diffusion.py**: Stable Diffusion image generation (LORA support) -- **subdomains.py**: Subdomain enumeration via CertSpotter -- **subnet.py**: Subnet calculator -- **sysinfo.py**: System information plugin -- **timezone.py**: World clock (offline IANA zones + free geocoding) -- **urbandictionary.py**: Urban Dictionary definitions -- **utils.py**: Security utilities for Funguy Bot plugins. -- **weather.py**: Weather data plugin -- **welcome.py**: Room welcome message -- **whois.py**: Domain WHOIS lookup -- **wikipedia.py**: Wikipedia article summary -- **xkcd.py**: Fetch random or specific xkcd comics -- **youtube-search.py**: YouTube video search - -## Configuration - -The bot uses a TOML configuration file (`funguy.conf`) for settings: -- `admin_user` - Matrix user ID with admin privileges -- `prefix` - Command prefix (default: "!") -- Plugin-specific settings in `plugins/ai.json` for AI commands - -## Dependencies - -- Python 3.7+ -- simplematrixbotlib -- Various AI/ML services (Stable Diffusion, Ollama, etc.) -- Database support (SQLite) -- External APIs (OpenWeatherMap, Urban Dictionary, YouTube) - -## Dependencies - -- Ensure all environment variables are set correctly -- Check that required services are running (Stable Diffusion API, Ollama, etc.) -- Verify plugin permissions and whitelist settings -- Check logs for detailed error information - -## Support - -Join our Matrix room for support and community: -[Self-hosting | Security | Sysadmin | Homelab | Programming](https://matrix.to/#/#selfhosting:mozilla.org) - -## Credits - -**๐Ÿง™โ€โ™‚๏ธ Creator & Developer**: HB (@hashborgir:mozilla.org) -**๐Ÿ„ Funguy Bot** - Created during recovery from cervical spinal surgery +```bash +source venv/bin/activate +python3 funguy.py +``` --- -*Note: This bot was created rapidly and may contain bugs. Please report issues and contribute improvements!* +## ๐Ÿ”‘ Core Admin Commands + +These commands are handled by `funguy.py` itself and require `admin_user` privileges. + +| Command | Description | +|---------|-------------| +| `!reload` | Reload all plugins from disk (no restart needed) | +| `!load ` | Dynamically load a single plugin by filename (without `.py`) | +| `!unload ` | Dynamically unload a single plugin | +| `!enable ` | Re-enable a plugin in the current room | +| `!disable ` | Disable a plugin in the current room (persisted to `funguy.conf`) | +| `!restart` | Gracefully stop the bot process (systemd will restart it automatically) | +| `!rehash` | Reload `funguy.conf` and the disabled-plugin list without restarting | + +--- + +## ๐Ÿงฉ Plugin Reference + +All commands use the prefix defined in `funguy.conf` (default `!`). Plugin filenames correspond to the names used with `!load` / `!unload` / `!disable` / `!enable`. + +--- + +### ๐Ÿ›ก๏ธ admin.py โ€“ Room Moderation + +Full moderator toolkit with multi-word display name resolution. Requires power level โ‰ฅ 50 or `admin_user`. The bot automatically resolves multi-word display names and prompts with a numbered disambiguation list when names are ambiguous. + +| Command | Description | +|---------|-------------| +| `!kick [reason]` | Kick a user from the room | +| `!ban [reason]` | Ban a user | +| `!unban <@user:domain>` | Unban a user (full MXID required) | +| `!invite ` | Invite a user to the room | +| `!op [power_level]` | Promote a user (max 50 / moderator level) | +| `!deop ` | Demote a user to power level 0 | +| `!userinfo ` | Show display name and power level | +| `!topic [new topic]` | View or set the room topic | +| `!roomname [new name]` | View or set the room name | +| `!avatar [mxc://โ€ฆ]` | View or set the room avatar (must be an `mxc://` URL) | +| `!members` | List all joined members with power levels | +| `!bans` | List all banned users | +| `!modhelp` | Show moderator command reference | + +`!admin ` also works as an explicit parent command for all of the above. + +--- + +### ๐Ÿ“„ arxiv.py โ€“ arXiv Academic Search + +| Command | Description | +|---------|-------------| +| `!arxiv ` | Search papers with abstracts | +| `!arxiv list ` | Search titles only (no abstracts) | +| `!arxiv category ` | Browse recent papers by category | +| `!arxiv recent [category]` | Papers from the last 7 days | +| `!arxiv random` | Random paper | +| `!arxiv ` | Fetch paper by arXiv ID (e.g. `2101.00101`) | + +**Categories:** `ai`, `ml`, `security`, `crypto`, `cv`, `nlp`, `math`, `physics`, `quantum`, `bio`, `software` + +--- + +### โ‚ฟ bitcoin.py โ€“ Bitcoin Price + +``` +!btc +``` + +Fetches the latest BTC/USD price from `bitcointicker.co` (Bitstamp feed, 60-second intervals). No API key required. + +--- + +### โš™๏ธ config.py โ€“ Live Configuration *(Admin Only)* + +Manage bot settings at runtime. Changes are in-memory until you run `!saveconf`. + +| Command | Description | +|---------|-------------| +| `!set