summaryrefslogtreecommitdiff
path: root/command.go
blob: 9f20c45cd9edcc76926585f8a634901d56cb17a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
	"fmt"
	"log"
	"strings"

	irc "github.com/fluffle/goirc/client"
)

type Commander interface {
	irc.Handler
	fmt.Stringer
}

const maxLen = 500

var commands = make(map[string]Commander)

func Register(cmd string, f Commander) {
	commands[cmd] = f
}

func Dispatch(conn *irc.Conn, line *irc.Line) {
	if f := strings.Fields(line.Text()); len(f) > 0 {
		cmd := strings.ToLower(f[0])
		if c, ok := commands[cmd]; ok {
			log.Println(line.Nick, f)
			c.Handle(conn, line)
		}
	}
}