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
+64
View File
@@ -452,3 +452,67 @@ Read from the LNbits source at `v0.12.12` (the target) and `v1.7.1` (current).
- Each worker updates its own yt-dlp on a schedule (`yt-dlp -U`).
`/ytdlp update` is delivered to workers with their next claim, so it
reaches every connected worker within seconds.
## Phase 5
### Groups
- **Groups are recorded** from `my_chat_member` updates, and also the first
time a command is used in one, in case that update was missed.
- **Admin rights come from Telegram only** (`getChatMember`), cached for
five minutes per group and user. A change of admins can therefore take up
to five minutes to reach the bot. The cache for a group is dropped when
the bot's own status in it changes.
- **Anonymous admins are not supported for commands.** A message sent "as
the group" carries no user to verify. Buttons work, because a button
press always carries the real user.
- **The settings panel is visible to every member**, so each button press
is checked again. A member who presses gets a notice and nothing changes.
- **A switched-off bot is silent in that group**, except for `/settings`
from an admin, which is how it is switched on again.
- **"Pass holders"** means: the requester has a pass of their own, or the
group has one, or they are an admin.
- **Spending rule "capped"** counts group credits a member spent today
(UTC). The first time it is chosen in the quick settings the cap defaults
to four downloads' worth.
- **Site lists** match a host and its subdomains. With an empty allow list
every site is allowed. At most 50 entries per list.
- **Group size and duration caps** can only lower what the group's pass or
credits allow, and only apply when the group pays. They are set from the
Mini App (Phase 6), not from a command.
- **Group language** overrides each member's language for everything the
bot says in that group.
- **Default quality** (group or personal) skips the card and starts that
format at once.
- **"Delete command messages"** needs the bot to be an admin with the right
to delete. Without it the delete fails quietly.
- **Auto-detect** takes the first link of a message. It needs the bot to
see ordinary messages (admin, or group privacy off), which the bot says
when the setting is turned on.
### Paying for a group
- **Anyone can pay into a group wallet.** What is bought belongs to the
group. Invoices only ever appear in the payer's private chat; the group
shows deep links (`?start=gw_<chat id>`) with the group pre-selected.
- A purchase for a group does not auto-start the download that was refused.
The requester presses the format button again.
- Refunds for downloads paid with group credits go back to the group.
### Owner tools
- Owner commands exist only in a private chat with a configured owner. For
everyone else, and for owners in groups, they are unknown commands.
- `/grant <id> <day|week|month>` and `/credit`, `/refund` take a user ID,
or a negative chat ID for a group. `/refund <id> pass <duration>` extends
a running pass.
- `/grant code ...` creates gift codes.
- `/broadcast` shows a preview and sends only after the owner presses the
confirm button. It goes to every user who is not banned, about 20
messages per second.
- `/maint on` refuses new downloads for everyone but owners. Running jobs
finish.
- `/reload i18n` needs `LOCALES_DIR`; catalogs built into the binary cannot
change at runtime.
- `/privacy`, `/terms` and `/support` are short texts in the catalog.
Replace them with your own before running a public bot.