Phase 2: command screens
- /help: a short introduction with the user's default format, how to be asked every time and the limits on one line, plus buttons Commands, Account, Groups, Open app and Upgrade that switch the same message to a section. Group commands are hidden in private chats; "Add me to a group" takes their place. - /quality: Ask every time, Best that fits my limit, Best, 1080p, 720p, 480p and Audio only, with the active one checked. Free users see which qualities may go over their limit. - /history: pages of five compact buttons (site, title, format, when), a view per download with Send again, Thumbnail, Remove from history, and Clear history with a confirmation. Thumbnails are grouped under their video. Migration 00007 stores extractor, title, uploader and profile on deliveries and adds a hidden flag. - docs/SCREENS.md shows every screen in en, es and nl, generated by the language test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6843053582
commit
123cede7f3
@@ -0,0 +1,118 @@
|
||||
package bot
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mymmrac/telego"
|
||||
|
||||
"github.com/noderunners/dlbot/internal/groups"
|
||||
"github.com/noderunners/dlbot/internal/i18n"
|
||||
"github.com/noderunners/dlbot/internal/service"
|
||||
)
|
||||
|
||||
// /help is a short introduction with buttons that turn the same message
|
||||
// into one section at a time: commands, account, groups.
|
||||
|
||||
// cbHelp switches the help message to a section: hp:<section>.
|
||||
const cbHelp = "hp"
|
||||
|
||||
// Help sections.
|
||||
const (
|
||||
helpHome = "home"
|
||||
helpCommands = "cmds"
|
||||
helpAccount = "acct"
|
||||
helpGroups = "groups"
|
||||
)
|
||||
|
||||
// helpView renders one section of the help for a chat.
|
||||
func (b *Bot) helpView(ctx context.Context, act actor, chat int64, chatType, section string) (string, *telego.InlineKeyboardMarkup, error) {
|
||||
lang := act.lang
|
||||
private := isPrivate(chatType)
|
||||
back := keyboard([]telego.InlineKeyboardButton{button(b.tr.T(lang, "btn.back", nil), cbData(cbHelp, helpHome))})
|
||||
switch section {
|
||||
case helpCommands:
|
||||
if private {
|
||||
return b.tr.HTML(lang, "help.commands", nil), back, nil
|
||||
}
|
||||
return b.tr.HTML(lang, "help.commands_group", nil), back, nil
|
||||
case helpAccount:
|
||||
return b.tr.HTML(lang, "help.account", nil), back, nil
|
||||
case helpGroups:
|
||||
if private {
|
||||
// Group commands mean nothing here: how to get the bot into a
|
||||
// group instead.
|
||||
return b.tr.HTML(lang, "help.groups_private", nil), keyboard(
|
||||
[]telego.InlineKeyboardButton{b.addToGroupButton(lang)},
|
||||
back.InlineKeyboard[0],
|
||||
), nil
|
||||
}
|
||||
return b.tr.HTML(lang, "help.groups_group", nil), back, nil
|
||||
}
|
||||
|
||||
dec, err := b.svc.Entitlement(ctx, service.Who{UserID: act.user.ID, ChatID: chat, ChatType: chatType}, false)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
l := dec.Limits
|
||||
var format string
|
||||
if private {
|
||||
format = b.tr.HTML(lang, "help.format", i18n.Args{"Quality": b.userQualityName(lang, act.user.Quality)})
|
||||
} else {
|
||||
q := ""
|
||||
if act.group != nil {
|
||||
q = act.group.Quality
|
||||
}
|
||||
format = b.tr.HTML(lang, "help.format_group", i18n.Args{"Quality": b.qualityName(lang, q)})
|
||||
}
|
||||
text := b.tr.HTML(lang, "help.intro", nil) + "\n\n" + format + "\n\n" +
|
||||
b.tr.HTML(lang, "help.limits", i18n.Args{
|
||||
"MaxSize": b.capSize(lang, min64(l.MaxSize, b.cfg.MaxUploadBytes())),
|
||||
"MaxDuration": b.tr.Span(lang, secondsDuration(l.MaxDuration)),
|
||||
"Daily": b.capNumber(lang, int64(l.DailyDownloads)),
|
||||
})
|
||||
rows := [][]telego.InlineKeyboardButton{
|
||||
{
|
||||
button(b.tr.T(lang, "btn.help_commands", nil), cbData(cbHelp, helpCommands)),
|
||||
button(b.tr.T(lang, "btn.help_account", nil), cbData(cbHelp, helpAccount)),
|
||||
},
|
||||
{button(b.tr.T(lang, "btn.help_groups", nil), cbData(cbHelp, helpGroups))},
|
||||
}
|
||||
var last []telego.InlineKeyboardButton
|
||||
if btn, ok := b.appButton(lang, private, ""); ok {
|
||||
last = append(last, btn)
|
||||
}
|
||||
if !dec.Source.Paid() {
|
||||
last = append(last, b.upgradeButton(lang, private)...)
|
||||
}
|
||||
rows = append(rows, last)
|
||||
return text, keyboard(rows...), nil
|
||||
}
|
||||
|
||||
func (b *Bot) cmdHelp(ctx context.Context, m *telego.Message, act actor) {
|
||||
text, kb, err := b.helpView(ctx, act, m.Chat.ID, m.Chat.Type, helpHome)
|
||||
if err != nil {
|
||||
b.internalError(ctx, m.Chat.ID, act, err)
|
||||
return
|
||||
}
|
||||
_, _ = b.send(ctx, m.Chat.ID, int64(m.MessageID), text, kb)
|
||||
}
|
||||
|
||||
// cbHelpSection turns the help message into another section.
|
||||
func (b *Bot) cbHelpSection(ctx context.Context, q *telego.CallbackQuery, act actor, section string) {
|
||||
if q.Message == nil {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "notice.expired", nil), false)
|
||||
return
|
||||
}
|
||||
chat := q.Message.GetChat()
|
||||
if groups.IsGroup(chat.Type) && act.group == nil {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "notice.expired", nil), false)
|
||||
return
|
||||
}
|
||||
text, kb, err := b.helpView(ctx, act, chat.ID, chat.Type, section)
|
||||
if err != nil {
|
||||
b.answer(ctx, q, b.tr.T(act.lang, "error.internal", nil), true)
|
||||
return
|
||||
}
|
||||
b.answer(ctx, q, "", false)
|
||||
_ = b.edit(ctx, chat.ID, int64(q.Message.GetMessageID()), false, text, kb)
|
||||
}
|
||||
Reference in New Issue
Block a user