Updated readme

This commit is contained in:
2026-08-07 17:17:43 -05:00
parent 187add59b2
commit a0dbf3be92
+53 -76
View File
@@ -1,101 +1,76 @@
# titlebot-ng # titlebot-ng
A Matrix chat bot for Jupiter Broadcasting's <s>"The Lunch"</s> shows "The Lunch" and "Linux Unplugged" chat room that collects and posts title suggestions. A Matrix chat bot for Jupiter Broadcasting's "The Lunch" and "Linux Unplugged" chat rooms that collects and posts title suggestions with web-based voting.
### From the Owner ### From the Owner
This has gotten out of hand. I've been woking 7 days a week for a couple years now and this has been my most recent mortar between the bricks of time that I've been squeezing out of my life between sleep. Simplification needs to happen whenever possible. This has gotten out of hand. I've been working 7 days a week for a couple years now and this has been my most recent mortar between the bricks of time that I've been squeezing out of my life between sleep. Simplification needs to happen whenever possible.
# Technical Outline # Technical Outline
At the moment, there are 6 processes that make up the whole project and must be run simultaneously: The project is a mix of Python (Matrix bot services) and Go (voting backend). Each room gets its own instance of every Python service, so the number of running processes scales with the number of configured rooms.
- scraper.py
- post_results.py
- get_user_list.py
- get_votes.py
- jsonEndpoint/jep
- voteServer/vs
### scraper.py
What it says on the tin. Reads configured target matrix room and collects suggestions
### post_results.py
Listens for the !gettitles command and readies the votes
### get_user_list.py
Gets a list of users in the room who have more than n votes and puts them in a database so that the voting can have some degree of validation beyond random voters being allowed in.
### get_votes.py
Listens for the !getvotes command in the chat room, reads the output of the http voting, and writes the results back to the room
### jsonEndpoint/jep
Provides a json endpoint for a list of all provided votes and who voted for them
### voteServer/vs
Provides a webpage where voters can vote
Services:
- **scraper.py** - Reads configured target Matrix room and collects suggestions
- **post_results.py** - Listens for the `!gettitles` command and posts suggestions for voting
- **get_user_list.py** - Collects the list of users in the room (with post counts and last activity) for vote validation
- **get_votes.py** - Listens for the `!getvotes` command and posts vote results to the room
- **jsonEndpoint/** - Go service (port 9080) exposing JSON endpoints for submissions and users
- **voteServer/** - Go service (port 9081) serving the web voting interface
Everything is launched by `run_all.sh`, which auto-installs Go, creates the Python venv, discovers room configs, builds the Go services, and starts one instance of each Python service per room.
## Features ## Features
- **Suggestion Collection**: Monitors chat for messages starting with `!suggest`, `!Suggest`, `!suggestion`, `!Suggestion`, `SUGGEST`, or `!sug` - **Suggestion Collection**: Monitors chat for messages starting with `!suggest`, `!Suggest`, `!suggestion`, `!Suggestion`, `SUGGEST`, or `!sug`
- **Interactive Voting**: Posts suggestions individually with 👍 reactions for voting - **Interactive Voting**: Posts suggestions individually with 👍 reactions for voting
- **Web Voting Interface**: Dedicated voting server with validation (exact display-name match + activity window)
- **Multi-Room Support**: One config file per room under `configs/`, with URL slugs for routing
- **Command System**: - **Command System**:
- `!gettitles` - Triggers posting of collected suggestions - `!gettitles` - Triggers posting of collected suggestions
- `!mayhem` - Generates chaotic text using Ollama AI - `!mayhem` - Generates chaotic text using Ollama AI
- `!countvotes` - Counts upvotes on posted suggestions - `!countvotes` - Counts 👍 upvotes on posted suggestions
- `!getvotes` - Posts current vote results from the voting server - `!getvotes` - Posts current results from the voting server
- `!voteurl` - Shares the voting URL where users can cast their votes - `!voteurl` - Shares the voting URL where users can cast their votes
- **Persistent Storage**: SQLite database per room with duplicate prevention - **Persistent Storage**: Per-room SQLite databases with duplicate prevention
- **Acknowledgment System**: Reacts with ✅ to confirm suggestion collection - **Acknowledgment System**: Reacts with ✅ to confirm suggestion collection
- **Web Voting Interface**: Dedicated voting server with vote validation - **Command Deduplication**: All commands are logged to prevent duplicate executions
## Quick Start ## Quick Start
1. Create and activate a Python virtual environment: 1. Clone the repo and copy the example config for each room you want to monitor:
```bash ```bash
python3 -m venv .venv cp configs/config_example.yaml configs/config.yaml
source .venv/bin/activate # Edit configs/config.yaml with your Matrix credentials and room ID
``` ```
2. Install dependencies: 2. Run everything with a single command (installs Go and creates the venv if missing):
```bash ```bash
./run_all.sh
```
Or run the components individually:
```bash
python3 -m venv .venv && source .venv/bin/activate
pip install matrix-nio pyyaml requests pip install matrix-nio pyyaml requests
``` cd jsonEndpoint && go build -o jep . && ./jep
cd voteServer && go build -o vs . && ./vs
3. Configure the bot:
```bash
cp config_example.yaml config.yaml
# Edit config.yaml with your Matrix credentials and room ID
```
4. Run the bot components:
```bash
# Terminal 1: Collect suggestions
python3 scraper.py
# Terminal 2: Post suggestions when requested
python3 post_results.py
``` ```
## Configuration ## Configuration
Create `config.yaml` based on `config_example.yaml`: One YAML file per room in `configs/`. Example (`configs/config_example.yaml`):
```yaml ```yaml
username: "your_bot_username" username: "magbot"
password: "your_bot_password" password: "your_bot_password"
room_id: "!your_room_id:homeserver.com" room_id: "!your_room_id:homeserver.com" # Matrix room to monitor
homeserver: "https://matrix.org" # Optional, defaults to matrix.org lookback_seconds: 86400 # 24 hours
lookback_limit: 7200 # Seconds to look back for suggestions (2 hours) lookback_limit: 400 # Max messages to look back when scraping
batch_size: 100 # Messages to fetch per batch dump_mode: False # Dump raw messages when scraping (debugging)
dbName: "suggestions.db" # Optional, auto-generated if not set dbName: "my_db_name" # Optional, auto-derived from room_id if empty
vote_host: "localhost" # Hostname for voting interface (e.g., "localhost", "example.com", "vote.mysite.xyz") vote_host: "localhost" # Hostname for voting interface (e.g., "example.com", "vote.mysite.xyz")
# vote_path: "my-room-slug" # Optional URL slug; auto-derived from room name if unset
vote_activity_hours: 72 # Hours a user must have been active within to be eligible to vote
``` ```
The bot resolves each room's voting page to a URL slug (`vote_path` config override, otherwise derived from the room name/alias) and persists the mapping to `room_slugs.json`, which the Go services read for routing.
## Architecture ## Architecture
- **`room.py`**: Core `Room` class handling Matrix connection, database operations, and command processing - **`room.py`**: Core `Room` class handling Matrix connection, database operations, and command processing
- **`post.py`**: `Post` class representing individual suggestions - **`post.py`**: `Post` class representing individual suggestions
@@ -109,16 +84,18 @@ vote_host: "localhost" # Hostname for voting interface (e.g., "localhost", "exa
- **`run_all.sh`**: Master script to start all services - **`run_all.sh`**: Master script to start all services
## Database Schema ## Database Schema
- **suggestions**: Stores collected suggestions with metadata Per room (suffixed with a sanitized room ID):
- **gettitles/mayhem/countvotes/getvotes/voteurl**: Command execution logs to prevent duplicates - **suggestions.db**: Collected suggestions with metadata (`is_posted`, `event_id`)
- **last_run/last_post**: Timestamps for state management - **users.db**: User info (`display_name`, `num_posts`, `last_active`) for vote validation, plus a `fetch_log` of collection runs
- **users**: User information for vote validation - **votes.db**: Web votes cast via the voting interface
Shared:
- **last_run.db / last_post.db**: Timestamps for state management
- Command log tables (`gettitles`, `mayhem`, `countvotes`, `getvotes`, `voteurl`) live inside each room's suggestions database and prevent duplicate executions
## Dependencies ## Dependencies
- **matrix-nio**: Matrix client library - **Python**: matrix-nio, pyyaml, requests, sqlite3 (built-in)
- **pyyaml**: Configuration file parsing - **Go**: github.com/mattn/go-sqlite3, gopkg.in/yaml.v2
- **requests**: HTTP requests for Ollama integration
- **sqlite3**: Built-in database support
## Optional: Ollama Integration ## Optional: Ollama Integration
For `!mayhem` command functionality: For `!mayhem` command functionality:
@@ -129,10 +106,10 @@ For `!mayhem` command functionality:
## Notes ## Notes
- Each room gets its own SQLite database for suggestions - Each room gets its own SQLite database for suggestions
- The bot acknowledges collected suggestions with ✅ reactions - The bot acknowledges collected suggestions with ✅ reactions
- Voting uses 👍 reactions on individual suggestion posts - Voting uses 👍 reactions on individual suggestion posts and a web voting interface
- Command deduplication prevents spam and duplicate executions - Command deduplication prevents spam and duplicate executions
- Safe database naming handles special characters in room IDs - Safe database naming handles special characters in room IDs
- Web votes are tied to a user's exact Matrix display name; voters must have been active in the room within `vote_activity_hours` of the most recent room activity
# TODO: # TODO:
- Rewrite in Rust - Rewrite in Rust