Let's try something

This commit is contained in:
Hamcha 2018-09-17 15:52:18 +02:00
parent 3670cafaac
commit da60c15f44
Signed by: hamcha
GPG key ID: A40413D21021EAEE

96
main.go
View file

@ -51,56 +51,54 @@ func webhook(update tg.APIUpdate) {
return
}
go func() {
query := update.Inline.Query
offset, _ := strconv.Atoi(update.Inline.Offset)
results, err := scryfallSearch(query, offset)
if err != nil {
fmt.Println(err)
// DO SOMETHING
return
}
query := update.Inline.Query
offset, _ := strconv.Atoi(update.Inline.Offset)
results, err := scryfallSearch(query, offset)
if err != nil {
fmt.Println(err)
// DO SOMETHING
return
}
nextcard := ""
if results.HasMore {
nextcard = strconv.Itoa(offset + len(results.Data))
}
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)
photos[i] = tg.APIInlineQueryResultPhoto{
Type: "photo",
ResultID: card.ID,
PhotoURL: card.ImageUris.Large,
ThumbURL: card.ImageUris.Normal,
Title: card.Name,
Caption: caption,
ReplyMarkup: &tg.APIInlineKeyboardMarkup{
InlineKeyboard: [][]tg.APIInlineKeyboardButton{{
{
Text: "Scryfall",
URL: card.ScryfallURI,
}, {
Text: "EDHREC",
URL: card.RelatedUris.Edhrec,
}, {
Text: "MCM",
URL: card.PurchaseUris.Magiccardmarket,
},
}},
},
}
nextcard := ""
if results.HasMore {
nextcard = strconv.Itoa(offset + len(results.Data))
}
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)
photos[i] = tg.APIInlineQueryResultPhoto{
Type: "photo",
ResultID: card.ID,
PhotoURL: card.ImageUris.Large,
ThumbURL: card.ImageUris.Normal,
Title: card.Name,
Caption: caption,
ReplyMarkup: &tg.APIInlineKeyboardMarkup{
InlineKeyboard: [][]tg.APIInlineKeyboardButton{{
{
Text: "Scryfall",
URL: card.ScryfallURI,
}, {
Text: "EDHREC",
URL: card.RelatedUris.Edhrec,
}, {
Text: "MCM",
URL: card.PurchaseUris.Magiccardmarket,
},
}},
},
}
}
err = api.AnswerInlineQuery(tg.InlineQueryResponse{
QueryID: update.Inline.QueryID,
Results: photos,
NextOffset: nextcard,
})
if err != nil {
fmt.Println(err)
// DO SOMETHING
return
}
}()
err = api.AnswerInlineQuery(tg.InlineQueryResponse{
QueryID: update.Inline.QueryID,
Results: photos,
NextOffset: nextcard,
})
if err != nil {
fmt.Println(err)
// DO SOMETHING
return
}
}