kunt

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

commit 88606e76531ffb55531fefcf968dce4a0c0f6b6c
parent cabbd46bc4d57000ce233de19546fb1048074783
Author: sin <sin@2f30.org>
Date:   Fri,  3 May 2013 12:42:54 +0100

update irc

Diffstat:
Msrc/irc/events.go | 16++++++++--------
Msrc/irc/irc.go | 8++++----
Msrc/irc/message.go | 5+++++
3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/irc/events.go b/src/irc/events.go @@ -1,5 +1,9 @@ package irc +import ( + "fmt" +) + const ( MAX_EVENTS = 16 ) @@ -9,21 +13,17 @@ type IrcEvent struct { Fn func(IrcMessage) } -func (i *IrcContext) AddEventHandler(ev IrcEvent) int { +func (i *IrcContext) AddEventHandler(ev IrcEvent) { i.ev = append(i.ev, ev) i.evnum++ - return 0 } -func (i *IrcContext) DelEventHandler(ev *IrcEvent) int { - if i.evnum == 0 { - return -1 //empty - } +func (i *IrcContext) DelEventHandler(ev *IrcEvent) error { for j := 0; j < i.evnum; j++ { if &i.ev[j] == ev { i.ev = append(i.ev[:j], i.ev[j+1:]...) - return 0 + return nil } } - return -1 + return fmt.Errorf("Event handler not found") } diff --git a/src/irc/irc.go b/src/irc/irc.go @@ -73,18 +73,18 @@ func (i *IrcContext) AddIntercept(a *chan IrcMessage) { } // Deletes based on pointer equality. caller must hold ref. -func (i *IrcContext) DelIntercept(ap *chan IrcMessage) int { +func (i *IrcContext) DelIntercept(ap *chan IrcMessage) error { for j := 0; j < len(i.intercepts); j++ { if ap == i.intercepts[j] { if j == 0 { i.intercepts = make([]*chan IrcMessage, 0) - return 0 + return nil } i.intercepts = append(i.intercepts[:j], i.intercepts[j+1:]...) - return 0 + return nil } } - return -1 //not found + return fmt.Errorf("Intercept not found") } // Add a channel to the set of channels diff --git a/src/irc/message.go b/src/irc/message.go @@ -12,6 +12,11 @@ type IrcMessage struct { Args []string } +const ( + IRCARG0 = iota + IRCTEXT +) + // Send the nickname func (i *IrcContext) Nick() { msg := IrcMessage{