Automatically leave channel when removed from config

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-06-14 23:42:40 +02:00
parent 2069596d01
commit b8737a4286
Signed by: luzifer
GPG Key ID: 0066F03ED215AD7D
2 changed files with 14 additions and 0 deletions

4
irc.go
View File

@ -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()

10
main.go
View File

@ -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 {