2021-08-19 13:33:56 +00:00
|
|
|
package deleteactor
|
2020-12-27 13:42:51 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/go-irc/irc"
|
|
|
|
"github.com/pkg/errors"
|
2021-11-25 22:48:16 +00:00
|
|
|
|
2022-10-23 13:06:45 +00:00
|
|
|
"github.com/Luzifer/twitch-bot/v2/plugins"
|
2020-12-27 13:42:51 +00:00
|
|
|
)
|
|
|
|
|
2021-09-22 13:36:45 +00:00
|
|
|
const actorName = "delete"
|
|
|
|
|
2021-08-19 13:33:56 +00:00
|
|
|
func Register(args plugins.RegistrationArguments) error {
|
2021-09-22 13:36:45 +00:00
|
|
|
args.RegisterActor(actorName, func() plugins.Actor { return &actor{} })
|
|
|
|
|
|
|
|
args.RegisterActorDocumentation(plugins.ActionDocumentation{
|
|
|
|
Description: "Delete message which caused the rule to be executed",
|
|
|
|
Name: "Delete Message",
|
|
|
|
Type: "delete",
|
|
|
|
})
|
2021-08-19 13:33:56 +00:00
|
|
|
|
|
|
|
return nil
|
2020-12-27 13:42:51 +00:00
|
|
|
}
|
2021-06-11 11:52:42 +00:00
|
|
|
|
2021-09-22 13:36:45 +00:00
|
|
|
type actor struct{}
|
2021-06-11 11:52:42 +00:00
|
|
|
|
2021-11-11 13:59:08 +00:00
|
|
|
func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule, eventData *plugins.FieldCollection, attrs *plugins.FieldCollection) (preventCooldown bool, err error) {
|
2021-06-11 11:52:42 +00:00
|
|
|
msgID, ok := m.Tags.GetTag("id")
|
|
|
|
if !ok || msgID == "" {
|
2021-08-11 22:12:10 +00:00
|
|
|
return false, nil
|
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(&irc.Message{
|
|
|
|
Command: "PRIVMSG",
|
|
|
|
Params: []string{
|
|
|
|
m.Params[0],
|
|
|
|
fmt.Sprintf("/delete %s", msgID),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
"sending delete",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-08-19 13:33:56 +00:00
|
|
|
func (a actor) IsAsync() bool { return false }
|
2021-09-22 13:36:45 +00:00
|
|
|
func (a actor) Name() string { return actorName }
|
|
|
|
|
2021-11-11 13:59:08 +00:00
|
|
|
func (a actor) Validate(attrs *plugins.FieldCollection) (err error) { return nil }
|