Phase 1: quick flow fixes

- One message per job: the status message is deleted once the file is
  sent, or shortened to "Sent." when Telegram keeps it.
- No reply quotes in private chats; groups keep them.
- Queue status only mentions the position when the wait is above
  QUEUE_NOTICE_THRESHOLD_SECONDS or somebody is ahead. Status edits are
  throttled to one per 2.5 s per message; a state that arrives too soon
  is shown later instead of dropped. The wait estimate is 0 with a free
  slot.
- Caption with title (uploader and date when generic), uploader,
  duration, a short source link without tracking parameters and an
  optional "via @bot" line (CAPTION_ATTRIBUTION). Uploaded videos get a
  320 px JPEG thumbnail; merged MP4s are written with faststart.
- Buttons under the result: Audio (MP3), Other quality, Thumbnail,
  Delete. Requester only in groups.
- Language resolved once per update and passed in the context. A
  fallback to English is logged as a bug; a test walks every screen in
  Spanish and Dutch. Language picker on the first /start.
- Sizes without a zero decimal ("50 MB").
- First link of a new user shows the card once and sets the default to
  "best that fits my limit".
- Errors offer the next step (Try again, Smaller quality, Upgrade, Open
  app); passing lookup failures are retried once.
- Up to MULTI_LINK_MAX links per message; a link sent a moment ago gets
  "already sent" with a Send again button.
- Mini App menu button, labelled per private chat in the user's
  language.
- Personal /settings in private chats with an "Add me to a group"
  button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 20:08:58 +00:00
co-authored by Claude Opus 5.5
parent 3c153af97f
commit 6843053582
52 changed files with 3369 additions and 271 deletions
+18 -3
View File
@@ -2,13 +2,15 @@ package i18n
import (
"fmt"
"math"
"strconv"
"strings"
"time"
)
// Size formats a byte count for humans in the user's locale, for example
// "61.9 MB" in English and "61,9 MB" in Spanish and Dutch.
// "61.9 MB" in English and "61,9 MB" in Spanish and Dutch. A whole number
// has no decimals: "50 MB", not "50.0 MB".
func (b *Bundle) Size(lang string, bytes int64) string {
const unit = 1024
p := b.printer(lang)
@@ -22,12 +24,25 @@ func (b *Bundle) Size(lang string, bytes int64) string {
if v >= 100 {
return p.Sprintf("%.0f MB", v)
}
return p.Sprintf("%.1f MB", v)
return p.Sprintf("%."+strconv.Itoa(decimals(v, 1))+"f MB", v)
default:
return p.Sprintf("%.2f GB", float64(bytes)/(unit*unit*unit))
v := float64(bytes) / (unit * unit * unit)
return p.Sprintf("%."+strconv.Itoa(decimals(v, 2))+"f GB", v)
}
}
// decimals is how many of at most max decimals v needs once rounded:
// 50.0 needs none, 1.50 needs one.
func decimals(v float64, max int) int {
scale := math.Pow(10, float64(max))
n := int64(math.Round(v * scale))
for max > 0 && n%10 == 0 {
n /= 10
max--
}
return max
}
// Clock formats a media duration as 1:02:03 or 2:03.
func Clock(seconds int64) string {
if seconds < 0 {
+27 -1
View File
@@ -218,16 +218,42 @@ func (b *Bundle) T(lang, id string, args Args) string {
cfg.PluralCount = c
}
}
out, err := b.localizer(lang).Localize(cfg)
out, tag, err := b.localizer(lang).LocalizeWithTag(cfg)
if err != nil && out == "" {
// A missing key is a bug caught by the catalog test. At runtime we
// show the ID so the gap is visible and searchable.
b.log.Error("i18n: missing message", "id", id, "lang", lang, "err", err)
return id
}
if b.fellBack(lang, tag) {
// The text exists, but only in English: the reader gets a sentence
// in the wrong language. Logged like a missing key, which fails the
// tests that run the bot in other languages.
b.log.Error("i18n: missing message", "id", id, "lang", lang, "fallback", tag.String())
}
return out
}
// fellBack reports whether a text asked for in lang came from a catalog
// of another language.
func (b *Bundle) fellBack(lang string, got language.Tag) bool {
want, _, _ := strings.Cut(strings.ToLower(lang), "-")
have, _ := got.Base()
if want == Default || strings.EqualFold(lang, Pseudo) || have.String() == want {
return false
}
// Only a language with a catalog can fall back; an unknown code is
// resolved to English on purpose.
b.mu.Lock()
defer b.mu.Unlock()
for _, n := range b.names {
if strings.EqualFold(n, lang) || strings.EqualFold(n, want) {
return true
}
}
return false
}
// HTML returns a message for parse_mode HTML. String arguments are escaped,
// so titles and names coming from the web cannot inject markup.
func (b *Bundle) HTML(lang, id string, args Args) string {
+13 -8
View File
@@ -110,12 +110,16 @@ func TestLoadNeedsEnglish(t *testing.T) {
func TestFormatting(t *testing.T) {
b := load(t)
sizes := map[int64]string{
512: "512 B",
2048: "2 KB",
5 << 20: "5.0 MB",
64_900_000: "61.9 MB",
150 << 20: "150 MB",
3 << 29: "1.50 GB",
512: "512 B",
2048: "2 KB",
5 << 20: "5 MB",
50 << 20: "50 MB",
52_377_600: "50 MB", // 49.95 rounds to a whole number
1 << 30: "1 GB",
64_900_000: "61.9 MB",
150 << 20: "150 MB",
3 << 29: "1.5 GB",
1_342_177_280: "1.25 GB",
}
for in, want := range sizes {
if got := b.Size("en", in); got != want {
@@ -280,8 +284,9 @@ func TestNumbersAndUnitsPerLanguage(t *testing.T) {
{"es", b.Sats("es", 10000), "10.000 sats"},
{"nl", b.Sats("nl", 10000), "10.000 sats"},
{"es", b.Sats("es", 1), "1 sat"},
{"es", b.Size("es", 5<<20), "5,0 MB"},
{"nl", b.Size("nl", 3<<29), "1,50 GB"},
{"es", b.Size("es", 5<<20), "5 MB"},
{"es", b.Size("es", 64_900_000), "61,9 MB"},
{"nl", b.Size("nl", 3<<29), "1,5 GB"},
{"es", b.Span("es", 5*time.Minute), "5 minutos"},
{"nl", b.Span("nl", time.Minute), "1 minuut"},
{"nl", b.Span("nl", 3*time.Hour), "3 uur"},