From 090d2fae173d241ee93966e6c6aa95e7d0ec9e86 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 6 Jul 2019 18:34:01 +0200 Subject: simplify --- internal/flood/flood.go | 20 +++++++++++++++++++- internal/flood/flood_test.go | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'internal/flood') diff --git a/internal/flood/flood.go b/internal/flood/flood.go index b8a71d1..b16b948 100644 --- a/internal/flood/flood.go +++ b/internal/flood/flood.go @@ -14,6 +14,24 @@ const ( black = "\u24B6\u262D\u272F\u262E\u2721\u5350\u534D\u2719\u0FD5\u0FD6\u16CB\uA5A6\u0FD7\u0FD8" ) +type Kicker interface { + Kick(nick string, message ...string) +} + +type Checker struct { + k Kicker +} + +func New(k Kicker) *Checker { + return &Checker{k: k} +} + +func (c Checker) Check(text, nick string) { + if isFlood(text) { + c.k.Kick(nick) + } +} + func entropy(s string) (e float64) { n := make(map[rune]float64) for _, r := range s { @@ -25,7 +43,7 @@ func entropy(s string) (e float64) { return e } -func Is(s string) bool { +func isFlood(s string) bool { if strings.ContainsAny(s, black) { return true } diff --git a/internal/flood/flood_test.go b/internal/flood/flood_test.go index c16da7c..a09a3c4 100644 --- a/internal/flood/flood_test.go +++ b/internal/flood/flood_test.go @@ -20,7 +20,7 @@ func TestFlood(t *testing.T) { } for _, tc := range testCases { t.Run(tc.line, func(t *testing.T) { - if Is(tc.line) != tc.ok { + if isFlood(tc.line) != tc.ok { t.Errorf("want %v", tc.ok) } }) -- cgit v1.2.3