Fixed bug with card _____ in Telegram

This commit is contained in:
Artyom Belousov 2021-06-25 13:01:55 +03:00
parent 50353b67cd
commit 310c99eeb6
2 changed files with 9 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package telegram
import (
"fmt"
"strings"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"gitlab.com/flygrounder/go-mtg-vk/internal/cardsinfo"
@ -24,7 +25,8 @@ func (h *Sender) Send(userId int64, message string) {
}
func formatCardPrices(name string, prices []cardsinfo.ScgCardPrice) string {
message := fmt.Sprintf("Оригинальное название: %v\n\n", name)
escapedName := strings.ReplaceAll(name, "_", "\\_")
message := fmt.Sprintf("Оригинальное название: %v\n\n", escapedName)
for i, v := range prices {
message += fmt.Sprintf("%v. %v", i+1, formatPrice(v))
}

View file

@ -23,3 +23,9 @@ func Test_formatCardPrices(t *testing.T) {
result := formatCardPrices("card", prices)
assert.Equal(t, "Оригинальное название: card\n\n1. [Alpha](scg1): 1\n2. [Beta](scg2): 2\n", result)
}
func Test_formatCardPricesEscapeUnderscore(t *testing.T) {
prices := []cardsinfo.ScgCardPrice{}
result := formatCardPrices("_____", prices)
assert.Equal(t, "Оригинальное название: \\_\\_\\_\\_\\_\n\nЦен не найдено\n", result)
}