From f22db3b8ba23c66dce23602c5e948aa7b6d5af31 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 21 Jul 2015 17:06:35 +0200 Subject: Split a bit --- command.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 command.go (limited to 'command.go') diff --git a/command.go b/command.go new file mode 100644 index 0000000..1dcb9f1 --- /dev/null +++ b/command.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "log" + "time" + + irc "github.com/fluffle/goirc/client" +) + +type Commander interface { + irc.Handler + fmt.Stringer + Timeout() bool + WithArgs(int) bool +} + +type Command struct { + Help string + Arg string + Last time.Time +} + +var commands = make(map[string]Commander) + +func Register(cmd string, f Commander) { + commands[cmd] = f +} + +func (v Command) String() string { return v.Help } +func (v *Command) Timeout() bool { + log.Println("timeout:", time.Since(v.Last)) + if time.Since(v.Last) > time.Minute { + v.Last = time.Now() + return false + } + return true +} +func (_ Command) WithArgs(n int) bool { return n == 1 } -- cgit v1.2.3