twitch-bot/internal/actors/announce/actor.go
Knut Ahlers 0a937a65d0
prepare release v3.0.0
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2022-11-02 22:54:52 +01:00

40 lines
943 B
Go

package announce
import (
"regexp"
"github.com/go-irc/irc"
"github.com/pkg/errors"
"github.com/Luzifer/twitch-bot/v3/pkg/twitch"
"github.com/Luzifer/twitch-bot/v3/plugins"
)
var (
botTwitchClient *twitch.Client
announceChatcommandRegex = regexp.MustCompile(`^/announce(|blue|green|orange|purple) +(.+)$`)
)
func Register(args plugins.RegistrationArguments) error {
botTwitchClient = args.GetTwitchClient()
args.RegisterMessageModFunc("/announce", handleChatCommand)
return nil
}
func handleChatCommand(m *irc.Message) error {
channel := plugins.DeriveChannel(m, nil)
matches := announceChatcommandRegex.FindStringSubmatch(m.Trailing())
if matches == nil {
return errors.New("announce message does not match required format")
}
if err := botTwitchClient.SendChatAnnouncement(channel, matches[1], matches[2]); err != nil {
return errors.Wrap(err, "sending announcement")
}
return plugins.ErrSkipSendingMessage
}