diff --git a/main.go b/main.go index ca584e1..7978680 100644 --- a/main.go +++ b/main.go @@ -9,16 +9,18 @@ import ( ) func connect() { - err := client.Login("509851616216875019") - if err != nil { - fmt.Printf("[%s] %s\n", time.Now().Format(time.RFC3339), err) - fmt.Printf("[%s] Connection failed, retrying in 30 seconds\n", time.Now().Format(time.RFC3339)) - time.Sleep(30 * time.Second) - connect() - } else { - setActivity() - for range time.Tick(time.Hour) { - go setActivity() + for { + err := client.Login("509851616216875019") + if err != nil { + fmt.Printf("[%s] %s\n", time.Now().Format(time.RFC3339), err) + fmt.Printf("[%s] Connection failed, retrying in 30 seconds\n", time.Now().Format(time.RFC3339)) + time.Sleep(30 * time.Second) + } else { + setActivity() + for range time.Tick(time.Hour) { + go setActivity() + } + break } } } @@ -29,7 +31,7 @@ func setActivity() { format := "2006-01-02T15:04:05" year := now.Year() if now.Month() == 12 && now.Day() > 25 { - year += 1 + year++ } christmas, err := time.Parse(format, fmt.Sprintf("%d-12-25T00:00:00", year)) if err != nil { @@ -37,12 +39,20 @@ func setActivity() { } diff := christmas.Unix() - now.Unix() sleeps := int64(math.Ceil(float64(diff) / 60 / 60 / 24)) - details := fmt.Sprintf("%d sleeps left", sleeps) + + var details string + if sleeps > 1 { + details = fmt.Sprintf("%d sleeps left", sleeps) + } else { + details = fmt.Sprintf("%d sleep left", sleeps) + } + state := "until Christmas" if now.Month() == 12 && now.Day() == 25 { details = "It's Christmas Day!" state = "Merry Christmas!" } + err = client.SetActivity(client.Activity{ State: state, Details: details,