Add basic command handler
This commit is contained in:
parent
be1bb797f4
commit
edcbd2035a
@ -18,6 +18,8 @@ import (
|
||||
"github.com/goshuirc/irc-go/ircmsg"
|
||||
)
|
||||
|
||||
var basicCmdPrefixes = []byte{'!', '@', '~', '.', '$'}
|
||||
|
||||
// ServerConnection is a connection to a single server.
|
||||
type ServerConnection struct {
|
||||
Name string
|
||||
@ -176,6 +178,10 @@ func (sc *ServerConnection) ProcessIncomingLine(line string) {
|
||||
|
||||
// IRC commands are case-insensitive
|
||||
sc.dispatchIn(strings.ToUpper(cmd), info)
|
||||
if strings.ToUpper(cmd) == "PRIVMSG" {
|
||||
sc.dispatchBasicCmd(info)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Disconnect closes the IRC socket.
|
||||
@ -273,6 +279,18 @@ func (sc *ServerConnection) Send(tags map[string]string, prefix string, command
|
||||
return nil
|
||||
}
|
||||
|
||||
// dispatchCommand dispatches an event based on simple commands (e.g !help)
|
||||
func (sc *ServerConnection) dispatchBasicCmd(info eventmgr.InfoMap) {
|
||||
cmd := info["params"].([]string)
|
||||
pfx := cmd[1][0]
|
||||
|
||||
for _, p := range basicCmdPrefixes {
|
||||
if pfx == p {
|
||||
sc.eventsIn.Dispatch("cmd"+cmd[1], info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dispatchRawIn dispatches raw inbound messages.
|
||||
func (sc *ServerConnection) dispatchRawIn(info eventmgr.InfoMap) {
|
||||
sc.eventsIn.Dispatch("raw", info)
|
||||
|
Loading…
Reference in New Issue
Block a user