From 78a4c71736d65563a3cf418ebf40f8dbd55c1083 Mon Sep 17 00:00:00 2001 From: Michael Jard Date: Sat, 21 May 2011 21:06:22 -0700 Subject: [PATCH 1/2] Add ability to silence callback handler --- irc.go | 1 + irc_callback.go | 7 +++++-- irc_struct.go | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/irc.go b/irc.go index 60872c8..410aadd 100644 --- a/irc.go +++ b/irc.go @@ -200,6 +200,7 @@ func IRC(nick, user string) *IRCConnection { irc.Error = make(chan os.Error) irc.nick = nick irc.user = user + irc.VerboseCallbackHandler = true irc.setupCallbacks() return irc } diff --git a/irc_callback.go b/irc_callback.go index ac9cfba..61592e2 100644 --- a/irc_callback.go +++ b/irc_callback.go @@ -49,11 +49,14 @@ func (irc *IRCConnection) RunCallbacks(event *IRCEvent) { } } if callbacks, ok := irc.events[event.Code]; ok { + if irc.VerboseCallbackHandler { + fmt.Printf("%v (%v) >> %#v\n", event.Code, len(callbacks), event) + } for _, callback := range callbacks { go callback(event) } - } else { - fmt.Printf("No callback for: %#v\n", event) + } else if irc.VerboseCallbackHandler { + fmt.Printf("%v (0) >> %#v\n", event.Code, event) } } diff --git a/irc_struct.go b/irc_struct.go index 23b6c09..8174018 100644 --- a/irc_struct.go +++ b/irc_struct.go @@ -26,6 +26,8 @@ type IRCConnection struct { ticker <-chan int64 ticker2 <-chan int64 + VerboseCallbackHandler bool + quitting bool } From 0a5d47140468856affa84b6a4c75eeec0e664071 Mon Sep 17 00:00:00 2001 From: Michael Jard Date: Sat, 21 May 2011 23:24:35 -0700 Subject: [PATCH 2/2] fix minor issue where bot tries to set its nick every 15 minutes, even if it has the wanted nick. --- irc.go | 1 + irc_callback.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/irc.go b/irc.go index 410aadd..e8c63f8 100644 --- a/irc.go +++ b/irc.go @@ -91,6 +91,7 @@ func pinger(i *IRCConnection) { i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds())) //Try to recapture nickname if it's not as configured. if i.nick != i.nickcurrent { + i.nickcurrent = i.nick i.SendRaw(fmt.Sprintf("NICK %s", i.nick)) } } diff --git a/irc_callback.go b/irc_callback.go index 61592e2..018fec5 100644 --- a/irc_callback.go +++ b/irc_callback.go @@ -110,4 +110,8 @@ func (irc *IRCConnection) setupCallbacks() { irc.nickcurrent = e.Arguments[0] } }) + + irc.AddCallback("001", func(e *IRCEvent) { + irc.nickcurrent = e.Arguments[0] + }) }