2020-12-21 00:32:39 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-irc/irc"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-12-25 18:31:07 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-12-25 18:31:07 +00:00
|
|
|
msg, err := formatMessage(*r.Respond, m, ruleDef, nil)
|
2020-12-21 00:32:39 +00:00
|
|
|
if err != nil {
|
2021-01-21 00:00:04 +00:00
|
|
|
if r.RespondFallback == nil {
|
|
|
|
return errors.Wrap(err, "preparing response")
|
|
|
|
}
|
2021-01-21 00:13:09 +00:00
|
|
|
if msg, err = formatMessage(*r.RespondFallback, m, ruleDef, nil); err != nil {
|
|
|
|
return errors.Wrap(err, "preparing response fallback")
|
|
|
|
}
|
2020-12-21 00:32:39 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 13:31:16 +00:00
|
|
|
ircMessage := &irc.Message{
|
|
|
|
Command: "PRIVMSG",
|
|
|
|
Params: []string{
|
|
|
|
m.Params[0],
|
|
|
|
msg,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.RespondAsReply != nil && *r.RespondAsReply {
|
|
|
|
id, ok := m.GetTag("id")
|
|
|
|
if ok {
|
|
|
|
if ircMessage.Tags == nil {
|
|
|
|
ircMessage.Tags = make(irc.Tags)
|
|
|
|
}
|
|
|
|
ircMessage.Tags["reply-parent-msg-id"] = irc.TagValue(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 00:32:39 +00:00
|
|
|
return errors.Wrap(
|
2021-06-02 13:31:16 +00:00
|
|
|
c.WriteMessage(ircMessage),
|
2020-12-21 00:32:39 +00:00
|
|
|
"sending response",
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|