Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit eb2a2eaae880ecbc3cea56f642359cc69c10df4e Author: Wim <wim@42.be> Date: Sat Apr 08 00:42:37 2017 +0000 Rejoin channel when kicked (irc). Closes #146 diff --git a/bridge/config/config.go b/bridge/config/config.go index 564ebdd..7827416 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -108 +109 @@ import (  )    const ( - EVENT_JOIN_LEAVE = "join_leave" - EVENT_FAILURE = "failure" + EVENT_JOIN_LEAVE = "join_leave" + EVENT_FAILURE = "failure" + EVENT_REJOIN_CHANNELS = "rejoin_channels"  )    type Message struct { diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index b1041f2..8f72f0f 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -16714 +16719 @@ func (b *Birc) handleNewConnection(event *irc.Event) {   i.AddCallback("JOIN", b.handleJoinPart)   i.AddCallback("PART", b.handleJoinPart)   i.AddCallback("QUIT", b.handleJoinPart) + i.AddCallback("KICK", b.handleJoinPart)   i.AddCallback("*", b.handleOther)   // we are now fully connected   b.connected <- struct{}{}  }    func (b *Birc) handleJoinPart(event *irc.Event) { - flog.Debugf("Sending JOIN_LEAVE event from %s to gateway", b.Account)   channel := event.Arguments[0] + if event.Code == "KICK" { + flog.Infof("Got kicked from %s by %s", channel, event.Nick) + b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: channel, Account: b.Account, Event: config.EVENT_REJOIN_CHANNELS} + return + }   if event.Code == "QUIT" {   if event.Nick == b.Nick && strings.Contains(event.Raw, "Ping timeout") {   flog.Infof("%s reconnecting ..", b.Account) @@ -1826 +1877 @@ func (b *Birc) handleJoinPart(event *irc.Event) {   return   }   } + flog.Debugf("Sending JOIN_LEAVE event from %s to gateway", b.Account)   b.Remote <- config.Message{Username: "system", Text: event.Nick + " " + strings.ToLower(event.Code) + "s", Channel: channel, Account: b.Account, Event: config.EVENT_JOIN_LEAVE}   flog.Debugf("handle %#v", event)  } diff --git a/gateway/gateway.go b/gateway/gateway.go index 140bfc4..b550430 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -1036 +10315 @@ func (gw *Gateway) handleReceive() {   }   }   } + if msg.Event == config.EVENT_REJOIN_CHANNELS { + for _, br := range gw.Bridges { + if msg.Account == br.Account { + br.Joined = make(map[string]bool) + br.JoinChannels() + } + } + continue + }   if !gw.ignoreMessage(&msg) {   msg.Timestamp = time.Now()   for _, br := range gw.Bridges {