Phase 5: groups

Group wallets, group passes, spending rules and admin-only settings.

- Groups recorded from my_chat_member; admin rights verified with
  getChatMember and cached for five minutes
- Group context in entitlement resolution: group pass, group credits under
  the spending rule (anyone, admins only, capped per person per day) and
  the group's daily cap; refunds go back to the wallet that paid
- Group gate before any lookup: bot on or off, who may use it, allowed
  and blocked sites, plus the owner's maintenance mode
- /settings with inline toggles checked on every press, /grouplang,
  /autodetect, /allow, /block, /spending, /groupwallet, /grouppass,
  /groupstats
- Deep links with the target pre-selected: paying for a group happens in
  the private chat; a refused download in a group offers "Buy for me" and
  "Add group credits"
- Optional link detection, tidy mode, default quality and language per
  group; per-member usage
- /quality, /language, /app, /privacy, /terms, /support
- Remaining owner tools: /stats, /queue all, /user, /group, /ban, /unban,
  /grant (passes and gift codes), /credit, /refund, /blocklist,
  /broadcast with confirmation, /maint, /reload i18n

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 09:46:32 +00:00
co-authored by Claude Fable 5.2
parent 7d4893bc3f
commit 51371da0e0
23 changed files with 3231 additions and 81 deletions
+22
View File
@@ -43,6 +43,7 @@ phase; sections for later phases say so.
| `internal/billing/lnbits` | LNbits HTTP client. |
| `internal/cache` | file_id and stored-copy cache, TTLs, eviction, takedown. |
| `internal/ffmpeg` | Transcoding lower profiles from a stored copy. |
| `internal/groups` | Group admin verification with a cache, host list matching. |
| `internal/links` | URL extraction, validation, redaction. |
| `internal/storage` | `Storage` interface and the local disk backend. |
| `internal/db` | Schema migrations and queries for SQLite and Postgres. |
@@ -329,6 +330,27 @@ when over budget (least recently and least often used first, keeping their
`file_id`), and removes stored files that no live job and no cache entry
references.
## Groups
A group has a row in `groups`, optional `group_settings`, and a wallet of
its own (`wallets.owner_type = 'group'`). `group_usage_daily` counts what
each member used per day; it backs the spending caps and the
usage-by-member view.
For a request from a group, `service.entitle` loads the group's settings
and wallet, asks `groups.Admins` whether the requester is an admin, works
out whether this requester may spend group credits right now (rule,
per-person cap, group daily cap), and hands all of it to the resolver as
plain data. The resolver stays pure.
`service.gate` then applies what is not about money: maintenance mode,
whether the bot is on in the group, who may use it, and the site lists.
It runs before a link is even looked up, and again when a download starts.
Admin-only actions are checked in one place each: `requireAdmin` for
commands and `cbSetting` for buttons, both through `groups.Admins`, which
asks Telegram and caches the answer.
## Internationalization
Handlers never contain user-facing text. They call `i18n.Bundle` with a