mirror of
https://github.com/cjdenio/jia.git
synced 2024-11-22 07:33:39 +00:00
Track users' monthly count
This commit is contained in:
parent
5c91f310f7
commit
25444a398d
1 changed files with 9 additions and 1 deletions
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue