Added different formatting for telegram bot
This commit is contained in:
parent
35f8fa5a57
commit
89623f5f6a
18 changed files with 233 additions and 173 deletions
|
|
@ -1,16 +1,38 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"gitlab.com/flygrounder/go-mtg-vk/internal/cardsinfo"
|
||||
)
|
||||
|
||||
type Sender struct {
|
||||
API *tgbotapi.BotAPI
|
||||
API *tgbotapi.BotAPI
|
||||
}
|
||||
|
||||
func (s *Sender) SendPrices(userId int64, cardName string, prices []cardsinfo.ScgCardPrice) {
|
||||
msg := formatCardPrices(cardName, prices)
|
||||
s.Send(userId, msg)
|
||||
}
|
||||
|
||||
func (h *Sender) Send(userId int64, message string) {
|
||||
msg := tgbotapi.NewMessage(userId, message)
|
||||
msg.DisableWebPagePreview = true
|
||||
h.API.Send(msg)
|
||||
msg := tgbotapi.NewMessage(userId, message)
|
||||
msg.DisableWebPagePreview = true
|
||||
h.API.Send(msg)
|
||||
}
|
||||
|
||||
func formatCardPrices(name string, prices []cardsinfo.ScgCardPrice) string {
|
||||
message := fmt.Sprintf("Оригинальное название: %v\n\n", name)
|
||||
for i, v := range prices {
|
||||
message += fmt.Sprintf("%v. %v", i+1, formatPrice(v))
|
||||
}
|
||||
if len(prices) == 0 {
|
||||
message += "Цен не найдено\n"
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
func formatPrice(s cardsinfo.ScgCardPrice) string {
|
||||
return fmt.Sprintf("[%v](%v): %v\n", s.Edition, s.Link, s.Price)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue