mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +00:00
Automatically leave channel when removed from config
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
2069596d01
commit
b8737a4286
2 changed files with 14 additions and 0 deletions
4
irc.go
4
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()
|
||||
|
|
10
main.go
10
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 {
|
||||
|
|
Loading…
Reference in a new issue