diff --git a/client/client.go b/client/client.go index d8d591f..64545b3 100644 --- a/client/client.go +++ b/client/client.go @@ -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)