kunt

golang IRC bot
git clone git://git.2f30.org/kunt
Log | Files | Refs | LICENSE

commit ecaf60dcb1fdf4df73e9ac41a20cfdf800cd5e05
parent 43af7c024ddfcf37ea8e194282a4ac867f1e4ce8
Author: sin <sin@2f30.org>
Date:   Fri, 10 May 2013 15:21:15 +0100

add dispatchHandler()

Diffstat:
Msrc/irc/events.go | 11+++++++++++
Msrc/irc/message.go | 9+--------
2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/irc/events.go b/src/irc/events.go @@ -38,3 +38,14 @@ func (i *Context) DelEventHandler(ev *Event) error { } return fmt.Errorf("Event handler not found") } + +func (i *Context) dispatchHandler(msg Message) { + i.Lock() + defer i.Unlock() + for _, v := range i.ev { + if v.Command == msg.Command { + v.Fn(msg) + break + } + } +} diff --git a/src/irc/message.go b/src/irc/message.go @@ -189,14 +189,7 @@ func (i *Context) incomingMsgLoop() error { if !ok { return nil } - // Check if the user has registered - // a callback for this message - for _, v := range i.ev { - if v.Command == msg.Command { - v.Fn(msg) - break - } - } + i.dispatchHandler(msg) } } return nil