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
+78
-11
@@ -18,20 +18,24 @@ var (
|
||||
privateMenu = []string{
|
||||
"dl", "audio", "thumb", "subs", "info", "queue", "cancel", "history",
|
||||
"account", "buy", "credits", "limits", "redeem", "referral", "donate",
|
||||
"quality", "language", "app", "support", "privacy", "terms", "help",
|
||||
"settings", "quality", "language", "app", "support", "privacy", "terms", "help",
|
||||
}
|
||||
groupMenu = []string{"dl", "audio", "thumb", "info", "queue", "cancel", "groupwallet", "grouppass", "app", "help"}
|
||||
adminMenu = append(append([]string{}, groupMenu...),
|
||||
"settings", "grouplang", "autodetect", "allow", "block", "spending", "groupstats")
|
||||
)
|
||||
|
||||
func (b *Bot) menu(lang string, names []string) []telego.BotCommand {
|
||||
func (b *Bot) menu(lang string, names []string, private bool) []telego.BotCommand {
|
||||
cmds := make([]telego.BotCommand, 0, len(names))
|
||||
for _, name := range names {
|
||||
if name == "app" && !b.cfg.MiniAppEnabled() {
|
||||
continue
|
||||
}
|
||||
cmds = append(cmds, telego.BotCommand{Command: name, Description: b.tr.T(lang, "menu."+name, nil)})
|
||||
key := "menu." + name
|
||||
if name == "settings" && private {
|
||||
key = "menu.settings_private" // /settings in a private chat is personal
|
||||
}
|
||||
cmds = append(cmds, telego.BotCommand{Command: name, Description: b.tr.T(lang, key, nil)})
|
||||
}
|
||||
return cmds
|
||||
}
|
||||
@@ -58,13 +62,15 @@ func (b *Bot) menuLangs() []string {
|
||||
// ignored: the bot works without a menu.
|
||||
func (b *Bot) RegisterCommands(ctx context.Context) {
|
||||
scopes := []struct {
|
||||
scope telego.BotCommandScope
|
||||
names []string
|
||||
scope telego.BotCommandScope
|
||||
names []string
|
||||
private bool
|
||||
}{
|
||||
{&telego.BotCommandScopeAllPrivateChats{Type: telego.ScopeTypeAllPrivateChats}, privateMenu},
|
||||
{&telego.BotCommandScopeAllGroupChats{Type: telego.ScopeTypeAllGroupChats}, groupMenu},
|
||||
{&telego.BotCommandScopeAllChatAdministrators{Type: telego.ScopeTypeAllChatAdministrators}, adminMenu},
|
||||
{&telego.BotCommandScopeAllPrivateChats{Type: telego.ScopeTypeAllPrivateChats}, privateMenu, true},
|
||||
{&telego.BotCommandScopeAllGroupChats{Type: telego.ScopeTypeAllGroupChats}, groupMenu, false},
|
||||
{&telego.BotCommandScopeAllChatAdministrators{Type: telego.ScopeTypeAllChatAdministrators}, adminMenu, false},
|
||||
}
|
||||
b.setDefaultMenuButton(ctx)
|
||||
for i, lang := range b.menuLangs() {
|
||||
code := lang
|
||||
if i == 0 {
|
||||
@@ -72,7 +78,7 @@ func (b *Bot) RegisterCommands(ctx context.Context) {
|
||||
}
|
||||
for _, s := range scopes {
|
||||
err := b.api.SetMyCommands(ctx, &telego.SetMyCommandsParams{
|
||||
Commands: b.menu(lang, s.names), Scope: s.scope, LanguageCode: code,
|
||||
Commands: b.menu(lang, s.names, s.private), Scope: s.scope, LanguageCode: code,
|
||||
})
|
||||
if err != nil {
|
||||
b.log.Warn("setMyCommands failed", "lang", lang, "scope", s.scope.ScopeType(), "err", err)
|
||||
@@ -131,7 +137,7 @@ func (b *Bot) SyncUserMenu(ctx context.Context, userID int64, lang string) {
|
||||
if lang == "" {
|
||||
err = b.api.DeleteMyCommands(ctx, &telego.DeleteMyCommandsParams{Scope: scope})
|
||||
} else {
|
||||
err = b.api.SetMyCommands(ctx, &telego.SetMyCommandsParams{Commands: b.menu(lang, privateMenu), Scope: scope})
|
||||
err = b.api.SetMyCommands(ctx, &telego.SetMyCommandsParams{Commands: b.menu(lang, privateMenu, true), Scope: scope})
|
||||
}
|
||||
if err != nil {
|
||||
b.log.Warn("set the menu of a chat", "chat_id", userID, "err", err)
|
||||
@@ -157,7 +163,7 @@ func (b *Bot) SyncGroupMenu(ctx context.Context, chatID int64, lang string) {
|
||||
if lang == "" {
|
||||
err = b.api.DeleteMyCommands(ctx, &telego.DeleteMyCommandsParams{Scope: s.scope})
|
||||
} else {
|
||||
err = b.api.SetMyCommands(ctx, &telego.SetMyCommandsParams{Commands: b.menu(lang, s.names), Scope: s.scope})
|
||||
err = b.api.SetMyCommands(ctx, &telego.SetMyCommandsParams{Commands: b.menu(lang, s.names, false), Scope: s.scope})
|
||||
}
|
||||
if err != nil {
|
||||
b.log.Warn("set the menu of a group", "chat_id", chatID, "err", err)
|
||||
@@ -186,3 +192,64 @@ func (b *Bot) findLang(code string, userID int64) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// menuButton is the button left of the message field that opens the Mini
|
||||
// App. The command list stays one tap away in the "/" button of the field.
|
||||
func (b *Bot) menuButton(lang string) *telego.MenuButtonWebApp {
|
||||
return &telego.MenuButtonWebApp{
|
||||
Type: telego.ButtonTypeWebApp,
|
||||
Text: b.tr.T(lang, "btn.open_app", nil),
|
||||
WebApp: telego.WebAppInfo{URL: b.cfg.PublicURL + "/app/"},
|
||||
}
|
||||
}
|
||||
|
||||
// setDefaultMenuButton makes the Mini App the menu button of every chat,
|
||||
// labelled in the source language. setChatMenuButton takes no language,
|
||||
// so each private chat gets its own label later, by syncMenuButton.
|
||||
func (b *Bot) setDefaultMenuButton(ctx context.Context) {
|
||||
if !b.cfg.MiniAppEnabled() {
|
||||
return
|
||||
}
|
||||
if err := b.api.SetChatMenuButton(ctx, &telego.SetChatMenuButtonParams{MenuButton: b.menuButton(b.tr.Langs()[0])}); err != nil {
|
||||
b.log.Warn("setChatMenuButton failed", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// syncMenuButton labels the menu button of a private chat in the user's
|
||||
// language. It runs once per user and language: what was set is kept in
|
||||
// memory and in the database, so it survives a restart.
|
||||
func (b *Bot) syncMenuButton(ctx context.Context, act actor) {
|
||||
if !b.cfg.MiniAppEnabled() {
|
||||
return
|
||||
}
|
||||
lang := b.userLang(act.user)
|
||||
b.statusMu.Lock()
|
||||
known := b.menuButtons[act.user.ID] == lang
|
||||
b.statusMu.Unlock()
|
||||
if known {
|
||||
return
|
||||
}
|
||||
key := "menubtn:" + itoa(act.user.ID)
|
||||
if old, _ := b.store.GetKV(ctx, key); old == lang {
|
||||
b.rememberMenuButton(act.user.ID, lang)
|
||||
return
|
||||
}
|
||||
if !b.rate.allow("menubtn:"+itoa(act.user.ID), 3, time.Minute) {
|
||||
return
|
||||
}
|
||||
err := b.api.SetChatMenuButton(ctx, &telego.SetChatMenuButtonParams{ChatID: act.user.ID, MenuButton: b.menuButton(lang)})
|
||||
if err != nil {
|
||||
b.log.Warn("setChatMenuButton failed", "chat_id", act.user.ID, "err", err)
|
||||
return
|
||||
}
|
||||
if err := b.store.SetKV(ctx, key, lang); err != nil {
|
||||
b.log.Warn("remember menu button", "chat_id", act.user.ID, "err", err)
|
||||
}
|
||||
b.rememberMenuButton(act.user.ID, lang)
|
||||
}
|
||||
|
||||
func (b *Bot) rememberMenuButton(userID int64, lang string) {
|
||||
b.statusMu.Lock()
|
||||
b.menuButtons[userID] = lang
|
||||
b.statusMu.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user