mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 00:30:02 +00:00
Add modchannel core module
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c9e7d48477
commit
7c75e94ade
2 changed files with 75 additions and 0 deletions
70
internal/actors/modchannel/actor.go
Normal file
70
internal/actors/modchannel/actor.go
Normal file
|
@ -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" }
|
|
@ -74,6 +74,11 @@ rules: # See below for examples
|
||||||
# Issue a timeout on the user who wrote the chat-line
|
# Issue a timeout on the user who wrote the chat-line
|
||||||
- timeout: 1s # Duration value: 1s / 1m / 1h
|
- 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
|
# Set a variable to value defined for later usage
|
||||||
- variable: myvar # String, name of the variable to set (applies templating)
|
- variable: myvar # String, name of the variable to set (applies templating)
|
||||||
clear: false # Boolean, clear the variable
|
clear: false # Boolean, clear the variable
|
||||||
|
|
Loading…
Reference in a new issue