Compare commits

...
1 Commits
Author SHA1 Message Date
callebtc 08630f76e3 fix markdown things 2022-02-15 10:49:41 +01:00
3 changed files with 21 additions and 16 deletions
+14 -12
View File
@@ -4,10 +4,11 @@ import (
"bytes"
"context"
"fmt"
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"strings"
"time"
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/internal/runtime/mutex"
"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))
return ctx, errors.Create(errors.InvalidAmountError)
}
toUserStr := GetUserStr(&q.From)
toUserStrMd := GetUserStrMd(&q.From)
// check whether the 3rd argument is a username
// 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
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
if from_SpecificUser {
@@ -116,7 +117,7 @@ func (bot TipBot) handleInlineReceiveQuery(ctx context.Context, q *tb.Query) (co
// required for photos
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}
results[i] = 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)
if !inlineReceive.Active {
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)
}
@@ -195,9 +197,7 @@ func (bot *TipBot) acceptInlineReceiveHandler(ctx context.Context, c *tb.Callbac
if from.Wallet == nil || balance < inlineReceive.Amount {
// if user has no wallet, show invoice
bot.tryEditMessage(inlineReceive.Message, inlineReceive.MessageText, &tb.ReplyMarkup{})
// runtime.IgnoreError(inlineReceive.Set(inlineReceive, bot.Bunt))
bot.inlineReceiveInvoice(ctx, c, inlineReceive)
return ctx, errors.Create(errors.BalanceToLowError)
return bot.inlineReceiveInvoice(ctx, c, inlineReceive)
} else {
// else, do an internal transaction
return bot.sendInlineReceiveHandler(ctx, c)
@@ -219,6 +219,7 @@ func (bot *TipBot) sendInlineReceiveHandler(ctx context.Context, c *tb.Callback)
if !inlineReceive.Active {
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)
}
@@ -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 {
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)
if err != nil {
errmsg := fmt.Sprintf("[/invoice] Could not create an invoice: %s", err.Error())
bot.tryEditMessage(inlineReceive.Message, Translate(ctx, "errorTryLaterMessage"))
log.Errorln(errmsg)
return
return ctx, err
}
// 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())
bot.tryEditMessage(inlineReceive.Message, Translate(ctx, "errorTryLaterMessage"))
log.Errorln(errmsg)
return
return ctx, err
}
// send the invoice data to user
@@ -297,7 +299,7 @@ func (bot *TipBot) inlineReceiveInvoice(ctx context.Context, c *tb.Callback, inl
invoice.InvoiceMessage = msg
runtime.IgnoreError(bot.Bunt.Set(invoice))
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) {
bot.tryDeleteMessage(invoiceEvent.InvoiceMessage)
+6 -3
View File
@@ -3,10 +3,11 @@ package telegram
import (
"context"
"fmt"
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"strings"
"time"
"github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/internal/runtime/mutex"
"github.com/LightningTipBot/LightningTipBot/internal/storage"
@@ -66,6 +67,7 @@ func (bot TipBot) handleInlineSendQuery(ctx context.Context, q *tb.Query) (conte
}
fromUser := LoadUser(ctx)
fromUserStr := GetUserStr(&q.From)
fromUserStrMd := GetUserStrMd(&q.From)
balance, err := bot.GetUserBalanceCached(fromUser)
if err != nil {
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
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
if to_SpecificUser {
@@ -127,7 +129,7 @@ func (bot TipBot) handleInlineSendQuery(ctx context.Context, q *tb.Query) (conte
// required for photos
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}
results[i] = 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
if !inlineSend.Active {
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)
}
+1 -1
View File
@@ -94,7 +94,7 @@ func DownloadProfilePicture(telegram *tb.Bot, user *tb.User) ([]byte, error) {
return nil, err
}
if len(photo) == 0 {
log.Error("[DownloadProfilePicture] No profile picture found")
log.Debugln("[DownloadProfilePicture] No profile picture found")
return nil, err
}
buf := new(bytes.Buffer)