2021-08-19 13:33:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-08-25 18:53:04 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-08-19 13:33:56 +00:00
|
|
|
"github.com/Luzifer/twitch-bot/internal/actors/ban"
|
|
|
|
"github.com/Luzifer/twitch-bot/internal/actors/delay"
|
|
|
|
deleteactor "github.com/Luzifer/twitch-bot/internal/actors/delete"
|
2021-09-10 17:45:31 +00:00
|
|
|
"github.com/Luzifer/twitch-bot/internal/actors/modchannel"
|
2021-08-19 13:33:56 +00:00
|
|
|
"github.com/Luzifer/twitch-bot/internal/actors/raw"
|
|
|
|
"github.com/Luzifer/twitch-bot/internal/actors/respond"
|
|
|
|
"github.com/Luzifer/twitch-bot/internal/actors/timeout"
|
|
|
|
"github.com/Luzifer/twitch-bot/internal/actors/whisper"
|
|
|
|
"github.com/Luzifer/twitch-bot/plugins"
|
2021-09-10 15:57:04 +00:00
|
|
|
"github.com/Luzifer/twitch-bot/twitch"
|
2021-08-28 15:27:24 +00:00
|
|
|
"github.com/pkg/errors"
|
2021-08-19 13:33:56 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
var coreActorRegistations = []plugins.RegisterFunc{
|
|
|
|
ban.Register,
|
|
|
|
delay.Register,
|
|
|
|
deleteactor.Register,
|
2021-09-10 17:45:31 +00:00
|
|
|
modchannel.Register,
|
2021-08-19 13:33:56 +00:00
|
|
|
raw.Register,
|
|
|
|
respond.Register,
|
|
|
|
timeout.Register,
|
|
|
|
whisper.Register,
|
|
|
|
}
|
|
|
|
|
2021-09-10 17:45:31 +00:00
|
|
|
func initCorePlugins() error {
|
2021-08-19 13:33:56 +00:00
|
|
|
args := getRegistrationArguments()
|
|
|
|
for _, rf := range coreActorRegistations {
|
|
|
|
if err := rf(args); err != nil {
|
2021-09-10 17:45:31 +00:00
|
|
|
return errors.Wrap(err, "registering core plugin")
|
2021-08-19 13:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-10 17:45:31 +00:00
|
|
|
return nil
|
2021-08-19 13:33:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 15:27:24 +00:00
|
|
|
func registerRoute(route plugins.HTTPRouteRegistrationArgs) error {
|
|
|
|
r := router.
|
|
|
|
PathPrefix(fmt.Sprintf("/%s/", route.Module)).
|
|
|
|
Subrouter()
|
|
|
|
|
|
|
|
if route.IsPrefix {
|
|
|
|
r.PathPrefix(route.Path).
|
|
|
|
HandlerFunc(route.HandlerFunc).
|
|
|
|
Methods(route.Method)
|
|
|
|
} else {
|
|
|
|
r.HandleFunc(route.Path, route.HandlerFunc).
|
|
|
|
Methods(route.Method)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !route.SkipDocumentation {
|
|
|
|
return errors.Wrap(registerSwaggerRoute(route), "registering documentation")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-19 13:33:56 +00:00
|
|
|
func getRegistrationArguments() plugins.RegistrationArguments {
|
|
|
|
return plugins.RegistrationArguments{
|
2021-09-02 13:01:10 +00:00
|
|
|
FormatMessage: formatMessage,
|
|
|
|
GetLogger: func(moduleName string) *log.Entry { return log.WithField("module", moduleName) },
|
2021-09-10 15:57:04 +00:00
|
|
|
GetTwitchClient: func() *twitch.Client { return twitchClient },
|
2021-09-02 13:01:10 +00:00
|
|
|
RegisterActor: registerAction,
|
|
|
|
RegisterAPIRoute: registerRoute,
|
|
|
|
RegisterCron: cronService.AddFunc,
|
|
|
|
RegisterRawMessageHandler: registerRawMessageHandler,
|
|
|
|
RegisterTemplateFunction: tplFuncs.Register,
|
|
|
|
SendMessage: sendMessage,
|
2021-08-19 13:33:56 +00:00
|
|
|
}
|
|
|
|
}
|