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