From 55b17a635a2cdc65287460d87f9d72ba9019383d Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 21 Dec 2020 01:52:10 +0100 Subject: [PATCH] Join channels on config change --- irc.go | 10 +++++++--- main.go | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/irc.go b/irc.go index c306603..963cfc0 100644 --- a/irc.go +++ b/irc.go @@ -59,6 +59,12 @@ func newIRCHandler() (*ircHandler, error) { func (i ircHandler) Close() error { return i.conn.Close() } +func (i ircHandler) ExecuteJoins(channels []string) { + for _, ch := range channels { + i.c.Write(fmt.Sprintf("JOIN #%s", strings.TrimLeft(ch, "#"))) + } +} + func (i ircHandler) Handle(c *irc.Client, m *irc.Message) { switch m.Command { case "001": @@ -74,9 +80,7 @@ func (i ircHandler) Handle(c *irc.Client, m *irc.Message) { }, " "), }, }) - for _, ch := range config.Channels { - c.Write(fmt.Sprintf("JOIN #%s", strings.TrimLeft(ch, "#"))) - } + i.ExecuteJoins(config.Channels) case "NOTICE": // NOTICE (Twitch Commands) diff --git a/main.go b/main.go index da9fd59..fcbbc31 100644 --- a/main.go +++ b/main.go @@ -105,6 +105,8 @@ func main() { continue } + irc.ExecuteJoins(config.Channels) + log.Info("Config file reloaded") }