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
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/noderunners/dlbot/internal/cache"
|
||||
"github.com/noderunners/dlbot/internal/config"
|
||||
"github.com/noderunners/dlbot/internal/db"
|
||||
"github.com/noderunners/dlbot/internal/groups"
|
||||
"github.com/noderunners/dlbot/internal/i18n"
|
||||
"github.com/noderunners/dlbot/internal/sched"
|
||||
"github.com/noderunners/dlbot/internal/service"
|
||||
@@ -41,6 +42,10 @@ type Deps struct {
|
||||
// WorkerSlots is the number of download slots serving the queue. It
|
||||
// only feeds the wait estimate.
|
||||
WorkerSlots func() int
|
||||
// Admins verifies group admins. A nil value gets a default checker.
|
||||
Admins *groups.Admins
|
||||
// ReloadI18n reloads the catalogs from disk. Nil when they are built in.
|
||||
ReloadI18n func() error
|
||||
}
|
||||
|
||||
// Bot handles Telegram updates and job events.
|
||||
@@ -53,6 +58,7 @@ type Bot struct {
|
||||
bill *billing.Billing
|
||||
cashu billing.Cashu
|
||||
cache *cache.Cache
|
||||
admins *groups.Admins
|
||||
storage storage.Storage
|
||||
tr *i18n.Bundle
|
||||
log *slog.Logger
|
||||
@@ -75,6 +81,11 @@ type Bot struct {
|
||||
// cancelledAt is when each user last sent /cancel. A playlist item
|
||||
// that was already being looked up at that moment must not start.
|
||||
cancelledAt map[int64]time.Time
|
||||
// broadcasts holds texts waiting for the owner's confirmation.
|
||||
broadcasts map[string]string
|
||||
reloadI18n func() error
|
||||
// broadcastGap is the pause between two broadcast messages.
|
||||
broadcastGap time.Duration
|
||||
|
||||
// Tunables, shortened in tests.
|
||||
reconcileEvery time.Duration
|
||||
@@ -122,10 +133,18 @@ func New(ctx context.Context, d Deps) (*Bot, error) {
|
||||
sending: map[string]bool{},
|
||||
pumping: map[int64]bool{},
|
||||
cancelledAt: map[int64]time.Time{},
|
||||
broadcasts: map[string]string{},
|
||||
reloadI18n: d.ReloadI18n,
|
||||
broadcastGap: 50 * time.Millisecond,
|
||||
admins: d.Admins,
|
||||
reconcileEvery: 5 * time.Second,
|
||||
statusMinGap: 3 * time.Second,
|
||||
invoiceGrace: 5 * time.Second,
|
||||
}
|
||||
if b.admins == nil {
|
||||
b.admins = groups.NewAdmins(d.API, 0)
|
||||
}
|
||||
d.Service.SetAdmins(b.admins)
|
||||
d.Sched.Subscribe(func(ev sched.Event) {
|
||||
select {
|
||||
case b.events <- ev:
|
||||
@@ -152,8 +171,12 @@ func (b *Bot) SetTimings(reconcile, statusGap time.Duration) {
|
||||
b.reconcileEvery = reconcile
|
||||
b.statusMinGap = statusGap
|
||||
b.invoiceGrace = 4 * reconcile
|
||||
b.broadcastGap = time.Millisecond
|
||||
}
|
||||
|
||||
// Admins returns the group admin checker, shared with the Mini App API.
|
||||
func (b *Bot) Admins() *groups.Admins { return b.admins }
|
||||
|
||||
// Run processes updates and job events until ctx ends, then waits for
|
||||
// in-flight work to finish.
|
||||
func (b *Bot) Run(ctx context.Context, updates <-chan telego.Update) {
|
||||
@@ -236,6 +259,8 @@ func updateChatID(u telego.Update) int64 {
|
||||
return u.CallbackQuery.Message.GetChat().ID
|
||||
}
|
||||
return u.CallbackQuery.From.ID
|
||||
case u.MyChatMember != nil:
|
||||
return u.MyChatMember.Chat.ID
|
||||
}
|
||||
return int64(u.UpdateID)
|
||||
}
|
||||
@@ -247,6 +272,8 @@ func (b *Bot) HandleUpdate(ctx context.Context, u telego.Update) {
|
||||
b.handleMessage(ctx, u.Message)
|
||||
case u.CallbackQuery != nil:
|
||||
b.handleCallback(ctx, u.CallbackQuery)
|
||||
case u.MyChatMember != nil:
|
||||
b.handleMyChatMember(ctx, u.MyChatMember)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user