Move logic into isRecent function

This commit is contained in:
ekzyis 2024-10-16 19:11:59 +02:00
parent ca2ccc569d
commit bd24198b05
1 changed files with 7 additions and 6 deletions

13
main.go
View File

@ -44,9 +44,7 @@ func tickGameStart(c *sn.Client) {
for _, n := range mentions {
// we only care about current notifications
x := time.Now().Add(-30 * time.Second)
if n.Item.CreatedAt.Before(x) {
if !isRecent(n.Item.CreatedAt) {
log.Printf("ignoring old mention %d\n", n.Item.Id)
continue
}
@ -95,9 +93,7 @@ func tickGameProgress(c *sn.Client) {
for _, n := range replies {
// we only care about current notifications
x := time.Now().Add(-30 * time.Second)
if n.Item.CreatedAt.Before(x) {
if !isRecent(n.Item.CreatedAt) {
log.Printf("ignoring old reply %d\n", n.Item.Id)
continue
}
@ -295,3 +291,8 @@ func parseGameProgress(input string) (string, error) {
return "", errors.New("failed to parse game update")
}
func isRecent(t time.Time) bool {
x := time.Now().Add(-30 * time.Second)
return t.After(x)
}