Track users' monthly count

This commit is contained in:
Caleb Denio 2020-11-11 12:33:37 -05:00
parent 5c91f310f7
commit 25444a398d

View file

@ -5,6 +5,7 @@ import (
"log" "log"
"regexp" "regexp"
"strconv" "strconv"
"time"
"github.com/slack-go/slack" "github.com/slack-go/slack"
"github.com/slack-go/slack/slackevents" "github.com/slack-go/slack/slackevents"
@ -14,7 +15,6 @@ func HandleInnerEvent(slackClient *slack.Client, innerEvent *slackevents.EventsA
switch e := innerEvent.Data.(type) { switch e := innerEvent.Data.(type) {
case *slackevents.MessageEvent: case *slackevents.MessageEvent:
onMessage(slackClient, e) onMessage(slackClient, e)
break
} }
} }
@ -80,4 +80,12 @@ func onMessage(slackClient *slack.Client, event *slackevents.MessageEvent) {
// Finally! // Finally!
redisClient.Set("last_valid_number", matchedNumber, 0) redisClient.Set("last_valid_number", matchedNumber, 0)
redisClient.Set("last_sender_id", event.User, 0) redisClient.Set("last_sender_id", event.User, 0)
// Get the current month/year in UTC
now := time.Now().UTC()
year := now.Year()
month := now.Month()
// Increment the person's monthly count
redisClient.Incr(fmt.Sprintf("%d-%d:%s", month, year, event.User))
} }