From 460bac780774bb582153313d06f67f331d18506f Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 21 Mar 2016 21:46:14 +0100 Subject: Reduce interface --- blame.go | 2 +- command.go | 14 ++------------ duck.go | 2 +- help.go | 2 +- ivy.go | 6 +----- last.go | 2 +- rfc.go | 3 +-- urban.go | 4 +--- 8 files changed, 9 insertions(+), 26 deletions(-) diff --git a/blame.go b/blame.go index c122028..85059ff 100644 --- a/blame.go +++ b/blame.go @@ -4,7 +4,7 @@ import ( irc "github.com/fluffle/goirc/client" ) -type Blame struct{ Command } +type Blame struct{} func (_ Blame) Handle(conn *irc.Conn, line *irc.Line) { src := []string{ diff --git a/command.go b/command.go index 45bbef0..4fb08a5 100644 --- a/command.go +++ b/command.go @@ -3,37 +3,27 @@ package main import ( "log" "strings" - "time" irc "github.com/fluffle/goirc/client" ) type Commander interface { irc.Handler - WithArgs(int) bool Help() string } -type Command struct { - lastCmd map[string]time.Time -} - var commands = make(map[string]Commander) func Register(cmd string, f Commander) { commands[cmd] = f } -func (_ Command) WithArgs(n int) bool { return n == 1 } - func Dispatch(conn *irc.Conn, line *irc.Line) { if f := strings.Fields(line.Text()); len(f) > 0 { cmd := strings.ToLower(f[0]) if c, ok := commands[cmd]; ok { - if c.WithArgs(len(f)) { - log.Println(line.Nick, f) - c.Handle(conn, line) - } + log.Println(line.Nick, f) + c.Handle(conn, line) } } } diff --git a/duck.go b/duck.go index f9f33f9..7c534b0 100644 --- a/duck.go +++ b/duck.go @@ -7,7 +7,7 @@ import ( irc "github.com/fluffle/goirc/client" ) -type Duck struct{ Command } +type Duck struct{} func (_ Duck) WithArgs(_ int) bool { return true } diff --git a/help.go b/help.go index dc01cdf..1aaf444 100644 --- a/help.go +++ b/help.go @@ -7,7 +7,7 @@ import ( irc "github.com/fluffle/goirc/client" ) -type Help struct{ Command } +type Help struct{} func (_ Help) Handle(conn *irc.Conn, line *irc.Line) { var msg []string diff --git a/ivy.go b/ivy.go index 66c07e7..7b2ff70 100644 --- a/ivy.go +++ b/ivy.go @@ -7,11 +7,7 @@ import ( ivy "robpike.io/ivy/mobile" ) -type Ivy struct { - Command -} - -func (_ Ivy) WithArgs(_ int) bool { return true } +type Ivy struct{} func (_ Ivy) Handle(conn *irc.Conn, line *irc.Line) { switch q := strings.SplitN(line.Text(), " ", 2); len(q) { diff --git a/last.go b/last.go index e7486ee..7218330 100644 --- a/last.go +++ b/last.go @@ -7,7 +7,7 @@ import ( irc "github.com/fluffle/goirc/client" ) -type Last struct{ Command } +type Last struct{} var buffer = ring.New(10) diff --git a/rfc.go b/rfc.go index 9dffede..9ec363d 100644 --- a/rfc.go +++ b/rfc.go @@ -9,14 +9,13 @@ import ( irc "github.com/fluffle/goirc/client" ) -type RFC struct{ Command } +type RFC struct{} var ( rfcMap = make(map[int]rfc.Entry) rfcKW = make(map[string][]string) ) -func (_ RFC) WithArgs(n int) bool { return n == 2 } func (_ RFC) Handle(conn *irc.Conn, line *irc.Line) { if f := strings.Fields(line.Text()); len(f) > 1 { kw := strings.ToLower(f[1]) diff --git a/urban.go b/urban.go index 3a3aab7..680bf13 100644 --- a/urban.go +++ b/urban.go @@ -8,9 +8,7 @@ import ( irc "github.com/fluffle/goirc/client" ) -type Urban struct{ Command } - -func (_ Urban) WithArgs(_ int) bool { return true } +type Urban struct{} func (_ Urban) Handle(conn *irc.Conn, line *irc.Line) { if q := strings.SplitN(line.Text(), " ", 2); len(q) == 2 { -- cgit v1.2.3