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)) photos := make([]tg.APIInlineQueryResultPhoto, len(results.Data))
for i, card := range 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{ photos[i] = tg.APIInlineQueryResultPhoto{
Type: "photo", Type: "photo",
ResultID: card.ID, ResultID: card.ID,
PhotoURL: card.ImageUris.Large, PhotoURL: card.ImageUris.Large,
ThumbURL: card.ImageUris.Normal, ThumbURL: card.ImageUris.Normal,
Title: card.Name, Title: card.Name,
Caption: caption, Caption: strings.Join(captions, " - "),
Width: 672, Width: 672,
Height: 936, Height: 936,
ReplyMarkup: &tg.APIInlineKeyboardMarkup{ ReplyMarkup: &tg.APIInlineKeyboardMarkup{
InlineKeyboard: [][]tg.APIInlineKeyboardButton{{ InlineKeyboard: [][]tg.APIInlineKeyboardButton{buttons},
{
Text: "Scryfall",
URL: card.ScryfallURI,
}, {
Text: "EDHREC",
URL: card.RelatedUris.Edhrec,
}, {
Text: "MCM",
URL: card.PurchaseUris.Magiccardmarket,
},
}},
}, },
} }
} }

View file

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