diff --git a/irc.go b/irc.go index 7a3d569..29d326e 100644 --- a/irc.go +++ b/irc.go @@ -61,6 +61,10 @@ func (i ircHandler) ExecuteJoins(channels []string) { } } +func (i ircHandler) ExecutePart(channel string) { + i.c.Write(fmt.Sprintf("PART #%s", strings.TrimLeft(channel, "#"))) +} + func (i ircHandler) Handle(c *irc.Client, m *irc.Message) { go func(m *irc.Message) { configLock.RLock() diff --git a/main.go b/main.go index a1bcbd2..cc16cbc 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "github.com/pkg/errors" log "github.com/sirupsen/logrus" + "github.com/Luzifer/go_helpers/v2/str" "github.com/Luzifer/rconfig/v2" ) @@ -121,6 +122,8 @@ func main() { // Fine, reload } + previousChannels := append([]string{}, config.Channels...) + if err := loadConfig(cfg.Config); err != nil { log.WithError(err).Error("Unable to reload config") continue @@ -128,6 +131,13 @@ func main() { irc.ExecuteJoins(config.Channels) + for _, c := range previousChannels { + if !str.StringInSlice(c, config.Channels) { + log.WithField("channel", c).Info("Leaving removed channel...") + irc.ExecutePart(c) + } + } + case <-autoMessageTicker.C: configLock.RLock() for _, am := range config.AutoMessages {