Skip to content

Commit

Permalink
🤞 Merge pull request #4 from creeperita09/main
Browse files Browse the repository at this point in the history
Update main.go
  • Loading branch information
eartharoid authored Jun 30, 2024
2 parents 03705af + 9fb54dc commit 45631ea
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand All @@ -29,20 +31,28 @@ 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 {
panic(err)
}
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,
Expand Down

0 comments on commit 45631ea

Please sign in to comment.