summaryrefslogtreecommitdiff
path: root/internal/fix/fix.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/fix/fix.go')
-rw-r--r--internal/fix/fix.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/internal/fix/fix.go b/internal/fix/fix.go
index 2a83a28..a1c1c2d 100644
--- a/internal/fix/fix.go
+++ b/internal/fix/fix.go
@@ -13,23 +13,34 @@ import (
var errNotRE = errors.New("not re")
type Fix struct {
- last *lru.Cache
- w io.Writer
+ cache *lru.Cache
+ w io.Writer
+}
+
+func (f Fix) get(nick string) (string, bool) {
+ if text, ok := f.cache.Get(nick); ok {
+ return text.(string), true
+ }
+ return "", false
+}
+
+func (f Fix) set(nick, text string) {
+ f.cache.Add(nick, text)
}
func New(w io.Writer) *Fix {
- last, _ := lru.New(100)
- return &Fix{last: last, w: w}
+ cache, _ := lru.New(100)
+ return &Fix{cache: cache, w: w}
}
-func (f *Fix) Fix(text, nick string) {
- defer f.last.Add(nick, text)
+func (f Fix) Fix(text, nick string) {
+ defer f.set(nick, text)
if !strings.HasPrefix(text, "s") {
return
}
- if tofix, ok := f.last.Get(nick); ok {
+ if tofix, ok := f.get(nick); ok {
global := strings.HasSuffix(text, "g")
- fixed, err := replace(tofix.(string), text[1:], global)
+ fixed, err := replace(tofix, text[1:], global)
if err == nil && fixed != tofix {
fmt.Fprintf(f.w, "%v meant to say: %s", nick, fixed)
}