mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +00:00
[core] Fix: send-message function passed to plugin was nil
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
8c32889584
commit
7e2b83fc0a
2 changed files with 17 additions and 6 deletions
6
main.go
6
main.go
|
@ -13,7 +13,6 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-irc/irc"
|
||||
"github.com/gofrs/uuid/v3"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -55,8 +54,6 @@ var (
|
|||
runID = uuid.Must(uuid.NewV4()).String()
|
||||
externalHTTPAvailable bool
|
||||
|
||||
sendMessage func(m *irc.Message) error
|
||||
|
||||
store = newStorageFile(false)
|
||||
twitchClient *twitch.Client
|
||||
twitchEventSubClient *twitch.EventSubClient
|
||||
|
@ -249,7 +246,6 @@ func main() {
|
|||
|
||||
case <-ircDisconnected:
|
||||
if ircHdl != nil {
|
||||
sendMessage = nil
|
||||
ircHdl.Close()
|
||||
}
|
||||
|
||||
|
@ -258,11 +254,9 @@ func main() {
|
|||
}
|
||||
|
||||
go func() {
|
||||
sendMessage = ircHdl.SendMessage
|
||||
if err := ircHdl.Run(); err != nil {
|
||||
log.WithError(err).Error("IRC run exited unexpectedly")
|
||||
}
|
||||
sendMessage = nil
|
||||
time.Sleep(ircReconnectDelay)
|
||||
ircDisconnected <- struct{}{}
|
||||
}()
|
||||
|
|
|
@ -4,9 +4,11 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-irc/irc"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/Luzifer/go_helpers/v2/backoff"
|
||||
"github.com/Luzifer/go_helpers/v2/str"
|
||||
"github.com/Luzifer/twitch-bot/internal/actors/ban"
|
||||
"github.com/Luzifer/twitch-bot/internal/actors/delay"
|
||||
|
@ -25,6 +27,8 @@ import (
|
|||
"github.com/Luzifer/twitch-bot/twitch"
|
||||
)
|
||||
|
||||
const ircHandleWaitRetries = 10
|
||||
|
||||
var (
|
||||
corePluginRegistrations = []plugins.RegisterFunc{
|
||||
// Actors
|
||||
|
@ -105,3 +109,16 @@ func getRegistrationArguments() plugins.RegistrationArguments {
|
|||
SendMessage: sendMessage,
|
||||
}
|
||||
}
|
||||
|
||||
func sendMessage(m *irc.Message) error {
|
||||
if err := backoff.NewBackoff().WithMaxIterations(ircHandleWaitRetries).Retry(func() error {
|
||||
if ircHdl == nil {
|
||||
return errors.New("irc handle not available")
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "waiting for IRC connection")
|
||||
}
|
||||
|
||||
return ircHdl.SendMessage(m)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue