mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-17 13:07:16 +02:00
* 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>
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package telegram
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/LightningTipBot/LightningTipBot/internal"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/skip2/go-qrcode"
|
|
tb "gopkg.in/lightningtipbot/telebot.v2"
|
|
)
|
|
|
|
func (bot *TipBot) lndhubHandler(ctx context.Context, m *tb.Message) (context.Context, error) {
|
|
if internal.Configuration.Lnbits.LnbitsPublicUrl == "" {
|
|
bot.trySendMessage(m.Sender, Translate(ctx, "couldNotLinkMessage"))
|
|
return ctx, fmt.Errorf("invalid configuration")
|
|
}
|
|
// check and print all commands
|
|
bot.anyTextHandler(ctx, m)
|
|
// reply only in private message
|
|
if m.Chat.Type != tb.ChatPrivate {
|
|
// delete message
|
|
bot.tryDeleteMessage(m)
|
|
}
|
|
// first check whether the user is initialized
|
|
fromUser := LoadUser(ctx)
|
|
bot.trySendMessage(m.Sender, Translate(ctx, "walletConnectMessage"))
|
|
|
|
// do not respond to banned users
|
|
if bot.UserIsBanned(fromUser) {
|
|
log.Warnln("[lndhubHandler] user is banned. not responding.")
|
|
return ctx, fmt.Errorf("user is banned")
|
|
}
|
|
|
|
lndhubUrl := fmt.Sprintf("lndhub://admin:%s@%slndhub/ext/", fromUser.Wallet.Adminkey, internal.Configuration.Lnbits.LnbitsPublicUrl)
|
|
|
|
// create qr code
|
|
qr, err := qrcode.Encode(lndhubUrl, qrcode.Medium, 256)
|
|
if err != nil {
|
|
errmsg := fmt.Sprintf("[/invoice] Failed to create QR code for invoice: %s", err.Error())
|
|
log.Errorln(errmsg)
|
|
return ctx, err
|
|
}
|
|
|
|
// send the link to the user
|
|
linkmsg := bot.trySendMessage(m.Sender, &tb.Photo{File: tb.File{FileReader: bytes.NewReader(qr)}, Caption: fmt.Sprintf("`%s`", lndhubUrl)})
|
|
|
|
go func() {
|
|
time.Sleep(time.Second * 60)
|
|
bot.tryDeleteMessage(linkmsg)
|
|
bot.trySendMessage(m.Sender, Translate(ctx, "linkHiddenMessage"))
|
|
}()
|
|
// auto delete the message
|
|
// NewMessage(linkmsg, WithDuration(time.Second*time.Duration(internal.Configuration.Telegram.MessageDisposeDuration), bot))
|
|
return ctx, nil
|
|
}
|