summaryrefslogtreecommitdiff
path: root/internal/flood
diff options
context:
space:
mode:
Diffstat (limited to 'internal/flood')
-rw-r--r--internal/flood/flood.go20
-rw-r--r--internal/flood/flood_test.go2
2 files changed, 20 insertions, 2 deletions
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)
}
})