2021-08-19 15:33:56 +02:00
|
|
|
package deleteactor
|
2020-12-27 14:42:51 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-irc/irc"
|
|
|
|
"github.com/pkg/errors"
|
2021-11-25 23:48:16 +01:00
|
|
|
|
2022-11-02 22:38:14 +01:00
|
|
|
"github.com/Luzifer/twitch-bot/v3/pkg/twitch"
|
|
|
|
"github.com/Luzifer/twitch-bot/v3/plugins"
|
2020-12-27 14:42:51 +01:00
|
|
|
)
|
|
|
|
|
2021-09-22 15:36:45 +02:00
|
|
|
const actorName = "delete"
|
|
|
|
|
2022-10-25 18:47:30 +02:00
|
|
|
var botTwitchClient *twitch.Client
|
|
|
|
|
2021-08-19 15:33:56 +02:00
|
|
|
func Register(args plugins.RegistrationArguments) error {
|
2022-10-25 18:47:30 +02:00
|
|
|
botTwitchClient = args.GetTwitchClient()
|
|
|
|
|
2021-09-22 15:36:45 +02: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 15:33:56 +02:00
|
|
|
|
|
|
|
return nil
|
2020-12-27 14:42:51 +01:00
|
|
|
}
|
2021-06-11 13:52:42 +02:00
|
|
|
|
2021-09-22 15:36:45 +02:00
|
|
|
type actor struct{}
|
2021-06-11 13:52:42 +02:00
|
|
|
|
2021-11-11 14:59:08 +01: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 13:52:42 +02:00
|
|
|
msgID, ok := m.Tags.GetTag("id")
|
|
|
|
if !ok || msgID == "" {
|
2021-08-12 00:12:10 +02:00
|
|
|
return false, nil
|
2021-06-11 13:52:42 +02:00
|
|
|
}
|
|
|
|
|
2021-08-12 00:12:10 +02:00
|
|
|
return false, errors.Wrap(
|
2022-10-25 18:47:30 +02:00
|
|
|
botTwitchClient.DeleteMessage(
|
|
|
|
plugins.DeriveChannel(m, eventData),
|
|
|
|
msgID,
|
|
|
|
),
|
|
|
|
"deleting message",
|
2021-06-11 13:52:42 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-08-19 15:33:56 +02:00
|
|
|
func (a actor) IsAsync() bool { return false }
|
2021-09-22 15:36:45 +02:00
|
|
|
func (a actor) Name() string { return actorName }
|
|
|
|
|
2022-10-31 17:26:53 +01:00
|
|
|
func (a actor) Validate(plugins.TemplateValidatorFunc, *plugins.FieldCollection) (err error) {
|
|
|
|
return nil
|
|
|
|
}
|