Compare commits
1
Commits
Dev
...
spring_clean
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08630f76e3 |
@@ -4,10 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/LightningTipBot/LightningTipBot/internal/errors"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/LightningTipBot/LightningTipBot/internal/errors"
|
||||||
|
|
||||||
"github.com/LightningTipBot/LightningTipBot/internal/runtime/mutex"
|
"github.com/LightningTipBot/LightningTipBot/internal/runtime/mutex"
|
||||||
"github.com/LightningTipBot/LightningTipBot/internal/storage"
|
"github.com/LightningTipBot/LightningTipBot/internal/storage"
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ func (bot TipBot) handleInlineReceiveQuery(ctx context.Context, q *tb.Query) (co
|
|||||||
bot.inlineQueryReplyWithError(q, Translate(ctx, "inlineSendInvalidAmountMessage"), fmt.Sprintf(Translate(ctx, "inlineQueryReceiveDescription"), bot.Telegram.Me.Username))
|
bot.inlineQueryReplyWithError(q, Translate(ctx, "inlineSendInvalidAmountMessage"), fmt.Sprintf(Translate(ctx, "inlineQueryReceiveDescription"), bot.Telegram.Me.Username))
|
||||||
return ctx, errors.Create(errors.InvalidAmountError)
|
return ctx, errors.Create(errors.InvalidAmountError)
|
||||||
}
|
}
|
||||||
toUserStr := GetUserStr(&q.From)
|
toUserStrMd := GetUserStrMd(&q.From)
|
||||||
|
|
||||||
// check whether the 3rd argument is a username
|
// check whether the 3rd argument is a username
|
||||||
// command is "@LightningTipBot receive 123 @from_user This is the memo"
|
// command is "@LightningTipBot receive 123 @from_user This is the memo"
|
||||||
@@ -98,7 +99,7 @@ func (bot TipBot) handleInlineReceiveQuery(ctx context.Context, q *tb.Query) (co
|
|||||||
}
|
}
|
||||||
results := make(tb.Results, len(urls)) // []tb.Result
|
results := make(tb.Results, len(urls)) // []tb.Result
|
||||||
for i, url := range urls {
|
for i, url := range urls {
|
||||||
inlineMessage := fmt.Sprintf(Translate(ctx, "inlineReceiveMessage"), toUserStr, amount)
|
inlineMessage := fmt.Sprintf(Translate(ctx, "inlineReceiveMessage"), toUserStrMd, amount)
|
||||||
|
|
||||||
// modify message if payment is to specific user
|
// modify message if payment is to specific user
|
||||||
if from_SpecificUser {
|
if from_SpecificUser {
|
||||||
@@ -116,7 +117,7 @@ func (bot TipBot) handleInlineReceiveQuery(ctx context.Context, q *tb.Query) (co
|
|||||||
// required for photos
|
// required for photos
|
||||||
ThumbURL: url,
|
ThumbURL: url,
|
||||||
}
|
}
|
||||||
id := fmt.Sprintf("inl-receive-%d-%d-%s", q.From.ID, amount, RandStringRunes(5))
|
id := fmt.Sprintf("inl:receive:%d:%d:%s", q.From.ID, amount, RandStringRunes(5))
|
||||||
result.ReplyMarkup = &tb.InlineKeyboardMarkup{InlineKeyboard: bot.makeReceiveKeyboard(ctx, id).InlineKeyboard}
|
result.ReplyMarkup = &tb.InlineKeyboardMarkup{InlineKeyboard: bot.makeReceiveKeyboard(ctx, id).InlineKeyboard}
|
||||||
results[i] = result
|
results[i] = result
|
||||||
// needed to set a unique string ID for each result
|
// needed to set a unique string ID for each result
|
||||||
@@ -160,6 +161,7 @@ func (bot *TipBot) acceptInlineReceiveHandler(ctx context.Context, c *tb.Callbac
|
|||||||
inlineReceive := rn.(*InlineReceive)
|
inlineReceive := rn.(*InlineReceive)
|
||||||
if !inlineReceive.Active {
|
if !inlineReceive.Active {
|
||||||
log.Errorf("[acceptInlineReceiveHandler] inline receive not active anymore")
|
log.Errorf("[acceptInlineReceiveHandler] inline receive not active anymore")
|
||||||
|
bot.tryEditMessage(c.Message, i18n.Translate(inlineReceive.LanguageCode, "inlineReceiveCancelledMessage"), &tb.ReplyMarkup{})
|
||||||
return ctx, errors.Create(errors.NotActiveError)
|
return ctx, errors.Create(errors.NotActiveError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,9 +197,7 @@ func (bot *TipBot) acceptInlineReceiveHandler(ctx context.Context, c *tb.Callbac
|
|||||||
if from.Wallet == nil || balance < inlineReceive.Amount {
|
if from.Wallet == nil || balance < inlineReceive.Amount {
|
||||||
// if user has no wallet, show invoice
|
// if user has no wallet, show invoice
|
||||||
bot.tryEditMessage(inlineReceive.Message, inlineReceive.MessageText, &tb.ReplyMarkup{})
|
bot.tryEditMessage(inlineReceive.Message, inlineReceive.MessageText, &tb.ReplyMarkup{})
|
||||||
// runtime.IgnoreError(inlineReceive.Set(inlineReceive, bot.Bunt))
|
return bot.inlineReceiveInvoice(ctx, c, inlineReceive)
|
||||||
bot.inlineReceiveInvoice(ctx, c, inlineReceive)
|
|
||||||
return ctx, errors.Create(errors.BalanceToLowError)
|
|
||||||
} else {
|
} else {
|
||||||
// else, do an internal transaction
|
// else, do an internal transaction
|
||||||
return bot.sendInlineReceiveHandler(ctx, c)
|
return bot.sendInlineReceiveHandler(ctx, c)
|
||||||
@@ -219,6 +219,7 @@ func (bot *TipBot) sendInlineReceiveHandler(ctx context.Context, c *tb.Callback)
|
|||||||
|
|
||||||
if !inlineReceive.Active {
|
if !inlineReceive.Active {
|
||||||
log.Errorf("[acceptInlineReceiveHandler] inline receive not active anymore")
|
log.Errorf("[acceptInlineReceiveHandler] inline receive not active anymore")
|
||||||
|
bot.tryEditMessage(c.Message, i18n.Translate(inlineReceive.LanguageCode, "inlineReceiveCancelledMessage"), &tb.ReplyMarkup{})
|
||||||
return ctx, errors.Create(errors.NotActiveError)
|
return ctx, errors.Create(errors.NotActiveError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,17 +265,18 @@ func (bot *TipBot) sendInlineReceiveHandler(ctx context.Context, c *tb.Callback)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *TipBot) inlineReceiveInvoice(ctx context.Context, c *tb.Callback, inlineReceive *InlineReceive) {
|
func (bot *TipBot) inlineReceiveInvoice(ctx context.Context, c *tb.Callback, inlineReceive *InlineReceive) (context.Context, error) {
|
||||||
if !inlineReceive.Active {
|
if !inlineReceive.Active {
|
||||||
log.Errorf("[acceptInlineReceiveHandler] inline receive not active anymore")
|
log.Errorf("[acceptInlineReceiveHandler] inline receive not active anymore")
|
||||||
return
|
bot.tryEditMessage(c.Message, i18n.Translate(inlineReceive.LanguageCode, "inlineReceiveCancelledMessage"), &tb.ReplyMarkup{})
|
||||||
|
return ctx, errors.Create(errors.NotActiveError)
|
||||||
}
|
}
|
||||||
invoice, err := bot.createInvoiceWithEvent(ctx, inlineReceive.To, inlineReceive.Amount, fmt.Sprintf("Pay to %s", GetUserStr(inlineReceive.To.Telegram)), InvoiceCallbackInlineReceive, inlineReceive.ID)
|
invoice, err := bot.createInvoiceWithEvent(ctx, inlineReceive.To, inlineReceive.Amount, fmt.Sprintf("Pay to %s", GetUserStr(inlineReceive.To.Telegram)), InvoiceCallbackInlineReceive, inlineReceive.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errmsg := fmt.Sprintf("[/invoice] Could not create an invoice: %s", err.Error())
|
errmsg := fmt.Sprintf("[/invoice] Could not create an invoice: %s", err.Error())
|
||||||
bot.tryEditMessage(inlineReceive.Message, Translate(ctx, "errorTryLaterMessage"))
|
bot.tryEditMessage(inlineReceive.Message, Translate(ctx, "errorTryLaterMessage"))
|
||||||
log.Errorln(errmsg)
|
log.Errorln(errmsg)
|
||||||
return
|
return ctx, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// create qr code
|
// create qr code
|
||||||
@@ -283,7 +285,7 @@ func (bot *TipBot) inlineReceiveInvoice(ctx context.Context, c *tb.Callback, inl
|
|||||||
errmsg := fmt.Sprintf("[/invoice] Failed to create QR code for invoice: %s", err.Error())
|
errmsg := fmt.Sprintf("[/invoice] Failed to create QR code for invoice: %s", err.Error())
|
||||||
bot.tryEditMessage(inlineReceive.Message, Translate(ctx, "errorTryLaterMessage"))
|
bot.tryEditMessage(inlineReceive.Message, Translate(ctx, "errorTryLaterMessage"))
|
||||||
log.Errorln(errmsg)
|
log.Errorln(errmsg)
|
||||||
return
|
return ctx, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// send the invoice data to user
|
// send the invoice data to user
|
||||||
@@ -297,7 +299,7 @@ func (bot *TipBot) inlineReceiveInvoice(ctx context.Context, c *tb.Callback, inl
|
|||||||
invoice.InvoiceMessage = msg
|
invoice.InvoiceMessage = msg
|
||||||
runtime.IgnoreError(bot.Bunt.Set(invoice))
|
runtime.IgnoreError(bot.Bunt.Set(invoice))
|
||||||
log.Printf("[/invoice] Incvoice created. User: %s, amount: %d sat.", GetUserStr(inlineReceive.To.Telegram), inlineReceive.Amount)
|
log.Printf("[/invoice] Incvoice created. User: %s, amount: %d sat.", GetUserStr(inlineReceive.To.Telegram), inlineReceive.Amount)
|
||||||
|
return ctx, nil
|
||||||
}
|
}
|
||||||
func (bot *TipBot) inlineReceiveEvent(invoiceEvent *InvoiceEvent) {
|
func (bot *TipBot) inlineReceiveEvent(invoiceEvent *InvoiceEvent) {
|
||||||
bot.tryDeleteMessage(invoiceEvent.InvoiceMessage)
|
bot.tryDeleteMessage(invoiceEvent.InvoiceMessage)
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ package telegram
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/LightningTipBot/LightningTipBot/internal/errors"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/LightningTipBot/LightningTipBot/internal/errors"
|
||||||
|
|
||||||
"github.com/LightningTipBot/LightningTipBot/internal/runtime/mutex"
|
"github.com/LightningTipBot/LightningTipBot/internal/runtime/mutex"
|
||||||
"github.com/LightningTipBot/LightningTipBot/internal/storage"
|
"github.com/LightningTipBot/LightningTipBot/internal/storage"
|
||||||
|
|
||||||
@@ -66,6 +67,7 @@ func (bot TipBot) handleInlineSendQuery(ctx context.Context, q *tb.Query) (conte
|
|||||||
}
|
}
|
||||||
fromUser := LoadUser(ctx)
|
fromUser := LoadUser(ctx)
|
||||||
fromUserStr := GetUserStr(&q.From)
|
fromUserStr := GetUserStr(&q.From)
|
||||||
|
fromUserStrMd := GetUserStrMd(&q.From)
|
||||||
balance, err := bot.GetUserBalanceCached(fromUser)
|
balance, err := bot.GetUserBalanceCached(fromUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errmsg := fmt.Sprintf("could not get balance of user %s", fromUserStr)
|
errmsg := fmt.Sprintf("could not get balance of user %s", fromUserStr)
|
||||||
@@ -109,7 +111,7 @@ func (bot TipBot) handleInlineSendQuery(ctx context.Context, q *tb.Query) (conte
|
|||||||
}
|
}
|
||||||
results := make(tb.Results, len(urls)) // []tb.Result
|
results := make(tb.Results, len(urls)) // []tb.Result
|
||||||
for i, url := range urls {
|
for i, url := range urls {
|
||||||
inlineMessage := fmt.Sprintf(Translate(ctx, "inlineSendMessage"), fromUserStr, amount)
|
inlineMessage := fmt.Sprintf(Translate(ctx, "inlineSendMessage"), fromUserStrMd, amount)
|
||||||
|
|
||||||
// modify message if payment is to specific user
|
// modify message if payment is to specific user
|
||||||
if to_SpecificUser {
|
if to_SpecificUser {
|
||||||
@@ -127,7 +129,7 @@ func (bot TipBot) handleInlineSendQuery(ctx context.Context, q *tb.Query) (conte
|
|||||||
// required for photos
|
// required for photos
|
||||||
ThumbURL: url,
|
ThumbURL: url,
|
||||||
}
|
}
|
||||||
id := fmt.Sprintf("inl-send-%d-%d-%s", q.From.ID, amount, RandStringRunes(5))
|
id := fmt.Sprintf("inl:send:%d:%d:%s", q.From.ID, amount, RandStringRunes(5))
|
||||||
result.ReplyMarkup = &tb.InlineKeyboardMarkup{InlineKeyboard: bot.makeSendKeyboard(ctx, id).InlineKeyboard}
|
result.ReplyMarkup = &tb.InlineKeyboardMarkup{InlineKeyboard: bot.makeSendKeyboard(ctx, id).InlineKeyboard}
|
||||||
results[i] = result
|
results[i] = result
|
||||||
// needed to set a unique string ID for each result
|
// needed to set a unique string ID for each result
|
||||||
@@ -177,6 +179,7 @@ func (bot *TipBot) acceptInlineSendHandler(ctx context.Context, c *tb.Callback)
|
|||||||
fromUser := inlineSend.From
|
fromUser := inlineSend.From
|
||||||
if !inlineSend.Active {
|
if !inlineSend.Active {
|
||||||
log.Errorf("[acceptInlineSendHandler] inline send not active anymore")
|
log.Errorf("[acceptInlineSendHandler] inline send not active anymore")
|
||||||
|
bot.tryEditMessage(c.Message, i18n.Translate(inlineSend.LanguageCode, "sendCancelledMessage"), &tb.ReplyMarkup{})
|
||||||
return ctx, errors.Create(errors.NotActiveError)
|
return ctx, errors.Create(errors.NotActiveError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ func DownloadProfilePicture(telegram *tb.Bot, user *tb.User) ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(photo) == 0 {
|
if len(photo) == 0 {
|
||||||
log.Error("[DownloadProfilePicture] No profile picture found")
|
log.Debugln("[DownloadProfilePicture] No profile picture found")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|||||||
Reference in New Issue
Block a user