Add logging
This commit is contained in:
parent
514574ef03
commit
b140847daa
2 changed files with 12 additions and 0 deletions
8
main.go
8
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -18,6 +19,7 @@ type config struct {
|
|||
WebhookURL string
|
||||
WebhookPath string
|
||||
MaxRequestsPerMessage int
|
||||
Log bool
|
||||
}
|
||||
|
||||
func checkErr(err error, msg string, args ...interface{}) {
|
||||
|
@ -70,6 +72,9 @@ func webhook(update tg.APIUpdate) {
|
|||
// DO SOMETHING
|
||||
return
|
||||
}
|
||||
if cfg.Log {
|
||||
log.Printf(" -> %d cards", len(results.Data))
|
||||
}
|
||||
|
||||
photos := make([]tg.APIInlineQueryResultPhoto, len(results.Data))
|
||||
for i, card := range results.Data {
|
||||
|
@ -118,6 +123,9 @@ func webhook(update tg.APIUpdate) {
|
|||
if err != nil {
|
||||
errlist = append(errlist, cardname)
|
||||
} else {
|
||||
if cfg.Log {
|
||||
log.Printf(" -> %d cards", len(cards.Data))
|
||||
}
|
||||
for _, card := range cards.Data {
|
||||
face, _, _ := getCardEntry(card, 0)
|
||||
cardmedia = append(cardmedia, tg.APIInputMediaPhoto{
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
@ -35,6 +36,9 @@ var netClient = &http.Client{
|
|||
func mlpapiSearch(query string) (results CardSearchResults, err error) {
|
||||
query = url.QueryEscape(query)
|
||||
requrl := fmt.Sprintf("https://www.ferrictorus.com/mlpapi1/cards?query=%s", query)
|
||||
if cfg.Log {
|
||||
log.Println(requrl)
|
||||
}
|
||||
response, err := netClient.Get(requrl)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue