2017-06-13 11:23:54 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-06-13 15:06:30 +00:00
|
|
|
"time"
|
2017-06-13 11:23:54 +00:00
|
|
|
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
gravatar "github.com/ungerik/go-gravatar"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Gravatar - https://gravatar.com/
|
2017-06-13 15:06:30 +00:00
|
|
|
type Gravatar struct {
|
|
|
|
Rating string
|
|
|
|
RequestLimiter *time.Ticker
|
|
|
|
}
|
2017-06-13 11:23:54 +00:00
|
|
|
|
|
|
|
// GetAvatar returns the Gravatar image for a user (if available).
|
|
|
|
func (source *Gravatar) GetAvatar(user *arn.User) *Avatar {
|
|
|
|
// If the user has no Email registered we can't get a Gravatar.
|
|
|
|
if user.Email == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build URL
|
2017-06-13 15:06:30 +00:00
|
|
|
gravatarURL := gravatar.Url(user.Email) + "?s=" + fmt.Sprint(arn.AvatarMaxSize) + "&d=404&r=" + source.Rating
|
2017-06-13 11:23:54 +00:00
|
|
|
|
2017-06-13 15:06:30 +00:00
|
|
|
// Wait for request limiter to allow us to send a request
|
|
|
|
<-source.RequestLimiter.C
|
2017-06-13 11:23:54 +00:00
|
|
|
|
2017-06-13 15:06:30 +00:00
|
|
|
// Download
|
|
|
|
return AvatarFromURL(gravatarURL, user)
|
2017-06-13 11:23:54 +00:00
|
|
|
}
|