twitch-bot/action_delete.go
2021-08-12 00:12:10 +02:00

41 lines
820 B
Go

package main
import (
"fmt"
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
func init() {
registerAction(func() Actor { return &ActorDelete{} })
}
type ActorDelete struct {
DeleteMessage *bool `json:"delete_message" yaml:"delete_message"`
}
func (a ActorDelete) Execute(c *irc.Client, m *irc.Message, r *Rule) (preventCooldown bool, err error) {
if a.DeleteMessage == nil || !*a.DeleteMessage {
return false, nil
}
msgID, ok := m.Tags.GetTag("id")
if !ok || msgID == "" {
return false, nil
}
return false, errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
m.Params[0],
fmt.Sprintf("/delete %s", msgID),
},
}),
"sending delete",
)
}
func (a ActorDelete) IsAsync() bool { return false }
func (a ActorDelete) Name() string { return "delete" }