Add logging

This commit is contained in:
Hamcha 2019-08-20 15:04:38 +02:00
parent 514574ef03
commit b140847daa
Signed by: hamcha
GPG key ID: 44AD3571EB09A39E
2 changed files with 12 additions and 0 deletions

View file

@ -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{

View file

@ -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