summaryrefslogtreecommitdiff
path: root/internal/flood
diff options
context:
space:
mode:
Diffstat (limited to 'internal/flood')
-rw-r--r--internal/flood/flood.go19
-rw-r--r--internal/flood/flood_test.go23
2 files changed, 4 insertions, 38 deletions
diff --git a/internal/flood/flood.go b/internal/flood/flood.go
index b16b948..fce81ae 100644
--- a/internal/flood/flood.go
+++ b/internal/flood/flood.go
@@ -4,7 +4,6 @@ import (
"math"
"sort"
"strings"
- "unicode"
"unicode/utf8"
)
@@ -18,15 +17,15 @@ type Kicker interface {
Kick(nick string, message ...string)
}
-type Checker struct {
+type Check struct {
k Kicker
}
-func New(k Kicker) *Checker {
- return &Checker{k: k}
+func New(k Kicker) *Check {
+ return &Check{k: k}
}
-func (c Checker) Check(text, nick string) {
+func (c Check) Check(text, nick string) {
if isFlood(text) {
c.k.Kick(nick)
}
@@ -68,13 +67,3 @@ func commonWord(v []string) int {
sort.Sort(sort.Reverse(sort.IntSlice(l)))
return l[0]
}
-
-func noSpaceCompare(a, b string) bool {
- dropSpaces := func(r rune) rune {
- if unicode.IsSpace(r) {
- return -1
- }
- return r
- }
- return strings.Map(dropSpaces, a) == strings.Map(dropSpaces, b)
-}
diff --git a/internal/flood/flood_test.go b/internal/flood/flood_test.go
index a09a3c4..1874254 100644
--- a/internal/flood/flood_test.go
+++ b/internal/flood/flood_test.go
@@ -26,26 +26,3 @@ func TestFlood(t *testing.T) {
})
}
}
-
-func TestNoSpaceCompare(t *testing.T) {
- testCases := []struct {
- a, b string
- ok bool
- }{
- {"", "", true},
- {"x", "", false},
- {"", "x", false},
- {"x ", "x", true},
- {" x", "x", true},
- {"x x", "xx", true},
- {"x x x", "x", false},
- }
- for _, tc := range testCases {
- t.Run(tc.a+"?"+tc.b, func(t *testing.T) {
- ok := noSpaceCompare(tc.a, tc.b)
- if ok != tc.ok {
- t.Errorf("got %v; want %v", ok, tc.ok)
- }
- })
- }
-}