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:
co-authored by
Claude Fable 5.2
parent
7d4893bc3f
commit
51371da0e0
@@ -0,0 +1,70 @@
|
||||
-- +goose Up
|
||||
-- Groups the bot was added to, recorded from my_chat_member updates.
|
||||
CREATE TABLE groups (
|
||||
chat_id BIGINT PRIMARY KEY,
|
||||
title TEXT NOT NULL DEFAULT '',
|
||||
type TEXT NOT NULL DEFAULT 'supergroup',
|
||||
bot_status TEXT NOT NULL DEFAULT 'member',
|
||||
added_by BIGINT NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL
|
||||
);
|
||||
|
||||
-- Per-group settings, changed by group admins only. A group without a row
|
||||
-- runs on the defaults.
|
||||
CREATE TABLE group_settings (
|
||||
chat_id BIGINT PRIMARY KEY,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
auto_detect BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
allowed_sites TEXT NOT NULL DEFAULT '',
|
||||
blocked_sites TEXT NOT NULL DEFAULT '',
|
||||
who_can_use TEXT NOT NULL DEFAULT 'everyone',
|
||||
max_size_mb BIGINT NOT NULL DEFAULT 0,
|
||||
max_duration_s BIGINT NOT NULL DEFAULT 0,
|
||||
spend_rule TEXT NOT NULL DEFAULT 'admins',
|
||||
spend_cap_sats BIGINT NOT NULL DEFAULT 0,
|
||||
daily_cap_sats BIGINT NOT NULL DEFAULT 0,
|
||||
delete_commands BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
default_quality TEXT NOT NULL DEFAULT '',
|
||||
lang TEXT NOT NULL DEFAULT '',
|
||||
updated_at BIGINT NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
-- What each member used in a group per UTC day: for spending caps and for
|
||||
-- the usage-by-member view.
|
||||
CREATE TABLE group_usage_daily (
|
||||
chat_id BIGINT NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
day INTEGER NOT NULL,
|
||||
downloads INTEGER NOT NULL DEFAULT 0,
|
||||
sats BIGINT NOT NULL DEFAULT 0,
|
||||
bytes BIGINT NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (chat_id, user_id, day)
|
||||
);
|
||||
|
||||
-- Which users were seen in which group, so "my groups" can be listed
|
||||
-- without asking Telegram about every group.
|
||||
CREATE TABLE group_users (
|
||||
chat_id BIGINT NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
last_seen_at BIGINT NOT NULL,
|
||||
PRIMARY KEY (chat_id, user_id)
|
||||
);
|
||||
CREATE INDEX group_users_user_idx ON group_users (user_id);
|
||||
|
||||
-- Small key-value store for owner switches such as maintenance mode.
|
||||
CREATE TABLE kv (
|
||||
k TEXT PRIMARY KEY,
|
||||
v TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- A user's default format: "" asks every time.
|
||||
ALTER TABLE users ADD COLUMN default_quality TEXT NOT NULL DEFAULT '';
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE users DROP COLUMN default_quality;
|
||||
DROP TABLE kv;
|
||||
DROP TABLE group_users;
|
||||
DROP TABLE group_usage_daily;
|
||||
DROP TABLE group_settings;
|
||||
DROP TABLE groups;
|
||||
Reference in New Issue
Block a user