From ce3d88f4a4bc92fe6f989d20fd1c24609548972b Mon Sep 17 00:00:00 2001 From: Caleb Denio Date: Fri, 15 Jul 2022 13:49:02 -0400 Subject: [PATCH] kog detection --- pkg/jia/handlers.go | 21 +++++++++++++++++++++ pkg/jia/server.go | 1 + 2 files changed, 22 insertions(+) diff --git a/pkg/jia/handlers.go b/pkg/jia/handlers.go index 8c71483..074cc64 100644 --- a/pkg/jia/handlers.go +++ b/pkg/jia/handlers.go @@ -8,6 +8,7 @@ import ( "regexp" "sort" "strconv" + "strings" "time" "github.com/slack-go/slack" @@ -89,10 +90,30 @@ func onMessage(slackClient *slack.Client, event *slackevents.MessageEvent) { 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! redisClient.Set("last_valid_number", matchedNumber, 0) redisClient.Set("last_valid_ts", event.TimeStamp, 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 now := time.Now().UTC() diff --git a/pkg/jia/server.go b/pkg/jia/server.go index cdf6be6..16b6c02 100644 --- a/pkg/jia/server.go +++ b/pkg/jia/server.go @@ -29,6 +29,7 @@ func StartServer(config *Config) { // Initialize default values redisClient.SetNX("last_sender_id", "", 0) redisClient.SetNX("last_valid_number", 0, 0) + redisClient.SetNX("last_count_at", 0, 0) // Initialize Slack app slackClient = slack.New(config.BotToken)