diff --git a/botfather-setcommands.txt b/botfather-setcommands.txt index 1a50f82..5e61ae0 100644 --- a/botfather-setcommands.txt +++ b/botfather-setcommands.txt @@ -7,11 +7,11 @@ help - Read the help. balance - Check balance. +transactions - List transactions tip - Reply to a message to tip: /tip 50 send - Send funds to a user: /send 100 @LightningTipBot invoice - Receive with Lightning: /invoice 1000 pay - Pay with Lightning: /pay lnbc10n1ps... donate - Donate: /donate 1000 faucet - Create a faucet: /faucet 2100 21 -tipjar - Create a tipjar: /tipjar 100 10 advanced - Advanced help \ No newline at end of file diff --git a/internal/lnbits/lnbits.go b/internal/lnbits/lnbits.go index 8c4edde..c446b9a 100644 --- a/internal/lnbits/lnbits.go +++ b/internal/lnbits/lnbits.go @@ -1,8 +1,9 @@ package lnbits import ( - "github.com/imroc/req" "time" + + "github.com/imroc/req" ) // NewClient returns a new lnbits api client. Pass your API key and url here. @@ -130,6 +131,30 @@ func (c Client) Info(w Wallet) (wtx Wallet, err error) { return } +// Info returns wallet payments +func (c Client) Payments(w Wallet) (wtx Payments, err error) { + // custom header with invoice key + invoiceHeader := req.Header{ + "Content-Type": "application/json", + "Accept": "application/json", + "X-Api-Key": w.Inkey, + } + resp, err := req.Get(c.url+"/api/v1/payments?limit=60", invoiceHeader, nil) + if err != nil { + return + } + + if resp.Response().StatusCode >= 300 { + var reqErr Error + resp.ToJSON(&reqErr) + err = reqErr + return + } + + err = resp.ToJSON(&wtx) + return +} + // Wallets returns all wallets belonging to an user func (c Client) Wallets(w User) (wtx []Wallet, err error) { resp, err := req.Get(c.url+"/usermanager/api/v1/wallets/"+w.ID, c.header, nil) diff --git a/internal/lnbits/types.go b/internal/lnbits/types.go index 7895952..6c5dd4a 100644 --- a/internal/lnbits/types.go +++ b/internal/lnbits/types.go @@ -105,6 +105,23 @@ type Wallet struct { Name string `json:"name"` User string `json:"user"` } + +type Payments []struct { + CheckingID string `json:"checking_id"` + Pending bool `json:"pending"` + Amount int `json:"amount"` + Fee int `json:"fee"` + Memo string `json:"memo"` + Time int `json:"time"` + Bolt11 string `json:"bolt11"` + Preimage string `json:"preimage"` + PaymentHash string `json:"payment_hash"` + Extra struct{} `json:"extra"` + WalletID string `json:"wallet_id"` + Webhook interface{} `json:"webhook"` + WebhookStatus interface{} `json:"webhook_status"` +} + type BitInvoice struct { PaymentHash string `json:"payment_hash"` PaymentRequest string `json:"payment_request"` diff --git a/internal/telegram/faucet.go b/internal/telegram/faucet.go index 8610313..30a0551 100644 --- a/internal/telegram/faucet.go +++ b/internal/telegram/faucet.go @@ -304,7 +304,7 @@ func (bot *TipBot) acceptInlineFaucetHandler(ctx intercept.Context) (intercept.C } // todo: user new get username function to get userStrings - transactionMemo := fmt.Sprintf("Faucet from %s to %s (%d sat).", fromUserStr, toUserStr, inlineFaucet.PerUserAmount) + transactionMemo := fmt.Sprintf("🚰 Faucet from %s to %s.", fromUserStr, toUserStr) t := NewTransaction(bot, from, to, inlineFaucet.PerUserAmount, TransactionType("faucet")) t.Memo = transactionMemo diff --git a/internal/telegram/groups.go b/internal/telegram/groups.go index 4bed39c..7261934 100644 --- a/internal/telegram/groups.go +++ b/internal/telegram/groups.go @@ -84,7 +84,7 @@ var ( ) var ( - groupInvoiceMemo = "Ticket for group %s" + groupInvoiceMemo = "🎟 Ticket for group %s" ) // groupHandler is called if the /group command is invoked. It then decides with other @@ -346,7 +346,7 @@ func (bot *TipBot) groupGetInviteLinkHandler(event Event) { lnbits.InvoiceParams{ Out: false, Amount: commissionSat, - Memo: "Ticket commission for group " + ticketEvent.Group.Title, + Memo: "🎟 Ticket commission for group " + ticketEvent.Group.Title, Webhook: internal.Configuration.Lnbits.WebhookServer}, bot.Client) if err != nil { diff --git a/internal/telegram/handler.go b/internal/telegram/handler.go index d2b26eb..9a0a3e2 100644 --- a/internal/telegram/handler.go +++ b/internal/telegram/handler.go @@ -120,6 +120,7 @@ func (bot TipBot) getHandler() []InterceptionWrapper { Handler: bot.payHandler, Interceptor: &Interceptor{ Before: []intercept.Func{ + bot.requirePrivateChatInterceptor, bot.localizerInterceptor, bot.logMessageInterceptor, bot.requireUserInterceptor, @@ -136,6 +137,7 @@ func (bot TipBot) getHandler() []InterceptionWrapper { Interceptor: &Interceptor{ Before: []intercept.Func{ + bot.requirePrivateChatInterceptor, bot.localizerInterceptor, bot.logMessageInterceptor, bot.requireUserInterceptor, @@ -183,6 +185,7 @@ func (bot TipBot) getHandler() []InterceptionWrapper { Interceptor: &Interceptor{ Before: []intercept.Func{ + bot.requirePrivateChatInterceptor, bot.localizerInterceptor, bot.logMessageInterceptor, bot.requireUserInterceptor, @@ -227,11 +230,51 @@ func (bot TipBot) getHandler() []InterceptionWrapper { }, }, }, + { + Endpoints: []interface{}{"/transactions"}, + Handler: bot.transactionsHandler, + Interceptor: &Interceptor{ + Before: []intercept.Func{ + bot.requirePrivateChatInterceptor, + bot.localizerInterceptor, + bot.logMessageInterceptor, + bot.requireUserInterceptor, + }}, + }, + { + Endpoints: []interface{}{&btnLeftTransactionsButton}, + Handler: bot.transactionsScrollLeftHandler, + Interceptor: &Interceptor{ + + Before: []intercept.Func{ + bot.localizerInterceptor, + bot.loadUserInterceptor, + bot.lockInterceptor, + }, + OnDefer: []intercept.Func{ + bot.unlockInterceptor, + }, + }, + }, + { + Endpoints: []interface{}{&btnRightTransactionsButton}, + Handler: bot.transactionsScrollRightHandler, + Interceptor: &Interceptor{ + + Before: []intercept.Func{ + bot.localizerInterceptor, + bot.loadUserInterceptor, + bot.lockInterceptor, + }, + OnDefer: []intercept.Func{ + bot.unlockInterceptor, + }, + }, + }, { Endpoints: []interface{}{"/faucet", "/zapfhahn", "/kraan", "/grifo"}, Handler: bot.faucetHandler, Interceptor: &Interceptor{ - Before: []intercept.Func{ bot.localizerInterceptor, bot.logMessageInterceptor, diff --git a/internal/telegram/inline_receive.go b/internal/telegram/inline_receive.go index 7b65e5d..1bad4cb 100644 --- a/internal/telegram/inline_receive.go +++ b/internal/telegram/inline_receive.go @@ -251,7 +251,7 @@ func (bot *TipBot) sendInlineReceiveHandler(ctx intercept.Context) (intercept.Co inlineReceive.Inactivate(inlineReceive, bot.Bunt) // todo: user new get username function to get userStrings - transactionMemo := fmt.Sprintf("InlineReceive from %s to %s (%d sat).", fromUserStr, toUserStr, inlineReceive.Amount) + transactionMemo := fmt.Sprintf("💸 Receive from %s to %s.", fromUserStr, toUserStr) t := NewTransaction(bot, from, to, inlineReceive.Amount, TransactionType("inline receive")) t.Memo = transactionMemo success, err := t.Send() diff --git a/internal/telegram/inline_send.go b/internal/telegram/inline_send.go index eb28a98..90289f1 100644 --- a/internal/telegram/inline_send.go +++ b/internal/telegram/inline_send.go @@ -224,7 +224,7 @@ func (bot *TipBot) acceptInlineSendHandler(ctx intercept.Context) (intercept.Con inlineSend.Inactivate(inlineSend, bot.Bunt) // todo: user new get username function to get userStrings - transactionMemo := fmt.Sprintf("InlineSend from %s to %s (%d sat).", fromUserStr, toUserStr, amount) + transactionMemo := fmt.Sprintf("💸 Send from %s to %s.", fromUserStr, toUserStr) t := NewTransaction(bot, fromUser, to, amount, TransactionType("inline send")) t.Memo = transactionMemo success, err := t.Send() diff --git a/internal/telegram/send.go b/internal/telegram/send.go index 63bf3e4..3f34394 100644 --- a/internal/telegram/send.go +++ b/internal/telegram/send.go @@ -4,9 +4,10 @@ import ( "context" "encoding/json" "fmt" - "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept" "strings" + "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept" + "github.com/LightningTipBot/LightningTipBot/internal/errors" "github.com/LightningTipBot/LightningTipBot/internal/runtime/mutex" @@ -306,7 +307,7 @@ func (bot *TipBot) confirmSendHandler(ctx intercept.Context) (intercept.Context, toUserStr := GetUserStr(to.Telegram) fromUserStr := GetUserStr(from.Telegram) - transactionMemo := fmt.Sprintf("Send from %s to %s (%d sat).", fromUserStr, toUserStr, amount) + transactionMemo := fmt.Sprintf("💸 Send from %s to %s.", fromUserStr, toUserStr) t := NewTransaction(bot, from, to, amount, TransactionType("send")) t.Memo = transactionMemo diff --git a/internal/telegram/shop.go b/internal/telegram/shop.go index 115e199..a65279b 100644 --- a/internal/telegram/shop.go +++ b/internal/telegram/shop.go @@ -858,7 +858,7 @@ func (bot *TipBot) shopConfirmBuyHandler(ctx intercept.Context) (intercept.Conte log.Errorf("[shopConfirmBuyHandler] item has no price.") return ctx, errors.Create(errors.InvalidAmountError) } - transactionMemo := fmt.Sprintf("Buy item %s (%d sat).", toUserStr, amount) + transactionMemo := fmt.Sprintf("🛍 Shop from %s.", toUserStr) t := NewTransaction(bot, from, to, amount, TransactionType("shop")) t.Memo = transactionMemo diff --git a/internal/telegram/tip.go b/internal/telegram/tip.go index c79e9c8..f65c488 100644 --- a/internal/telegram/tip.go +++ b/internal/telegram/tip.go @@ -3,11 +3,12 @@ package telegram import ( "context" "fmt" - "github.com/LightningTipBot/LightningTipBot/internal/errors" - "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept" "strings" "time" + "github.com/LightningTipBot/LightningTipBot/internal/errors" + "github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept" + "github.com/LightningTipBot/LightningTipBot/internal" "github.com/LightningTipBot/LightningTipBot/internal/str" @@ -106,7 +107,7 @@ func (bot *TipBot) tipHandler(ctx intercept.Context) (intercept.Context, error) } // todo: user new get username function to get userStrings - transactionMemo := fmt.Sprintf("Tip from %s to %s (%d sat).", fromUserStr, toUserStr, amount) + transactionMemo := fmt.Sprintf("🏅 Tip from %s to %s.", fromUserStr, toUserStr) t := NewTransaction(bot, from, to, amount, TransactionType("tip"), TransactionChat(m.Chat)) t.Memo = transactionMemo success, err := t.Send() diff --git a/internal/telegram/tipjar.go b/internal/telegram/tipjar.go index a9b13dd..951c7d6 100644 --- a/internal/telegram/tipjar.go +++ b/internal/telegram/tipjar.go @@ -279,7 +279,7 @@ func (bot *TipBot) acceptInlineTipjarHandler(ctx intercept.Context) (intercept.C fromUserStr := GetUserStr(from.Telegram) // todo: user new get username function to get userStrings - transactionMemo := fmt.Sprintf("Tipjar from %s to %s (%d sat).", fromUserStr, toUserStr, inlineTipjar.PerUserAmount) + transactionMemo := fmt.Sprintf("🍯 Tipjar from %s to %s.", fromUserStr, toUserStr) t := NewTransaction(bot, from, to, inlineTipjar.PerUserAmount, TransactionType("tipjar")) t.Memo = transactionMemo diff --git a/translations/de.toml b/translations/de.toml index 00582c0..b81ce38 100644 --- a/translations/de.toml +++ b/translations/de.toml @@ -118,11 +118,13 @@ advancedMessage = """%s 📖 Du kannst Inline Befehle in jedem Chat verwenden, sogar in privaten Nachrichten. Warte eine Sekunde, nachdem du den Befehl eingegeben hast und *klicke* auf das Ergebnis, statt Enter einzugeben. ⚙️ *Fortgeschrittene Befehle* +*/transactions* 📊 Liste der Transaktionen */link* 🔗 Verbinde dein Wallet mit [BlueWallet](https://bluewallet.io/) oder [Zeus](https://zeusln.app/) -*/lnurl* ⚡️ Lnurl empfangen oder senden: `/lnurl` or `/lnurl ` +*/lnurl* ⚡️ Lnurl empfangen oder senden: `/lnurl` oder `/lnurl ` */faucet* 🚰 Erzeuge einen Zapfhahn: `/faucet ` */tipjar* 🍯 Erzeuge eine Spendendose: `/tipjar ` -*/group* 🎟 Tickets für Gruppenchats: `/group add []`""" +*/group* 🎟 Tickets für Gruppenchats: `/group add []` +*/shop* 🛍 Durchsuche shops: `/shop` oder `/shop `""" # GENERIC enterAmountRangeMessage = """⌨️ Gebe einen Betrag zwischen %d und %d sat ein.""" diff --git a/translations/en.toml b/translations/en.toml index d75d956..1d517fb 100644 --- a/translations/en.toml +++ b/translations/en.toml @@ -121,11 +121,13 @@ advancedMessage = """%s 📖 You can use inline commands in every chat, even in private conversations. Wait a second after entering an inline command and *click* the result, don't press enter. ⚙️ *Advanced commands* +*/transactions* 📊 List transactions */link* 🔗 Link your wallet to [BlueWallet](https://bluewallet.io/) or [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl receive or pay: `/lnurl` or `/lnurl ` */faucet* 🚰 Create a faucet: `/faucet ` */tipjar* 🍯 Create a tipjar: `/tipjar ` -*/group* 🎟 Create group tickets: `/group add []`""" +*/group* 🎟 Create group tickets: `/group add []` +*/shop* 🛍 Browse shops: `/shop` or `/shop `""" # GENERIC enterAmountRangeMessage = """💯 Enter an amount between %d and %d sat.""" diff --git a/translations/es.toml b/translations/es.toml index 4c901d6..f642b44 100644 --- a/translations/es.toml +++ b/translations/es.toml @@ -117,11 +117,13 @@ advancedMessage = """%s 📖 Puedes usar comandos _inline_ en todos los chats, incluso en las conversaciones privadas. Espera un segundo después de introducir un comando _inline_ y *haz clic* en el resultado, no pulses enter. ⚙️ *Comandos avanzados* +*/transactions* 📊 List transactions */link* 🔗 Enlaza tu monedero a [ BlueWallet ](https://bluewallet.io/) o [ Zeus ](https://zeusln.app/) */lnurl* ⚡️ Lnurl recibir o pagar: `/lnurl` o `/lnurl ` */faucet* 🚰 Crear un grifo: `/faucet ` */tipjar* 🍯 Crear un tipjar: `/tipjar ` -*/group* 🎟 Create group tickets: `/group add []`""" +*/group* 🎟 Create group tickets: `/group add []` +*/shop* 🛍 Browse shops: `/shop` or `/shop `""" # GENERIC enterAmountRangeMessage = """💯 Introduce un monto entre %d y %d sat.""" diff --git a/translations/fr.toml b/translations/fr.toml index af81265..2c0c2f1 100644 --- a/translations/fr.toml +++ b/translations/fr.toml @@ -117,11 +117,13 @@ advancedMessage = """%s 📖 Vous pouvez utiliser ces commandes dans tous les chats et même dans les conversations privées. Attendez une seconde après avoir tapé une commandé puis *click* sur le résultat, n'appuyez pas sur entrée. ⚙️ *Commandes avancées* +*/transactions* 📊 List transactions */link* 🔗 Lier votre wallet à [BlueWallet](https://bluewallet.io/) ou [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl recevoir ou payer: `/lnurl` ou `/lnurl ` */faucet* 🚰 Créer un faucet: `/faucet ` */tipjar* 🍯 Créer un tipjar: `/tipjar ` -*/group* 🎟 Create group tickets: `/group add []`""" +*/group* 🎟 Create group tickets: `/group add []` +*/shop* 🛍 Browse shops: `/shop` or `/shop `""" # GENERIC enterAmountRangeMessage = """💯 Choisissez un montant entre %d et %d sat.""" diff --git a/translations/id.toml b/translations/id.toml index 272cb28..52eecf9 100644 --- a/translations/id.toml +++ b/translations/id.toml @@ -117,11 +117,13 @@ advancedMessage = """%s 📖 Kamu dapat menggunakan sebaris perintah di tiap percakapan, bahkan di percakapan privat. Tunggu sejenak setelah memasukkan sebaris perintah lalu *pencet* hasilnya, jangan tekan enter. ⚙️ *Perintah lanjutan* +*/transactions* 📊 List transactions */link* 🔗 Menghubungkan dompet mu ke [BlueWallet](https://bluewallet.io/) atau [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl menerima atau membayar: `/lnurl` atau `/lnurl ` */faucet* 🚰 Membuat sebuah keran `/faucet ` */tipjar* 🍯 Create a tipjar: `/tipjar ` -*/group* 🎟 Create group tickets: `/group add []`""" +*/group* 🎟 Create group tickets: `/group add []` +*/shop* 🛍 Browse shops: `/shop` or `/shop `""" # GENERIC enterAmountRangeMessage = """💯 Masukkan jumlah diantara %d dan %d sat.""" diff --git a/translations/it.toml b/translations/it.toml index b771f0a..375046a 100644 --- a/translations/it.toml +++ b/translations/it.toml @@ -117,11 +117,13 @@ advancedMessage = """%s 📖 Puoi usare i comandi in linea in ogni chat, anche nelle conversazioni private. Attendi un secondo dopo aver inviato un comando in linea e *clicca* sull'azione desiderata, non premere invio. ⚙️ *Comandi avanzati* +*/transactions* 📊 List transactions */link* 🔗 Crea un collegamento al tuo wallet [BlueWallet](https://bluewallet.io/) o [Zeus](https://zeusln.app/) */lnurl* ⚡️ Ricevi o paga un Lnurl: `/lnurl` or `/lnurl ` */faucet* 🚰 Crea una distribuzione: `/faucet ` */tipjar* 🍯 Crea un tipjar: `/tipjar ` -*/group* 🎟 Create group tickets: `/group add []`""" +*/group* 🎟 Create group tickets: `/group add []` +*/shop* 🛍 Browse shops: `/shop` or `/shop `""" # GENERIC enterAmountRangeMessage = """💯 Imposta un ammontare tra %d e %d sat.""" diff --git a/translations/nl.toml b/translations/nl.toml index 12bd567..789349c 100644 --- a/translations/nl.toml +++ b/translations/nl.toml @@ -117,11 +117,13 @@ advancedMessage = """%s 📖 Je kunt inline commando's in elke chat gebruiken, zelfs in privé gesprekken. Wacht een seconde na het invoeren van een inline commando en *klik* op het resultaat, druk niet op enter. ⚙️ *Geavanceerde opdrachten* +*/transactions* 📊 List transactions */link* 🔗 Koppel uw wallet aan [BlueWallet](https://bluewallet.io/) of [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl ontvangen of betalen: `/lnurl` of `/lnurl ` */faucet* 🚰 Maak een kraan: `/faucet ` */tipjar* 🍯 Maak een tipjar: `/tipjar ` -*/group* 🎟 Create group tickets: `/group add []`""" +*/group* 🎟 Create group tickets: `/group add []` +*/shop* 🛍 Browse shops: `/shop` or `/shop `""" # GENERIC enterAmountRangeMessage = """💯 Voer een bedrag in tussen %d en %d sat.""" diff --git a/translations/pt-br.toml b/translations/pt-br.toml index 51ad6fa..8f1250d 100644 --- a/translations/pt-br.toml +++ b/translations/pt-br.toml @@ -117,11 +117,13 @@ advancedMessage = """%s 📖 Você pode usar comandos _inline_ em todas as conversas, mesmo em conversas privadas. Espere um segundo após inserir um comando _inline_ e *clique* no resultado, não pressione enter. ⚙️ *Comandos avançados* +*/transactions* 📊 List transactions */link* 🔗 Vincule sua carteira a [ BlueWallet ](https://bluewallet.io/) ou [ Zeus ](https://zeusln.app/) */lnurl* ⚡️ Receber ou pagar com lnurl: `/lnurl` o `/lnurl ` */faucet* 🚰 Criar uma torneira: `/faucet ` */tipjar* 🍯 Criar uma tipjar: `/tipjar ` -*/group* 🎟 Create group tickets: `/group add []`""" +*/group* 🎟 Create group tickets: `/group add []` +*/shop* 🛍 Browse shops: `/shop` or `/shop `""" # GENERIC enterAmountRangeMessage = """💯 Insira uma quantia entre %d e %d sat.""" diff --git a/translations/ru.toml b/translations/ru.toml index 1027133..8ae3037 100644 --- a/translations/ru.toml +++ b/translations/ru.toml @@ -121,11 +121,13 @@ advancedMessage = """%s 📖 Вы можете использовать команды в любом чате, даже в личных беседах. Подождите секунду после ввода команды и *щелкните* результат, не нажимайте Enter.. ⚙️ *Продвинутые команды* +*/transactions* 📊 List transactions */link* 🔗 Link your wallet to [BlueWallet](https://bluewallet.io/) or [Zeus](https://zeusln.app/) */lnurl* Получить или оплатить через ⚡️Lnurl: `/lnurl` or `/lnurl ` */faucet* 🚰 Создать криптораздачу: `/faucet <ёмкость> <на_пользователя>` */tipjar* 🍯 Создать копилку: `/tipjar <ёмкость> <на_пользователя>` -*/group* 🎟 Create group tickets: `/group add []`""" +*/group* 🎟 Create group tickets: `/group add []` +*/shop* 🛍 Browse shops: `/shop` or `/shop `""" # GENERIC enterAmountRangeMessage = """💯 Введите количество между %d и %d sat.""" diff --git a/translations/tr.toml b/translations/tr.toml index 92e06e0..0545c98 100644 --- a/translations/tr.toml +++ b/translations/tr.toml @@ -117,11 +117,13 @@ advancedMessage = """%s 📖 İnline komutları her sohbette ve hatta özel mesajlarda kullanabilirsin. Komutu yazdıktan sonra bir saniye bekle ve Enter yazmak yerine sonuca *tıkla*. ⚙️ *Gelişmiş komutlar* +*/transactions* 📊 List transactions */link* 🔗 Cüzdanını bağla: [BlueWallet](https://bluewallet.io/) veya [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl iste veya gönder: `/lnurl` veya `/lnurl ` */faucet* 🚰 Bir fıçı oluştur: `/faucet ` */tipjar* 🍯 Bir tipjar oluştur: `/tipjar ` -*/group* 🎟 Create group tickets: `/group add []`""" +*/group* 🎟 Create group tickets: `/group add []` +*/shop* 🛍 Browse shops: `/shop` or `/shop `""" # GENERIC enterAmountRangeMessage = """💯 %d ve %d sat arasında bir miktar gir."""