twitch-bot/action_respond.go

34 lines
594 B
Go
Raw Normal View History

2020-12-21 00:32:39 +00:00
package main
import (
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
func init() {
registerAction(func(c *irc.Client, m *irc.Message, ruleDef *rule, r *ruleAction) error {
2020-12-21 00:32:39 +00:00
if r.Respond == nil {
return nil
}
msg, err := formatMessage(*r.Respond, m, ruleDef, nil)
2020-12-21 00:32:39 +00:00
if err != nil {
if r.RespondFallback == nil {
return errors.Wrap(err, "preparing response")
}
msg = *r.RespondFallback
2020-12-21 00:32:39 +00:00
}
return errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
m.Params[0],
msg,
},
}),
"sending response",
)
})
}