Improved avatar log
This commit is contained in:
parent
47a7940e32
commit
627eae999b
@ -11,6 +11,8 @@ import (
|
||||
"github.com/parnurzeal/gorequest"
|
||||
)
|
||||
|
||||
var netLog = avatarLog.NewChannel("NET")
|
||||
|
||||
// Avatar represents a single image and the name of the format.
|
||||
type Avatar struct {
|
||||
User *arn.User
|
||||
@ -37,13 +39,13 @@ func AvatarFromURL(url string, user *arn.User) *Avatar {
|
||||
|
||||
// Network errors
|
||||
if networkErr != nil {
|
||||
avatarLog.Error("NET", user.Nick, url, networkErr)
|
||||
netLog.Error(user.Nick, url, networkErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Bad status codes
|
||||
if response.StatusCode != http.StatusOK {
|
||||
avatarLog.Error("NET", user.Nick, url, response.StatusCode)
|
||||
netLog.Error(user.Nick, url, response.StatusCode)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -51,7 +53,7 @@ func AvatarFromURL(url string, user *arn.User) *Avatar {
|
||||
img, format, decodeErr := image.Decode(bytes.NewReader(data))
|
||||
|
||||
if decodeErr != nil {
|
||||
avatarLog.Error("IMG", user.Nick, url, decodeErr)
|
||||
netLog.Error(user.Nick, url, decodeErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ import (
|
||||
gravatar "github.com/ungerik/go-gravatar"
|
||||
)
|
||||
|
||||
var gravatarLog = avatarLog.NewChannel("GRA")
|
||||
|
||||
// Gravatar - https://gravatar.com/
|
||||
type Gravatar struct {
|
||||
Rating string
|
||||
@ -18,7 +20,7 @@ type Gravatar struct {
|
||||
func (source *Gravatar) GetAvatar(user *arn.User) *Avatar {
|
||||
// If the user has no Email registered we can't get a Gravatar.
|
||||
if user.Email == "" {
|
||||
avatarLog.Error("GRA", user.Nick, "No Email")
|
||||
gravatarLog.Error(user.Nick, "No Email")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
var userIDRegex = regexp.MustCompile(`<user_id>(\d+)<\/user_id>`)
|
||||
var malLog = avatarLog.NewChannel("MAL")
|
||||
|
||||
// MyAnimeList - https://myanimelist.net/
|
||||
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 malNick == "" {
|
||||
avatarLog.Error("MAL", user.Nick, "No MAL nick")
|
||||
malLog.Error(user.Nick, "No MAL nick")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -31,12 +32,12 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar {
|
||||
response, xml, networkErr := gorequest.New().Get(userInfoURL).End()
|
||||
|
||||
if networkErr != nil {
|
||||
avatarLog.Error("MAL", user.Nick, userInfoURL, networkErr)
|
||||
malLog.Error(user.Nick, userInfoURL, networkErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
avatarLog.Error("MAL", user.Nick, userInfoURL, response.StatusCode)
|
||||
malLog.Error(user.Nick, userInfoURL, response.StatusCode)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -44,7 +45,7 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar {
|
||||
matches := userIDRegex.FindStringSubmatch(xml)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ const (
|
||||
|
||||
var avatarSources []AvatarSource
|
||||
var avatarOutputs []AvatarOutput
|
||||
var avatarLog = log.NewChannel("avatar")
|
||||
var avatarLog = log.NewLog()
|
||||
|
||||
// Main
|
||||
func main() {
|
||||
|
Loading…
Reference in New Issue
Block a user