lightningtipbot/internal/telegram/help.go
gohumble 4e812f7897
add errors to handler (#273)
* add errors to handler

* add errors to handlers

* shop fixes (#274)

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>

* better log (#275)

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>

* add errors to map

* more errors

* rename NoWalletError

* fix one panic (#276)

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>

* add invalid type error

* Shop panic attempt 2 (#277)

* less log

* fix shop first view

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>

* make errors private

* add errors to handler

* add errors to handlers

* add errors to map

* more errors

* rename NoWalletError

* add invalid type error

* make errors private

* patch

* return handlers

* add noPrivateChat

* add invalid amount err

Co-authored-by: LightningTipBot <88730856+LightningTipBot@users.noreply.github.com>
Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2022-01-09 21:39:09 +01:00

86 lines
2.7 KiB
Go
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package telegram
import (
"context"
"fmt"
tb "gopkg.in/lightningtipbot/telebot.v2"
)
func (bot TipBot) makeHelpMessage(ctx context.Context, m *tb.Message) string {
fromUser := LoadUser(ctx)
dynamicHelpMessage := ""
// user has no username set
if len(m.Sender.Username) == 0 {
// return fmt.Sprintf(helpMessage, fmt.Sprintf("%s\n\n", helpNoUsernameMessage))
dynamicHelpMessage = dynamicHelpMessage + "\n" + Translate(ctx, "helpNoUsernameMessage")
}
lnaddr, _ := bot.UserGetLightningAddress(fromUser)
if len(lnaddr) > 0 {
dynamicHelpMessage = dynamicHelpMessage + "\n" + fmt.Sprintf(Translate(ctx, "infoYourLightningAddress"), lnaddr)
}
if len(dynamicHelpMessage) > 0 {
dynamicHelpMessage = Translate(ctx, "infoHelpMessage") + dynamicHelpMessage
}
helpMessage := Translate(ctx, "helpMessage")
return fmt.Sprintf(helpMessage, dynamicHelpMessage)
}
func (bot TipBot) helpHandler(ctx context.Context, m *tb.Message) (context.Context, error) {
// check and print all commands
bot.anyTextHandler(ctx, m)
if !m.Private() {
// delete message
bot.tryDeleteMessage(m)
}
bot.trySendMessage(m.Sender, bot.makeHelpMessage(ctx, m), tb.NoPreview)
return ctx, nil
}
func (bot TipBot) basicsHandler(ctx context.Context, m *tb.Message) (context.Context, error) {
// check and print all commands
bot.anyTextHandler(ctx, m)
if !m.Private() {
// delete message
bot.tryDeleteMessage(m)
}
bot.trySendMessage(m.Sender, Translate(ctx, "basicsMessage"), tb.NoPreview)
return ctx, nil
}
func (bot TipBot) makeAdvancedHelpMessage(ctx context.Context, m *tb.Message) string {
fromUser := LoadUser(ctx)
dynamicHelpMessage := " *Info*\n"
// user has no username set
if len(m.Sender.Username) == 0 {
// return fmt.Sprintf(helpMessage, fmt.Sprintf("%s\n\n", helpNoUsernameMessage))
dynamicHelpMessage = dynamicHelpMessage + fmt.Sprintf("%s", Translate(ctx, "helpNoUsernameMessage")) + "\n"
}
// we print the anonymous ln address in the advanced help
lnaddr, err := bot.UserGetAnonLightningAddress(fromUser)
if err == nil {
dynamicHelpMessage = dynamicHelpMessage + fmt.Sprintf("Anonymous lightning address: `%s`\n", lnaddr)
}
lnurl, err := UserGetLNURL(fromUser)
if err == nil {
dynamicHelpMessage = dynamicHelpMessage + fmt.Sprintf("LNURL: `%s`", lnurl)
}
// this is so stupid:
return fmt.Sprintf(
Translate(ctx, "advancedMessage"),
dynamicHelpMessage,
GetUserStr(bot.Telegram.Me),
)
}
func (bot TipBot) advancedHelpHandler(ctx context.Context, m *tb.Message) (context.Context, error) {
// check and print all commands
bot.anyTextHandler(ctx, m)
if !m.Private() {
// delete message
bot.tryDeleteMessage(m)
}
bot.trySendMessage(m.Sender, bot.makeAdvancedHelpMessage(ctx, m), tb.NoPreview)
return ctx, nil
}