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
+91 -1
View File
@@ -2,8 +2,10 @@ package app_test
import (
"context"
"encoding/json"
"fmt"
"io/fs"
"os"
"regexp"
"sort"
"strings"
@@ -198,6 +200,24 @@ func tour(t *testing.T, h *moneyHarness, user int64, lang string) {
seq = send(cmd)
h.wait(seq, "sendMessage", inChat)
}
// Help sections and the history screens.
seq = send("/help")
help := h.wait(seq, "sendMessage", inChat)
for _, key := range []string{"hp:cmds", "hp:acct", "hp:groups", "hp:home"} {
seq = h.srv.Seq()
h.srv.PushCallback(user, user, help.MessageID, key)
h.wait(seq, "editMessageText", func(c fakeserver.Call) bool { return c.MessageID == help.MessageID })
}
seq = send("/history")
hist := h.wait(seq, "sendMessage", inChat)
editedHist := func(seq int) fakeserver.Call {
return h.wait(seq, "editMessageText", func(c fakeserver.Call) bool { return c.MessageID == hist.MessageID })
}
item := editedHist(pressOn(hist, "hv:"))
back := editedHist(pressOn(item, "hd:"))
ask := editedHist(pressOn(back, "hc:"))
editedHist(pressOn(ask, "hy"))
// An invoice.
seq = send("/buy")
buy := h.wait(seq, "sendMessage", inChat)
@@ -224,15 +244,34 @@ func tourFake() *ytdlptest.Fake {
}
}
// TestEveryScreenInSpanishAndDutch walks every screen in Spanish and in
// Dutch. With DLBOT_SCREENS=<file> it also walks them in English and
// writes what each screen shows, in all three languages, to that file for
// review: DLBOT_SCREENS=$PWD/docs/SCREENS.md go test ./internal/app -run TestEveryScreen
func TestEveryScreenInSpanishAndDutch(t *testing.T) {
foreign := englishOnly(t)
for _, lang := range []string{"es", "nl"} {
langs := []string{"es", "nl"}
out := os.Getenv("DLBOT_SCREENS")
if out != "" {
langs = []string{"en", "es", "nl"}
}
var dump strings.Builder
dump.WriteString("# Screens\n\nWhat the bot shows on every screen of a scripted walk through it, in each\n" +
"language, in order. Generated by TestEveryScreenInSpanishAndDutch with\n" +
"DLBOT_SCREENS set; do not edit by hand. Buttons are in brackets.\n")
for _, lang := range langs {
t.Run(lang, func(t *testing.T) {
// A missing message or a fallback to English is logged as a bug,
// which fails the test (see guardHandler).
h := startApp(t, tourFake(), nil)
const user = int64(501)
tour(t, h, user, lang)
if out != "" {
writeScreens(&dump, h.harness, user, lang)
}
if lang == "en" {
return
}
var leaks []string
for text, where := range shownTo(h.harness, user) {
@@ -249,6 +288,57 @@ func TestEveryScreenInSpanishAndDutch(t *testing.T) {
}
})
}
if out != "" {
if err := os.WriteFile(out, []byte(dump.String()), 0o644); err != nil {
t.Fatal(err)
}
}
}
// writeScreens appends what a chat showed, call by call, to a review file.
func writeScreens(sb *strings.Builder, h *harness, chat int64, lang string) {
fmt.Fprintf(sb, "\n## %s\n", lang)
last := ""
for _, c := range h.srv.Calls("") {
if c.Failed {
continue
}
text := c.Text()
switch {
case c.Method == "answerCallbackQuery":
text = c.Params["text"]
if text == "" {
continue
}
case c.ChatID() != chat || text == "" || strings.HasPrefix(c.Method, "get") || strings.HasPrefix(c.Method, "set"):
continue
}
// One line per keyboard row, as Telegram shows them.
var markup struct {
Rows [][]struct {
Text string `json:"text"`
} `json:"inline_keyboard"`
}
_ = json.Unmarshal([]byte(c.Params["reply_markup"]), &markup)
var btns []string
for _, row := range markup.Rows {
var line []string
for _, b := range row {
line = append(line, "["+b.Text+"]")
}
btns = append(btns, strings.Join(line, " "))
}
entry := text + "\n" + strings.Join(btns, "\n")
if entry == last {
continue
}
last = entry
fmt.Fprintf(sb, "\n%s\n\n```\n%s\n", c.Method, text)
if len(btns) > 0 {
fmt.Fprintf(sb, "%s\n", strings.Join(btns, "\n"))
}
sb.WriteString("```\n")
}
}
// --- language resolution -----------------------------------------------------