Improved avatar log

This commit is contained in:
Eduard Urbach 2017-06-16 13:48:11 +02:00
parent 47a7940e32
commit 627eae999b
4 changed files with 14 additions and 9 deletions

View File

@ -11,6 +11,8 @@ import (
"github.com/parnurzeal/gorequest" "github.com/parnurzeal/gorequest"
) )
var netLog = avatarLog.NewChannel("NET")
// Avatar represents a single image and the name of the format. // Avatar represents a single image and the name of the format.
type Avatar struct { type Avatar struct {
User *arn.User User *arn.User
@ -37,13 +39,13 @@ func AvatarFromURL(url string, user *arn.User) *Avatar {
// Network errors // Network errors
if networkErr != nil { if networkErr != nil {
avatarLog.Error("NET", user.Nick, url, networkErr) netLog.Error(user.Nick, url, networkErr)
return nil return nil
} }
// Bad status codes // Bad status codes
if response.StatusCode != http.StatusOK { if response.StatusCode != http.StatusOK {
avatarLog.Error("NET", user.Nick, url, response.StatusCode) netLog.Error(user.Nick, url, response.StatusCode)
return nil return nil
} }
@ -51,7 +53,7 @@ func AvatarFromURL(url string, user *arn.User) *Avatar {
img, format, decodeErr := image.Decode(bytes.NewReader(data)) img, format, decodeErr := image.Decode(bytes.NewReader(data))
if decodeErr != nil { if decodeErr != nil {
avatarLog.Error("IMG", user.Nick, url, decodeErr) netLog.Error(user.Nick, url, decodeErr)
return nil return nil
} }

View File

@ -8,6 +8,8 @@ import (
gravatar "github.com/ungerik/go-gravatar" gravatar "github.com/ungerik/go-gravatar"
) )
var gravatarLog = avatarLog.NewChannel("GRA")
// Gravatar - https://gravatar.com/ // Gravatar - https://gravatar.com/
type Gravatar struct { type Gravatar struct {
Rating string Rating string
@ -18,7 +20,7 @@ type Gravatar struct {
func (source *Gravatar) GetAvatar(user *arn.User) *Avatar { func (source *Gravatar) GetAvatar(user *arn.User) *Avatar {
// If the user has no Email registered we can't get a Gravatar. // If the user has no Email registered we can't get a Gravatar.
if user.Email == "" { if user.Email == "" {
avatarLog.Error("GRA", user.Nick, "No Email") gravatarLog.Error(user.Nick, "No Email")
return nil return nil
} }

View File

@ -10,6 +10,7 @@ import (
) )
var userIDRegex = regexp.MustCompile(`<user_id>(\d+)<\/user_id>`) var userIDRegex = regexp.MustCompile(`<user_id>(\d+)<\/user_id>`)
var malLog = avatarLog.NewChannel("MAL")
// MyAnimeList - https://myanimelist.net/ // MyAnimeList - https://myanimelist.net/
type MyAnimeList struct { type MyAnimeList struct {
@ -22,7 +23,7 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar {
// If the user has no username we can't get an avatar. // If the user has no username we can't get an avatar.
if malNick == "" { if malNick == "" {
avatarLog.Error("MAL", user.Nick, "No MAL nick") malLog.Error(user.Nick, "No MAL nick")
return nil return nil
} }
@ -31,12 +32,12 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar {
response, xml, networkErr := gorequest.New().Get(userInfoURL).End() response, xml, networkErr := gorequest.New().Get(userInfoURL).End()
if networkErr != nil { if networkErr != nil {
avatarLog.Error("MAL", user.Nick, userInfoURL, networkErr) malLog.Error(user.Nick, userInfoURL, networkErr)
return nil return nil
} }
if response.StatusCode != http.StatusOK { if response.StatusCode != http.StatusOK {
avatarLog.Error("MAL", user.Nick, userInfoURL, response.StatusCode) malLog.Error(user.Nick, userInfoURL, response.StatusCode)
return nil return nil
} }
@ -44,7 +45,7 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar {
matches := userIDRegex.FindStringSubmatch(xml) matches := userIDRegex.FindStringSubmatch(xml)
if matches == nil || len(matches) < 2 { if matches == nil || len(matches) < 2 {
avatarLog.Error("MAL", user.Nick, "Could not find user ID") malLog.Error(user.Nick, "Could not find user ID")
return nil return nil
} }

View File

@ -22,7 +22,7 @@ const (
var avatarSources []AvatarSource var avatarSources []AvatarSource
var avatarOutputs []AvatarOutput var avatarOutputs []AvatarOutput
var avatarLog = log.NewChannel("avatar") var avatarLog = log.NewLog()
// Main // Main
func main() { func main() {