Files
LightningTipBot/internal/telegram/lnurlmints.go
T
MichilisandClaude Fable 5.1 3c2ccf8d83 Add the LNURLcash Telegram commands
/note, /notes (list and batch), /redeem and /lnurlmints with confirm
dialogs, group posting with private receipts, claim notifications,
batch export as PDF/JSON/CSV, and LNURLcash notes detected inside the
existing /lnurl, paste and QR-photo flows. Plain withdraw links behave
as before. Two /lnurl log lines no longer print k1.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-13 22:12:27 +00:00

88 lines
2.8 KiB
Go

package telegram
import (
"fmt"
"github.com/LightningTipBot/LightningTipBot/internal"
tiperrors "github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/internal/lnurlcash"
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
lnurlcashgo "github.com/lnurlcash/lnurlcash-go"
tb "gopkg.in/lightningtipbot/telebot.v3"
)
var btnSetMint = (&tb.ReplyMarkup{}).Data("", "lnc_setmint")
func bot_lnurlcash_cfg() *lnurlcash.Config { return &internal.Configuration.LNURLCash }
// lnurlmintsHandler lists the admin mints and lets the user pick a default.
func (bot *TipBot) lnurlmintsHandler(ctx intercept.Context) (intercept.Context, error) {
if !bot.lnurlcashReady(ctx) {
return ctx, nil
}
m := ctx.Message()
user, ok := bot.noteCommandUser(ctx)
if !ok {
return ctx, tiperrors.Create(tiperrors.UserNoWalletError)
}
if !m.Private() {
NewMessage(m, WithDuration(0, bot))
}
text, kb := bot.mintsText(ctx, user.Name)
if _, ok := bot.sendPrivate(m.Sender, text, kb); !ok && !m.Private() {
bot.tryReplyMessage(m, Translate(ctx, "lnurlcashStartPrivateFirstMessage"))
}
return ctx, nil
}
func (bot *TipBot) mintsText(ctx intercept.Context, user string) (string, *tb.ReplyMarkup) {
reg := bot.LNURLCash.Mints()
current, _ := reg.ForUser(user)
menu := &tb.ReplyMarkup{}
var rows []tb.Row
text := TranslateUser(ctx, "lnurlmintsHeader")
for _, mnt := range reg.All() {
state := "🟢"
switch {
case mnt.Disabled:
state = "⛔️"
case !mnt.Healthy:
state = "🔴"
}
mark := ""
if current != nil && current.ID == mnt.ID {
mark = " ⭐️"
}
fee := TranslateUser(ctx, "lnurlmintsNoFee")
if mnt.FeeBaseMsat > 0 || mnt.FeePpm > 0 {
fee = lnurlcashgo.DescribeMintFee(mnt.Fee())
}
text += fmt.Sprintf(TranslateUser(ctx, "lnurlmintsItem"), state, mnt.ID, mark, lnurlcashgo.ServerOf(mnt.PayURL), fee)
if mnt.Usable() {
rows = append(rows, menu.Row(menu.Data(fmt.Sprintf(TranslateUser(ctx, "lnurlmintsSetButton"), mnt.ID), "lnc_setmint", mnt.ID)))
}
}
menu.Inline(rows...)
return text, menu
}
// setMintHandler stores the user's default mint.
func (bot *TipBot) setMintHandler(ctx intercept.Context) (intercept.Context, error) {
if bot.LNURLCash == nil {
return ctx, nil
}
user := LoadUser(ctx)
mnt, ok := bot.LNURLCash.Mints().Get(ctx.Data())
if !ok || !mnt.Usable() {
bot.trySendMessageEditable(ctx.Sender(), TranslateUser(ctx, "noteMintUnavailableMessage"))
return ctx, nil
}
if err := bot.LNURLCash.Store().SetPref(user.Name, mnt.ID); err != nil {
return ctx, err
}
bot.trySendMessageEditable(ctx.Sender(), fmt.Sprintf(TranslateUser(ctx, "lnurlmintsSetMessage"), mnt.ID))
text, kb := bot.mintsText(ctx, user.Name)
bot.tryEditMessage(ctx.Callback().Message, text, kb)
return ctx, nil
}