2021-05-26 13:36:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-irc/irc"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-06-11 11:52:42 +00:00
|
|
|
registerAction(func() Actor { return &ActorRaw{} })
|
2021-05-26 13:36:03 +00:00
|
|
|
}
|
2021-06-11 11:52:42 +00:00
|
|
|
|
|
|
|
type ActorRaw struct {
|
|
|
|
RawMessage *string `json:"raw_message" yaml:"raw_message"`
|
|
|
|
}
|
|
|
|
|
2021-08-11 22:12:10 +00:00
|
|
|
func (a ActorRaw) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) {
|
2021-06-11 11:52:42 +00:00
|
|
|
if a.RawMessage == nil {
|
2021-08-11 22:12:10 +00:00
|
|
|
return false, nil
|
2021-06-11 11:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rawMsg, err := formatMessage(*a.RawMessage, m, r, nil)
|
|
|
|
if err != nil {
|
2021-08-11 22:12:10 +00:00
|
|
|
return false, errors.Wrap(err, "preparing raw message")
|
2021-06-11 11:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg, err := irc.ParseMessage(rawMsg)
|
|
|
|
if err != nil {
|
2021-08-11 22:12:10 +00:00
|
|
|
return false, errors.Wrap(err, "parsing raw message")
|
2021-06-11 11:52:42 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 22:12:10 +00:00
|
|
|
return false, errors.Wrap(
|
2021-06-11 11:52:42 +00:00
|
|
|
c.WriteMessage(msg),
|
|
|
|
"sending raw message",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a ActorRaw) IsAsync() bool { return false }
|
|
|
|
func (a ActorRaw) Name() string { return "raw" }
|