diff --git a/irc.go b/irc.go index 29d326e..d3747d0 100644 --- a/irc.go +++ b/irc.go @@ -138,6 +138,8 @@ func (i ircHandler) Handle(c *irc.Client, m *irc.Message) { func (i ircHandler) Run() error { return errors.Wrap(i.c.Run(), "running IRC client") } +func (i ircHandler) SendMessage(m *irc.Message) error { return i.c.WriteMessage(m) } + func (ircHandler) getChannel(m *irc.Message) string { if len(m.Params) > 0 { return m.Params[0] diff --git a/main.go b/main.go index 40649cb..0859c24 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "github.com/go-irc/irc" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -32,6 +33,8 @@ var ( config *configFile configLock = new(sync.RWMutex) + sendMessage func(m *irc.Message) error + store = newStorageFile(false) version = "dev" @@ -102,6 +105,7 @@ func main() { case <-ircDisconnected: if irc != nil { + sendMessage = nil irc.Close() } @@ -110,9 +114,11 @@ func main() { } go func() { + sendMessage = irc.SendMessage if err := irc.Run(); err != nil { log.WithError(err).Error("IRC run exited unexpectedly") } + sendMessage = nil time.Sleep(ircReconnectDelay) ircDisconnected <- struct{}{} }()