Remove some logging, update comments

This commit is contained in:
Victor Truong 2020-07-30 03:27:43 -07:00
parent 567cb76f96
commit d07d84c60e

View file

@ -19,19 +19,17 @@ func HandleInnerEvent(slackClient *slack.Client, innerEvent *slackevents.EventsA
} }
func onMessage(slackClient *slack.Client, event *slackevents.MessageEvent) { func onMessage(slackClient *slack.Client, event *slackevents.MessageEvent) {
// Ignore messages that aren't in the target channel, or are non-user messages // Ignore messages that aren't in the target channel, or are non-user messages.
if event.Channel != jiaConfig.ChannelID || event.User == "USLACKBOT" || event.User == "" { if event.Channel != jiaConfig.ChannelID || event.User == "USLACKBOT" || event.User == "" {
return return
} }
// Attempt to extract a positive number from the beginning of a string // Attempt to extract a positive number at the start of a string.
countPattern := regexp.MustCompile(`^\d+`) countPattern := regexp.MustCompile(`^\d+`)
matchedNumber, err := strconv.Atoi(countPattern.FindString(event.Text)) matchedNumber, err := strconv.Atoi(countPattern.FindString(event.Text))
log.Println(matchedNumber)
// Ignore messages that don't have numbers. // Ignore messages that don't have numbers.
if err != nil { if err != nil {
log.Println("Failed to retrieve number, skipping…")
return return
} }
@ -51,7 +49,7 @@ func onMessage(slackClient *slack.Client, event *slackevents.MessageEvent) {
return return
} }
// Ignore numbers that aren't in order. // Retrieve stored info about the last valid number and its sender.
lastValidNumberStr, err := redisClient.Get("last_valid_number").Result() lastValidNumberStr, err := redisClient.Get("last_valid_number").Result()
if err != nil { if err != nil {
log.Println("Failed to retrieve the last valid number") log.Println("Failed to retrieve the last valid number")
@ -62,6 +60,8 @@ func onMessage(slackClient *slack.Client, event *slackevents.MessageEvent) {
log.Println("Failed to convert the last valid number to an integer") log.Println("Failed to convert the last valid number to an integer")
return return
} }
// Ignore numbers that aren't in order.
if matchedNumber != lastValidNumber+1 { if matchedNumber != lastValidNumber+1 {
slackClient.AddReaction("bangbang", slack.ItemRef{ slackClient.AddReaction("bangbang", slack.ItemRef{
Channel: event.Channel, Channel: event.Channel,