Fix for tg api change AND scryfall api change

This commit is contained in:
Hamcha 2018-12-13 11:22:10 +01:00
parent e09a2b473a
commit a2d2189585
Signed by: hamcha
GPG key ID: A40413D21021EAEE
2 changed files with 37 additions and 23 deletions

42
main.go
View file

@ -70,29 +70,43 @@ func webhook(update tg.APIUpdate) {
}
photos := make([]tg.APIInlineQueryResultPhoto, len(results.Data))
for i, card := range results.Data {
caption := fmt.Sprintf("EDHREC rank: #%d - cardmarket: € %s", card.EdhrecRank, card.Eur)
buttons := []tg.APIInlineKeyboardButton{
{
Text: "Scryfall",
URL: card.ScryfallURI,
},
}
if card.RelatedUris.Edhrec != "" {
buttons = append(buttons, tg.APIInlineKeyboardButton{
Text: "EDHREC",
URL: card.RelatedUris.Edhrec,
})
}
if card.PurchaseUris.Cardmarket != "" {
buttons = append(buttons, tg.APIInlineKeyboardButton{
Text: "MCM",
URL: card.PurchaseUris.Cardmarket,
})
}
captions := []string{}
if card.EdhrecRank != nil {
captions = append(captions, fmt.Sprintf("EDHREC rank: #%d", *card.EdhrecRank))
}
if card.Eur != "" {
captions = append(captions, fmt.Sprintf("cardmarket: € %s", card.Eur))
}
photos[i] = tg.APIInlineQueryResultPhoto{
Type: "photo",
ResultID: card.ID,
PhotoURL: card.ImageUris.Large,
ThumbURL: card.ImageUris.Normal,
Title: card.Name,
Caption: caption,
Caption: strings.Join(captions, " - "),
Width: 672,
Height: 936,
ReplyMarkup: &tg.APIInlineKeyboardMarkup{
InlineKeyboard: [][]tg.APIInlineKeyboardButton{{
{
Text: "Scryfall",
URL: card.ScryfallURI,
}, {
Text: "EDHREC",
URL: card.RelatedUris.Edhrec,
}, {
Text: "MCM",
URL: card.PurchaseUris.Magiccardmarket,
},
}},
InlineKeyboard: [][]tg.APIInlineKeyboardButton{buttons},
},
}
}

View file

@ -31,7 +31,7 @@ type CardData struct {
BorderCrop string `json:"border_crop"`
} `json:"image_uris"`
Eur string `json:"eur"`
EdhrecRank int `json:"edhrec_rank"`
EdhrecRank *int `json:"edhrec_rank"`
RelatedUris struct {
Gatherer string `json:"gatherer"`
TcgplayerDecks string `json:"tcgplayer_decks"`
@ -39,14 +39,14 @@ type CardData struct {
Mtgtop8 string `json:"mtgtop8"`
} `json:"related_uris"`
PurchaseUris struct {
Amazon string `json:"amazon"`
Ebay string `json:"ebay"`
Tcgplayer string `json:"tcgplayer"`
Magiccardmarket string `json:"magiccardmarket"`
Cardhoarder string `json:"cardhoarder"`
CardKingdom string `json:"card_kingdom"`
MtgoTraders string `json:"mtgo_traders"`
Coolstuffinc string `json:"coolstuffinc"`
Amazon string `json:"amazon"`
Ebay string `json:"ebay"`
Tcgplayer string `json:"tcgplayer"`
Cardmarket string `json:"cardmarket"`
Cardhoarder string `json:"cardhoarder"`
CardKingdom string `json:"card_kingdom"`
MtgoTraders string `json:"mtgo_traders"`
Coolstuffinc string `json:"coolstuffinc"`
} `json:"purchase_uris"`
}