Requested changes

This commit is contained in:
Caleb Denio 2020-11-21 09:37:14 -05:00
parent a6ecd85fff
commit e3f8dd8ef1

View file

@ -90,7 +90,7 @@ func onMessage(slackClient *slack.Client, event *slackevents.MessageEvent) {
month := now.Month() month := now.Month()
// Increment the person's monthly count // Increment the person's monthly count
redisClient.Incr(fmt.Sprintf("leaderboard:%d-%d:%s", month, year, event.User)) redisClient.Incr(fmt.Sprintf("leaderboard:%d-%d:%s", year, month, event.User))
} }
func HandleLeaderboardSlashCommand(w http.ResponseWriter, r *http.Request) { func HandleLeaderboardSlashCommand(w http.ResponseWriter, r *http.Request) {
@ -99,13 +99,13 @@ func HandleLeaderboardSlashCommand(w http.ResponseWriter, r *http.Request) {
year := now.Year() year := now.Year()
month := now.Month() month := now.Month()
scan := redisClient.Scan(0, fmt.Sprintf("leaderboard:%d-%d:*", month, year), 10) scan := redisClient.Scan(0, fmt.Sprintf("leaderboard:%d-%d:*", year, month), 10)
if scan.Err() != nil { if scan.Err() != nil {
w.Write([]byte("Something went wrong while loading the leaderboard :cry: Please try again later!")) w.Write([]byte("Something went wrong while loading the leaderboard :cry: Please try again later!"))
return return
} }
scan_iterator := scan.Iterator() scanIterator := scan.Iterator()
type Entry struct { type Entry struct {
Number int Number int
@ -114,16 +114,16 @@ func HandleLeaderboardSlashCommand(w http.ResponseWriter, r *http.Request) {
entries := []Entry{} entries := []Entry{}
for scan_iterator.Next() { for scanIterator.Next() {
entry := redisClient.Get(scan_iterator.Val()) entry := redisClient.Get(scanIterator.Val())
entry_int, err := entry.Int() entryInt, err := entry.Int()
if err != nil { if err != nil {
return return
} }
if user, ok := parseLeaderboardEntry(scan_iterator.Val()); ok { if user, ok := parseLeaderboardEntry(scanIterator.Val()); ok {
entries = append(entries, Entry{ entries = append(entries, Entry{
Number: entry_int, Number: entryInt,
User: user, User: user,
}) })
} }