mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-21 04:11:16 +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"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-irc/irc"
|
|
||||||
"github.com/gofrs/uuid/v3"
|
"github.com/gofrs/uuid/v3"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -55,8 +54,6 @@ var (
|
||||||
runID = uuid.Must(uuid.NewV4()).String()
|
runID = uuid.Must(uuid.NewV4()).String()
|
||||||
externalHTTPAvailable bool
|
externalHTTPAvailable bool
|
||||||
|
|
||||||
sendMessage func(m *irc.Message) error
|
|
||||||
|
|
||||||
store = newStorageFile(false)
|
store = newStorageFile(false)
|
||||||
twitchClient *twitch.Client
|
twitchClient *twitch.Client
|
||||||
twitchEventSubClient *twitch.EventSubClient
|
twitchEventSubClient *twitch.EventSubClient
|
||||||
|
@ -249,7 +246,6 @@ func main() {
|
||||||
|
|
||||||
case <-ircDisconnected:
|
case <-ircDisconnected:
|
||||||
if ircHdl != nil {
|
if ircHdl != nil {
|
||||||
sendMessage = nil
|
|
||||||
ircHdl.Close()
|
ircHdl.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,11 +254,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
sendMessage = ircHdl.SendMessage
|
|
||||||
if err := ircHdl.Run(); err != nil {
|
if err := ircHdl.Run(); err != nil {
|
||||||
log.WithError(err).Error("IRC run exited unexpectedly")
|
log.WithError(err).Error("IRC run exited unexpectedly")
|
||||||
}
|
}
|
||||||
sendMessage = nil
|
|
||||||
time.Sleep(ircReconnectDelay)
|
time.Sleep(ircReconnectDelay)
|
||||||
ircDisconnected <- struct{}{}
|
ircDisconnected <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -4,9 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-irc/irc"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/Luzifer/go_helpers/v2/backoff"
|
||||||
"github.com/Luzifer/go_helpers/v2/str"
|
"github.com/Luzifer/go_helpers/v2/str"
|
||||||
"github.com/Luzifer/twitch-bot/internal/actors/ban"
|
"github.com/Luzifer/twitch-bot/internal/actors/ban"
|
||||||
"github.com/Luzifer/twitch-bot/internal/actors/delay"
|
"github.com/Luzifer/twitch-bot/internal/actors/delay"
|
||||||
|
@ -25,6 +27,8 @@ import (
|
||||||
"github.com/Luzifer/twitch-bot/twitch"
|
"github.com/Luzifer/twitch-bot/twitch"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ircHandleWaitRetries = 10
|
||||||
|
|
||||||
var (
|
var (
|
||||||
corePluginRegistrations = []plugins.RegisterFunc{
|
corePluginRegistrations = []plugins.RegisterFunc{
|
||||||
// Actors
|
// Actors
|
||||||
|
@ -105,3 +109,16 @@ func getRegistrationArguments() plugins.RegistrationArguments {
|
||||||
SendMessage: sendMessage,
|
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