kog detection

This commit is contained in:
Caleb Denio 2022-07-15 13:49:02 -04:00
parent 3342f3ed4a
commit ce3d88f4a4
No known key found for this signature in database
GPG key ID: D2E75BDDE8F717AD
2 changed files with 22 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import (
"regexp" "regexp"
"sort" "sort"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/slack-go/slack" "github.com/slack-go/slack"
@ -89,10 +90,30 @@ func onMessage(slackClient *slack.Client, event *slackevents.MessageEvent) {
return return
} }
// kog detection
lastCountAtInt, err := redisClient.Get("last_count_at").Int64()
if err != nil {
log.Println(err)
}
lastCountAt := time.Unix(lastCountAtInt, 0)
if event.User == "UR6P49Q79" && time.Since(lastCountAt).Seconds() < 2 && strings.Contains(lastValidNumberStr, "69") {
slackClient.AddReaction("bangbang", slack.ItemRef{
Channel: event.Channel,
Timestamp: event.TimeStamp,
})
slackClient.AddReaction("robot_face", slack.ItemRef{
Channel: event.Channel,
Timestamp: event.TimeStamp,
})
return
}
// Finally! // Finally!
redisClient.Set("last_valid_number", matchedNumber, 0) redisClient.Set("last_valid_number", matchedNumber, 0)
redisClient.Set("last_valid_ts", event.TimeStamp, 0) redisClient.Set("last_valid_ts", event.TimeStamp, 0)
redisClient.Set("last_sender_id", event.User, 0) redisClient.Set("last_sender_id", event.User, 0)
redisClient.Set("last_count_at", time.Now().Unix(), 0)
// Get the current month/year in UTC // Get the current month/year in UTC
now := time.Now().UTC() now := time.Now().UTC()

View file

@ -29,6 +29,7 @@ func StartServer(config *Config) {
// Initialize default values // Initialize default values
redisClient.SetNX("last_sender_id", "", 0) redisClient.SetNX("last_sender_id", "", 0)
redisClient.SetNX("last_valid_number", 0, 0) redisClient.SetNX("last_valid_number", 0, 0)
redisClient.SetNX("last_count_at", 0, 0)
// Initialize Slack app // Initialize Slack app
slackClient = slack.New(config.BotToken) slackClient = slack.New(config.BotToken)