summaryrefslogtreecommitdiff
path: root/command.go
diff options
context:
space:
mode:
Diffstat (limited to 'command.go')
-rw-r--r--command.go14
1 files changed, 8 insertions, 6 deletions
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
}