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
+63
-34
@@ -18,33 +18,16 @@ import (
|
||||
"github.com/noderunners/dlbot/internal/service"
|
||||
)
|
||||
|
||||
// maxLinksPerMessage caps how many links of one message get a card.
|
||||
const maxLinksPerMessage = 3
|
||||
|
||||
func (b *Bot) handleMessage(ctx context.Context, m *telego.Message) {
|
||||
if m.From == nil || m.From.IsBot {
|
||||
return
|
||||
}
|
||||
act, err := b.actorFor(ctx, m.From)
|
||||
if err != nil {
|
||||
b.log.Error("load user", "user_id", m.From.ID, "err", err)
|
||||
return
|
||||
}
|
||||
if act.user.Banned {
|
||||
act, ok := actorFrom(ctx)
|
||||
if !ok || act.user.Banned {
|
||||
return
|
||||
}
|
||||
private := isPrivate(m.Chat.Type)
|
||||
inGroup := groups.IsGroup(m.Chat.Type)
|
||||
var gset *db.GroupSettings
|
||||
if inGroup {
|
||||
if gset, err = b.store.GetGroupSettings(ctx, m.Chat.ID); err != nil {
|
||||
b.log.Error("load group settings", "chat_id", m.Chat.ID, "err", err)
|
||||
return
|
||||
}
|
||||
// A group can pin its own language for everything said in it.
|
||||
if gset.Lang != "" {
|
||||
act.lang = gset.Lang
|
||||
}
|
||||
gset := act.group
|
||||
if inGroup && gset == nil {
|
||||
return
|
||||
}
|
||||
cmd, forUs, isCmd := b.parseCommand(m)
|
||||
if isCmd {
|
||||
@@ -59,6 +42,9 @@ func (b *Bot) handleMessage(ctx context.Context, m *telego.Message) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if private {
|
||||
b.syncMenuButton(ctx, act)
|
||||
}
|
||||
if b.ownerCommand(ctx, m, act, cmd) {
|
||||
return
|
||||
}
|
||||
@@ -83,34 +69,55 @@ func (b *Bot) handleMessage(ctx context.Context, m *telego.Message) {
|
||||
if !private {
|
||||
return
|
||||
}
|
||||
b.syncMenuButton(ctx, act)
|
||||
if len(urls) == 0 {
|
||||
_, _ = b.send(ctx, m.Chat.ID, 0, b.tr.HTML(act.lang, "hint.send_link", nil), nil)
|
||||
return
|
||||
}
|
||||
if len(urls) > maxLinksPerMessage {
|
||||
urls = urls[:maxLinksPerMessage]
|
||||
if max := b.cfg.MultiLinkMax; max > 0 && len(urls) > max {
|
||||
urls = urls[:max]
|
||||
}
|
||||
for _, u := range urls {
|
||||
b.startLink(ctx, linkRequest{
|
||||
chatID: m.Chat.ID, chatType: m.Chat.Type, sourceID: int64(m.MessageID), act: act, url: u,
|
||||
preset: presetFor(act, nil),
|
||||
preset: presetFor(act, nil), checkRecent: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Personal quality settings besides a profile. Stored in users.default_quality.
|
||||
const (
|
||||
// qualityUnset is a user who never chose. Their first link shows the
|
||||
// card once, and their default becomes qualityFit.
|
||||
qualityUnset = ""
|
||||
// qualityAsk shows the card for every link.
|
||||
qualityAsk = "ask"
|
||||
// qualityFit picks the best quality whose estimated size fits the
|
||||
// user's size limit.
|
||||
qualityFit = "fit"
|
||||
)
|
||||
|
||||
// presetFor returns the format to start without showing the card: the
|
||||
// group's default quality in a group, the user's own in a private chat.
|
||||
// An empty result means the card is shown.
|
||||
func presetFor(act actor, gset *db.GroupSettings) media.Profile {
|
||||
q := act.user.Quality
|
||||
if gset != nil {
|
||||
q = gset.Quality
|
||||
}
|
||||
if q == qualityFit {
|
||||
return presetFit
|
||||
}
|
||||
if p, err := media.Parse(q); err == nil {
|
||||
return p
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// presetFit stands for "best that fits my limit" until the link has been
|
||||
// looked up and the real profile can be picked.
|
||||
const presetFit media.Profile = "fit"
|
||||
|
||||
// runCommand dispatches the commands everyone can use.
|
||||
func (b *Bot) runCommand(ctx context.Context, m *telego.Message, act actor, cmd string, gset *db.GroupSettings) {
|
||||
// Commands that carry a link. In a group their message can be removed
|
||||
@@ -177,6 +184,10 @@ func (b *Bot) runCommand(ctx context.Context, m *telego.Message, act actor, cmd
|
||||
b.cmdStatic(ctx, m, act, "static."+cmd)
|
||||
}
|
||||
case "settings":
|
||||
if isPrivate(m.Chat.Type) {
|
||||
b.cmdPersonalSettings(ctx, m.Chat.ID, act)
|
||||
return
|
||||
}
|
||||
b.cmdSettings(ctx, m, act)
|
||||
case "grouplang":
|
||||
b.cmdGroupLang(ctx, m, act)
|
||||
@@ -299,7 +310,13 @@ func (b *Bot) cmdStart(ctx context.Context, m *telego.Message, act actor) {
|
||||
}
|
||||
}
|
||||
}
|
||||
_, _ = b.send(ctx, m.Chat.ID, 0, b.tr.HTML(act.lang, "start.private", i18n.Args{"Name": act.user.FirstName}), nil)
|
||||
// Somebody new picks a language under the welcome. It starts in the
|
||||
// language of their Telegram app, which is usually right.
|
||||
var kb *telego.InlineKeyboardMarkup
|
||||
if act.user.IsNew {
|
||||
kb = b.languageKeyboard(act, func(l string) string { return cbData(cbWelcomeLang, l) }, false)
|
||||
}
|
||||
_, _ = b.send(ctx, m.Chat.ID, 0, b.tr.HTML(act.lang, "start.private", i18n.Args{"Name": act.user.FirstName}), kb)
|
||||
}
|
||||
|
||||
func (b *Bot) cmdHelp(ctx context.Context, m *telego.Message, act actor) {
|
||||
@@ -475,20 +492,14 @@ func (b *Bot) release(ctx context.Context, d *db.Delivery) string {
|
||||
}
|
||||
|
||||
func (b *Bot) handleCallback(ctx context.Context, q *telego.CallbackQuery) {
|
||||
act, err := b.actorFor(ctx, &q.From)
|
||||
if err != nil {
|
||||
b.log.Error("load user", "user_id", q.From.ID, "err", err)
|
||||
act, ok := actorFrom(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if act.user.Banned {
|
||||
b.answer(ctx, q, "", false)
|
||||
return
|
||||
}
|
||||
if q.Message != nil && groups.IsGroup(q.Message.GetChat().Type) {
|
||||
if gset, err := b.store.GetGroupSettings(ctx, q.Message.GetChat().ID); err == nil && gset.Lang != "" {
|
||||
act.lang = gset.Lang
|
||||
}
|
||||
}
|
||||
action, id, arg := parseCallback(q.Data)
|
||||
switch action {
|
||||
case cbGroupSetting:
|
||||
@@ -499,6 +510,8 @@ func (b *Bot) handleCallback(ctx context.Context, q *telego.CallbackQuery) {
|
||||
b.cbSetQuality(ctx, q, act, id)
|
||||
case cbLanguage:
|
||||
b.cbSetLanguage(ctx, q, act, id)
|
||||
case cbWelcomeLang:
|
||||
b.cbWelcomeLanguage(ctx, q, act, id)
|
||||
case cbBroadcast:
|
||||
b.cbBroadcastSend(ctx, q, act, id)
|
||||
case cbDownload:
|
||||
@@ -509,6 +522,22 @@ func (b *Bot) handleCallback(ctx context.Context, q *telego.CallbackQuery) {
|
||||
b.cbPlaylistStart(ctx, q, act, id, arg)
|
||||
case cbResend:
|
||||
b.cbResendFile(ctx, q, act, id)
|
||||
case cbFollowAudio:
|
||||
b.cbFollow(ctx, q, act, id, media.MP3)
|
||||
case cbFollowThumb:
|
||||
b.cbFollow(ctx, q, act, id, media.Thumb)
|
||||
case cbFollowQuality:
|
||||
b.cbOtherQuality(ctx, q, act, id)
|
||||
case cbFollowDelete:
|
||||
b.cbDeleteResult(ctx, q, act, id)
|
||||
case cbRetry:
|
||||
b.cbRetryDownload(ctx, q, act, id, arg)
|
||||
case cbRetryLookup:
|
||||
b.cbRetryLookup(ctx, q, act, id)
|
||||
case cbUpgrade:
|
||||
b.cbShowUpgrade(ctx, q, act)
|
||||
case cbPersonal:
|
||||
b.cbPersonalSetting(ctx, q, act, id, arg)
|
||||
case cbSkipQueue:
|
||||
b.cbSkip(ctx, q, act, id)
|
||||
case cbBuy:
|
||||
|
||||
Reference in New Issue
Block a user