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:
co-authored by
Claude Opus 5.5
parent
3c153af97f
commit
6843053582
+27
-53
@@ -21,6 +21,7 @@ const (
|
||||
cbGroupBuy = "gb" // gb:<product>:<chat id>[:<amount>]
|
||||
cbQuality = "ql" // ql:<profile or "ask">
|
||||
cbLanguage = "lg" // lg:<language or "auto">
|
||||
cbWelcomeLang = "lw" // lw:<language or "auto">, under the first welcome
|
||||
)
|
||||
|
||||
// handleMyChatMember records the groups the bot is in. Telegram sends this
|
||||
@@ -525,35 +526,14 @@ func (b *Bot) cbGroupBuyProduct(ctx context.Context, q *telego.CallbackQuery, ac
|
||||
// --- personal preferences ---------------------------------------------------
|
||||
|
||||
func (b *Bot) cmdQuality(ctx context.Context, m *telego.Message, act actor) {
|
||||
lang := act.lang
|
||||
opt := func(value string) telego.InlineKeyboardButton {
|
||||
label := b.qualityName(lang, value)
|
||||
if value == act.user.Quality {
|
||||
label = "✓ " + label
|
||||
}
|
||||
data := value
|
||||
if data == "" {
|
||||
data = "ask"
|
||||
}
|
||||
return button(label, cbData(cbQuality, data))
|
||||
}
|
||||
kb := keyboard(
|
||||
[]telego.InlineKeyboardButton{opt("")},
|
||||
[]telego.InlineKeyboardButton{opt(string(media.Best)), opt(string(media.P1080)), opt(string(media.P720)), opt(string(media.P480))},
|
||||
[]telego.InlineKeyboardButton{opt(string(media.MP3))},
|
||||
)
|
||||
_, _ = b.send(ctx, m.Chat.ID, int64(m.MessageID), b.tr.HTML(lang, "quality.pick", nil), kb)
|
||||
kb := b.qualityKeyboard(act, func(v string) string { return cbData(cbQuality, v) }, false)
|
||||
_, _ = b.send(ctx, m.Chat.ID, int64(m.MessageID), b.tr.HTML(act.lang, "quality.pick", nil), kb)
|
||||
}
|
||||
|
||||
func (b *Bot) cbSetQuality(ctx context.Context, q *telego.CallbackQuery, act actor, value string) {
|
||||
if value == "ask" {
|
||||
value = ""
|
||||
}
|
||||
if value != "" {
|
||||
if p, err := media.Parse(value); err != nil || (p.Kind() != media.KindVideo && p.Kind() != media.KindAudio) {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "notice.expired", nil), false)
|
||||
return
|
||||
}
|
||||
if !validUserQuality(value) {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "notice.expired", nil), false)
|
||||
return
|
||||
}
|
||||
if err := b.store.SetUserQuality(ctx, act.user.ID, value); err != nil {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "error.internal", nil), true)
|
||||
@@ -562,42 +542,21 @@ func (b *Bot) cbSetQuality(ctx context.Context, q *telego.CallbackQuery, act act
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "notice.saved", nil), false)
|
||||
if q.Message != nil {
|
||||
_ = b.edit(ctx, q.Message.GetChat().ID, int64(q.Message.GetMessageID()), false,
|
||||
b.tr.HTML(act.lang, "quality.set", i18n.Args{"Quality": b.qualityName(act.lang, value)}), nil)
|
||||
b.tr.HTML(act.lang, "quality.set", i18n.Args{"Quality": b.userQualityName(act.lang, value)}), nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Bot) cmdLanguage(ctx context.Context, m *telego.Message, act actor) {
|
||||
var row []telego.InlineKeyboardButton
|
||||
var rows [][]telego.InlineKeyboardButton
|
||||
for _, l := range b.visibleLangs(act.user.ID) {
|
||||
// Each language is listed under its own name.
|
||||
row = append(row, button(b.tr.T(l, "language.name", nil), cbData(cbLanguage, l)))
|
||||
if len(row) == 3 {
|
||||
rows = append(rows, row)
|
||||
row = nil
|
||||
}
|
||||
}
|
||||
rows = append(rows, row, []telego.InlineKeyboardButton{button(b.tr.T(act.lang, "language.auto", nil), cbData(cbLanguage, "auto"))})
|
||||
_, _ = b.send(ctx, m.Chat.ID, int64(m.MessageID), b.tr.HTML(act.lang, "language.pick", nil), keyboard(rows...))
|
||||
kb := b.languageKeyboard(act, func(l string) string { return cbData(cbLanguage, l) }, false)
|
||||
_, _ = b.send(ctx, m.Chat.ID, int64(m.MessageID), b.tr.HTML(act.lang, "language.pick", nil), kb)
|
||||
}
|
||||
|
||||
func (b *Bot) cbSetLanguage(ctx context.Context, q *telego.CallbackQuery, act actor, value string) {
|
||||
lang := ""
|
||||
if value != "auto" {
|
||||
if lang = b.findLang(value, act.user.ID); lang == "" {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "notice.expired", nil), false)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := b.store.SetUserLang(ctx, act.user.ID, lang); err != nil {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "error.internal", nil), true)
|
||||
shown, ok := b.applyLanguage(ctx, act, value)
|
||||
if !ok {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "notice.expired", nil), false)
|
||||
return
|
||||
}
|
||||
shown := lang
|
||||
if shown == "" {
|
||||
shown = b.tr.Resolve(act.user.Lang)
|
||||
}
|
||||
b.SyncUserMenu(ctx, act.user.ID, lang)
|
||||
b.answer(ctx, q, b.tr.T(shown, "notice.saved", nil), false)
|
||||
if q.Message != nil {
|
||||
_ = b.edit(ctx, q.Message.GetChat().ID, int64(q.Message.GetMessageID()), false,
|
||||
@@ -605,6 +564,21 @@ func (b *Bot) cbSetLanguage(ctx context.Context, q *telego.CallbackQuery, act ac
|
||||
}
|
||||
}
|
||||
|
||||
// cbWelcomeLanguage is a language picked under the first welcome: the
|
||||
// welcome is written again in that language.
|
||||
func (b *Bot) cbWelcomeLanguage(ctx context.Context, q *telego.CallbackQuery, act actor, value string) {
|
||||
shown, ok := b.applyLanguage(ctx, act, value)
|
||||
if !ok {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "notice.expired", nil), false)
|
||||
return
|
||||
}
|
||||
b.answer(ctx, q, b.tr.T(shown, "notice.saved", nil), false)
|
||||
if q.Message != nil {
|
||||
_ = b.edit(ctx, q.Message.GetChat().ID, int64(q.Message.GetMessageID()), false,
|
||||
b.tr.HTML(shown, "start.private", i18n.Args{"Name": act.user.FirstName}), nil)
|
||||
}
|
||||
}
|
||||
|
||||
// cmdStatic answers /privacy, /terms and /support from the catalog.
|
||||
func (b *Bot) cmdStatic(ctx context.Context, m *telego.Message, act actor, key string) {
|
||||
contact := b.cfg.Support
|
||||
|
||||
Reference in New Issue
Block a user