feat(matrixbot): stop auto-joining invites, restrict commands to two rooms
Lint / JS (eslint) (push) Successful in 40s
Lint / Python (ruff) (push) Successful in 10s
Lint / Python deps (pip-audit) (push) Successful in 1m44s
Lint / Secret scan (gitleaks) (push) Successful in 33s
Lint / Shell (shellcheck) (push) Successful in 11s

#general is now published to the public room directory, so the bot is
reachable by strangers. Two hardening changes:

- Invites are only accepted from INVITE_ALLOWED_USERS (defaults to
  ADMIN_USERS). Anything else is declined via room_leave so hostile
  invites do not accumulate as pending. Previously any invite from
  anyone was auto-joined.
- Commands and the passive scramble/riddle answer checks only run in
  COMMAND_ROOMS (#commands and #management). The gate sits early in
  Callbacks.message, so the bot stays silent everywhere else, including
  #general. Set COMMAND_ROOMS="*" to restore the old behaviour.

Reaction handlers are deliberately left ungated so the welcome flow
keeps working; game votes elsewhere cannot match an active game.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-16 01:37:45 -04:00
co-authored by Claude Opus 5
parent 7c05827dbc
commit 9e5d3ec83d
3 changed files with 39 additions and 8 deletions
+7 -1
View File
@@ -3,7 +3,7 @@ from functools import wraps
from nio import AsyncClient
from config import BOT_PREFIX, MATRIX_USER_ID
from config import BOT_PREFIX, COMMAND_ROOMS, MATRIX_USER_ID
from commands import (
COMMANDS,
metrics,
@@ -50,6 +50,12 @@ class Callbacks:
if event.sender == MATRIX_USER_ID:
return
# Only act in designated command rooms. This covers both prefixed
# commands and the passive game-answer checks below, so the bot never
# speaks in public rooms such as #general. "*" allows every room.
if "*" not in COMMAND_ROOMS and room.room_id not in COMMAND_ROOMS:
return
body = event.body.strip() if event.body else ""
# Check active non-command games that monitor all room messages