Phase 2: command screens

- /help: a short introduction with the user's default format, how to be
  asked every time and the limits on one line, plus buttons Commands,
  Account, Groups, Open app and Upgrade that switch the same message to
  a section. Group commands are hidden in private chats; "Add me to a
  group" takes their place.
- /quality: Ask every time, Best that fits my limit, Best, 1080p, 720p,
  480p and Audio only, with the active one checked. Free users see which
  qualities may go over their limit.
- /history: pages of five compact buttons (site, title, format, when),
  a view per download with Send again, Thumbnail, Remove from history,
  and Clear history with a confirmation. Thumbnails are grouped under
  their video. Migration 00007 stores extractor, title, uploader and
  profile on deliveries and adds a hidden flag.
- docs/SCREENS.md shows every screen in en, es and nl, generated by the
  language test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 20:46:13 +00:00
co-authored by Claude Opus 5.5
parent 6843053582
commit 123cede7f3
21 changed files with 3758 additions and 183 deletions
+47 -5
View File
@@ -9,6 +9,7 @@ import (
"github.com/noderunners/dlbot/internal/db"
"github.com/noderunners/dlbot/internal/i18n"
"github.com/noderunners/dlbot/internal/media"
"github.com/noderunners/dlbot/internal/service"
)
// This file is /settings in a private chat: the person's own settings in
@@ -90,7 +91,7 @@ func (b *Bot) personalView(ctx context.Context, act actor) (string, *telego.Inli
b.tr.T(lang, "settings.button", i18n.Args{"Label": label, "Value": value}), cbData(cbPersonal, key))}
}
rows := [][]telego.InlineKeyboardButton{
row(psQuality, b.tr.T(lang, "settings.quality", nil), b.userQualityName(lang, u.Quality)),
row(psQuality, b.tr.T(lang, "settings.format", nil), b.userQualityName(lang, u.Quality)),
row(psAudio, b.tr.T(lang, "settings.audio_only", nil), b.onOff(lang, u.Quality == string(media.MP3))),
row(psAsk, b.tr.T(lang, "settings.ask", nil), b.onOff(lang, u.Quality == qualityAsk)),
row(psLanguage, b.tr.T(lang, "settings.language", nil), langName),
@@ -141,7 +142,8 @@ func (b *Bot) cbPersonalSetting(ctx context.Context, q *telego.CallbackQuery, ac
case psHome:
case psQuality:
b.answer(ctx, q, "", false)
show(b.tr.HTML(act.lang, "quality.pick", nil), b.qualityKeyboard(act, func(v string) string {
risky, maxSize := b.riskyQualities(ctx, act)
show(b.qualityText(act.lang, risky, maxSize), b.qualityKeyboard(act, risky, func(v string) string {
return cbData(cbPersonal, psSetQ, v)
}, true))
return
@@ -207,9 +209,46 @@ func (b *Bot) cbPersonalSetting(ctx context.Context, q *telego.CallbackQuery, ac
show(b.personalView(ctx, act))
}
// qualityKeyboard lists the default formats with the active one checked.
// data builds the callback data of a choice.
func (b *Bot) qualityKeyboard(act actor, data func(v string) string, back bool) *telego.InlineKeyboardMarkup {
// typicalBitrate is a usual total bitrate per quality, in bits per
// second, for warning free users before they pick a default.
var typicalBitrate = map[media.Profile]int64{
media.Best: 6_000_000, media.P1080: 4_500_000, media.P720: 2_500_000, media.P480: 1_200_000, media.MP3: 192_000,
}
// riskyQualities are the defaults that are likely to go over a free
// user's size limit on a video as long as their duration limit allows.
// Paid users get no warning: their limits are far apart from these. The
// pick text then explains what happens in that case.
func (b *Bot) riskyQualities(ctx context.Context, act actor) (map[string]bool, int64) {
dec, err := b.svc.Entitlement(ctx, service.Who{UserID: act.user.ID, ChatID: act.user.ID, ChatType: telego.ChatTypePrivate}, false)
if err != nil || dec.Source.Paid() {
return nil, 0
}
maxSize := min64(dec.Limits.MaxSize, b.cfg.MaxUploadBytes())
if maxSize <= 0 || dec.Limits.MaxDuration <= 0 {
return nil, 0
}
out := map[string]bool{}
for p, bps := range typicalBitrate {
if bps/8*dec.Limits.MaxDuration > maxSize {
out[string(p)] = true
}
}
return out, maxSize
}
// qualityText is the text above the quality picker.
func (b *Bot) qualityText(lang string, risky map[string]bool, maxSize int64) string {
text := b.tr.HTML(lang, "quality.pick", nil)
if len(risky) > 0 {
text += "\n\n" + b.tr.HTML(lang, "quality.over_note", i18n.Args{"MaxSize": b.tr.Size(lang, maxSize)})
}
return text
}
// qualityKeyboard lists the default formats with the active one checked,
// and the risky ones marked. data builds the callback data of a choice.
func (b *Bot) qualityKeyboard(act actor, risky map[string]bool, data func(v string) string, back bool) *telego.InlineKeyboardMarkup {
lang := act.lang
cur := act.user.Quality
if cur == qualityUnset {
@@ -217,6 +256,9 @@ func (b *Bot) qualityKeyboard(act actor, data func(v string) string, back bool)
}
opt := func(v string) telego.InlineKeyboardButton {
label := b.userQualityName(lang, v)
if risky[v] {
label = b.tr.T(lang, "btn.maybe_over", i18n.Args{"Label": label})
}
if v == cur {
label = b.tr.T(lang, "btn.checked", i18n.Args{"Label": label})
}