Skip to content

Commit

Permalink
Clear existing IRC event handlers before connecting to new ones
Browse files Browse the repository at this point in the history
Clear IRC event handlers that we will be registering for the new
connection before registering new handlers. This prevents duplicate
event handlers in the case where we are connecting via a BNC and are
seeing a reconnect. Attempting to clear handlers when none have been set
is a no-op.

Fixes #1564
Co-authored-by: Andreas Vögele <andreas@andreasvoegele.com>
  • Loading branch information
bd808 committed Apr 27, 2024
1 parent 56e7bd0 commit 59a09e1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bridge/irc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ func (b *Birc) handleNewConnection(client *girc.Client, event girc.Event) {
i := b.i
b.Nick = event.Params[0]

b.Log.Debug("Clearing handlers before adding in case of BNC reconnect")
i.Handlers.Clear("PRIVMSG")
i.Handlers.Clear("CTCP_ACTION")
i.Handlers.Clear(girc.RPL_TOPICWHOTIME)
i.Handlers.Clear(girc.NOTICE)
i.Handlers.Clear("JOIN")
i.Handlers.Clear("PART")
i.Handlers.Clear("QUIT")
i.Handlers.Clear("KICK")
i.Handlers.Clear("INVITE")

i.Handlers.AddBg("PRIVMSG", b.handlePrivMsg)
i.Handlers.AddBg("CTCP_ACTION", b.handlePrivMsg)
i.Handlers.Add(girc.RPL_TOPICWHOTIME, b.handleTopicWhoTime)
Expand Down

0 comments on commit 59a09e1

Please sign in to comment.