limit requests
This commit is contained in:
parent
9f71865570
commit
79f7b617da
|
@ -30,7 +30,7 @@ type TwitchFollower struct {
|
||||||
FollowedAt time.Time `json:"followed_at"`
|
FollowedAt time.Time `json:"followed_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFollows(u *User) {
|
func getFollows(u *User, max int) {
|
||||||
result := &TwitchFollowers{}
|
result := &TwitchFollowers{}
|
||||||
|
|
||||||
after := ""
|
after := ""
|
||||||
|
@ -64,6 +64,11 @@ func getFollows(u *User) {
|
||||||
if t.Pagination == nil || t.Pagination.Cursor == "" {
|
if t.Pagination == nil || t.Pagination.Cursor == "" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if max > -1 && len(result.Data) >= max {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
after = "&after=" + t.Pagination.Cursor
|
after = "&after=" + t.Pagination.Cursor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
21
main.go
21
main.go
|
@ -48,7 +48,12 @@ func main() {
|
||||||
if user != nil {
|
if user != nil {
|
||||||
handleSaves()
|
handleSaves()
|
||||||
}
|
}
|
||||||
c := time.Tick(20 * time.Second)
|
interval := 20 * time.Second
|
||||||
|
if settings.UpdateInterval > 10*time.Second {
|
||||||
|
interval = settings.UpdateInterval
|
||||||
|
}
|
||||||
|
log.Infof("Update interval: %s", interval)
|
||||||
|
c := time.Tick(interval)
|
||||||
for range c {
|
for range c {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
continue
|
continue
|
||||||
|
@ -77,12 +82,22 @@ func handleSaves() {
|
||||||
user.TwitchChannel.SaveFiles()
|
user.TwitchChannel.SaveFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
getFollows(user)
|
maxFollower := -1
|
||||||
|
if settings.MaxFollowers > 0 {
|
||||||
|
maxFollower = settings.MaxFollowers
|
||||||
|
}
|
||||||
|
log.Infof("Fetch max follower: %d", maxFollower)
|
||||||
|
getFollows(user, maxFollower)
|
||||||
if user.TwitchFollowers != nil {
|
if user.TwitchFollowers != nil {
|
||||||
user.TwitchFollowers.SaveFiles()
|
user.TwitchFollowers.SaveFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
getSubs(user)
|
maxSubs := -1
|
||||||
|
if settings.MaxSubs > 0 {
|
||||||
|
maxSubs = settings.MaxSubs
|
||||||
|
}
|
||||||
|
log.Infof("Fetch max subs: %d", maxSubs)
|
||||||
|
getSubs(user, maxSubs)
|
||||||
if user.TwitchSubscriptions != nil {
|
if user.TwitchSubscriptions != nil {
|
||||||
user.TwitchSubscriptions.SaveFiles()
|
user.TwitchSubscriptions.SaveFiles()
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,10 @@ var (
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
ClientID string `yaml:"client_id"`
|
ClientID string `yaml:"client_id"`
|
||||||
ClientSecret string `yaml:"client_secret"`
|
ClientSecret string `yaml:"client_secret"`
|
||||||
|
MaxFollowers int `yaml:"max_followers"`
|
||||||
|
MaxSubs int `yaml:"max_subs"`
|
||||||
RedirectURL string `yaml:"redirect_url"`
|
RedirectURL string `yaml:"redirect_url"`
|
||||||
|
UpdateInterval time.Duration `yaml:"update_interval"`
|
||||||
VerificationToken string `yaml:"verification_token"`
|
VerificationToken string `yaml:"verification_token"`
|
||||||
WebserverPort string `yaml:"webserver_port"`
|
WebserverPort string `yaml:"webserver_port"`
|
||||||
}
|
}
|
||||||
|
|
5
subs.go
5
subs.go
|
@ -37,7 +37,7 @@ type TwitchSubUser struct {
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSubs(u *User) {
|
func getSubs(u *User, max int) {
|
||||||
result := &TwitchSubscriptions{}
|
result := &TwitchSubscriptions{}
|
||||||
|
|
||||||
limit := 100
|
limit := 100
|
||||||
|
@ -74,6 +74,9 @@ func getSubs(u *User) {
|
||||||
result.Total = t.Total
|
result.Total = t.Total
|
||||||
result.Subscriptions = append(result.Subscriptions, t.Subscriptions...)
|
result.Subscriptions = append(result.Subscriptions, t.Subscriptions...)
|
||||||
|
|
||||||
|
if max > -1 && len(result.Subscriptions) >= max {
|
||||||
|
break
|
||||||
|
}
|
||||||
offset += limit
|
offset += limit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user