From dcec8549b4a91863d6f8820582bd757447a6b408 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 21 Sep 2015 23:27:29 +0200 Subject: Move Help() into interface{} --- command.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'command.go') diff --git a/command.go b/command.go index e4ee147..b2bdb59 100644 --- a/command.go +++ b/command.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "strings" "time" @@ -11,15 +10,13 @@ import ( type Commander interface { irc.Handler - fmt.Stringer Timeout(string) bool WithArgs(int) bool + Help() string } type Command struct { - Help string - Arg string - Last map[string]time.Time + last map[string]time.Time } var commands = make(map[string]Commander) @@ -28,13 +25,12 @@ func Register(cmd string, f Commander) { commands[cmd] = f } -func (v Command) String() string { return v.Help } func (v *Command) Timeout(nick string) bool { - defer func() { v.Last[nick] = time.Now() }() - if v.Last == nil { - v.Last = make(map[string]time.Time) + defer func() { v.last[nick] = time.Now() }() + if v.last == nil { + v.last = make(map[string]time.Time) } - if last, ok := v.Last[nick]; ok { + if last, ok := v.last[nick]; ok { if to := time.Since(last); to < 5*time.Second { log.Println(nick, "timeout", to) return true -- cgit v1.2.3