diff --git a/internal/actors/modchannel/actor.go b/internal/actors/modchannel/actor.go new file mode 100644 index 0000000..001e861 --- /dev/null +++ b/internal/actors/modchannel/actor.go @@ -0,0 +1,70 @@ +package modchannel + +import ( + "context" + "strings" + + "github.com/Luzifer/twitch-bot/plugins" + "github.com/Luzifer/twitch-bot/twitch" + "github.com/go-irc/irc" + "github.com/pkg/errors" +) + +var ( + formatMessage plugins.MsgFormatter + twitchClient *twitch.Client +) + +func Register(args plugins.RegistrationArguments) error { + formatMessage = args.FormatMessage + twitchClient = args.GetTwitchClient() + + args.RegisterActor(func() plugins.Actor { return &actor{} }) + + return nil +} + +type actor struct { + Channel string `json:"channel" yaml:"channel"` + UpdateGame *string `json:"update_game" yaml:"update_game"` + UpdateTitle *string `json:"update_title" yaml:"update_title"` +} + +func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule, eventData plugins.FieldCollection) (preventCooldown bool, err error) { + if a.UpdateGame == nil && a.UpdateTitle == nil { + return false, nil + } + + var game, title *string + + channel, err := formatMessage(a.Channel, m, r, eventData) + if err != nil { + return false, errors.Wrap(err, "parsing channel") + } + + if a.UpdateGame != nil { + parsedGame, err := formatMessage(*a.UpdateGame, m, r, eventData) + if err != nil { + return false, errors.Wrap(err, "parsing game") + } + + game = &parsedGame + } + + if a.UpdateTitle != nil { + parsedTitle, err := formatMessage(*a.UpdateTitle, m, r, eventData) + if err != nil { + return false, errors.Wrap(err, "parsing title") + } + + title = &parsedTitle + } + + return false, errors.Wrap( + twitchClient.ModifyChannelInformation(context.Background(), strings.TrimLeft(channel, "#"), game, title), + "updating channel info", + ) +} + +func (a actor) IsAsync() bool { return false } +func (a actor) Name() string { return "modchannel" } diff --git a/wiki/Home.md b/wiki/Home.md index 6b2a66b..8ce20cc 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -74,6 +74,11 @@ rules: # See below for examples # Issue a timeout on the user who wrote the chat-line - timeout: 1s # Duration value: 1s / 1m / 1h + # Update channel information (one of `update_game` and `update_title` must be defined) + - channel: '{{ .channel }}' # String, applies templating + update_game: 'Just Chatting' # String, optional, set game to given category + update_title: 'My special title' # String, optional, set title to given title + # Set a variable to value defined for later usage - variable: myvar # String, name of the variable to set (applies templating) clear: false # Boolean, clear the variable