Files
MichilisandClaude Opus 5.5 6843053582 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>
2026-11-18 20:08:58 +00:00

120 lines
3.5 KiB
Go

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. 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)
switch {
case bytes < unit:
return p.Sprintf("%d B", bytes)
case bytes < unit*unit:
return p.Sprintf("%.0f KB", float64(bytes)/unit)
case bytes < unit*unit*unit:
v := float64(bytes) / (unit * unit)
if v >= 100 {
return p.Sprintf("%.0f MB", v)
}
return p.Sprintf("%."+strconv.Itoa(decimals(v, 1))+"f MB", v)
default:
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 {
seconds = 0
}
h, m, s := seconds/3600, seconds/60%60, seconds%60
if h > 0 {
return fmt.Sprintf("%d:%02d:%02d", h, m, s)
}
return fmt.Sprintf("%d:%02d", m, s)
}
// Span formats a length of time in words, such as "30 seconds", "5 minutes"
// or "2 hours", using the plural rules of the language.
func (b *Bundle) Span(lang string, d time.Duration) string {
switch {
case d < time.Minute:
n := int(d.Round(time.Second) / time.Second)
if n < 1 {
n = 1
}
return b.T(lang, "unit.seconds", Args{"Count": n})
case d < time.Hour:
return b.T(lang, "unit.minutes", Args{"Count": int(d.Round(time.Minute) / time.Minute)})
default:
return b.T(lang, "unit.hours", Args{"Count": int(d.Round(time.Hour) / time.Hour)})
}
}
// Percent formats a ratio in the 0 to 1 range as a whole percentage.
func (b *Bundle) Percent(lang string, ratio float64) string {
if ratio < 0 {
ratio = 0
}
if ratio > 1 {
ratio = 1
}
return b.printer(lang).Sprintf("%d%%", int(ratio*100+0.5))
}
// Number formats an integer with the digit grouping of the locale, such as
// "9,000" in English and "9.000" in Spanish and Dutch.
func (b *Bundle) Number(lang string, n int64) string {
return b.printer(lang).Sprintf("%d", n)
}
// Sats formats an amount of sats with its unit, for example "1,000 sats".
func (b *Bundle) Sats(lang string, n int64) string {
return b.T(lang, "unit.sats", Args{"Count": n, "N": b.Number(lang, n)})
}
// DateTime formats a point in time the way the language writes dates,
// from format.datetime and format.months in its catalog. It is always in
// UTC and says so: the bot does not know the reader's time zone.
func (b *Bundle) DateTime(lang string, t time.Time) string {
return b.T(lang, "format.datetime", b.dateArgs(lang, t))
}
// Date formats a day, from format.date and format.months.
func (b *Bundle) Date(lang string, t time.Time) string {
return b.T(lang, "format.date", b.dateArgs(lang, t))
}
func (b *Bundle) dateArgs(lang string, t time.Time) Args {
t = t.UTC()
month := strconv.Itoa(int(t.Month()))
if names := strings.Split(b.T(lang, "format.months", nil), ","); len(names) == 12 {
month = strings.TrimSpace(names[t.Month()-1])
}
return Args{
"Day": t.Day(), "Month": month, "MonthNumber": fmt.Sprintf("%02d", int(t.Month())), "Year": t.Year(),
"Hour": fmt.Sprintf("%02d", t.Hour()), "Minute": fmt.Sprintf("%02d", t.Minute()),
}
}