From 7c1c2ffad83317bcab14e90f124a64882c99a5e4 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 28 Sep 2015 18:41:59 +0200 Subject: Store last city --- command.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'command.go') diff --git a/command.go b/command.go index b2bdb59..cd34b7e 100644 --- a/command.go +++ b/command.go @@ -16,7 +16,7 @@ type Commander interface { } type Command struct { - last map[string]time.Time + lastCmd map[string]time.Time } var commands = make(map[string]Commander) @@ -25,13 +25,15 @@ func Register(cmd string, f Commander) { commands[cmd] = f } +const timeOut = 5 * time.Second + 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.lastCmd[nick] = time.Now() }() + if v.lastCmd == nil { + v.lastCmd = make(map[string]time.Time) } - if last, ok := v.last[nick]; ok { - if to := time.Since(last); to < 5*time.Second { + if last, ok := v.lastCmd[nick]; ok { + if to := time.Since(last); to < timeOut { log.Println(nick, "timeout", to) return true } -- cgit v1.2.3