mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-08 16:20:02 +00:00
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package ban
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/Luzifer/twitch-bot/plugins"
|
|
"github.com/go-irc/irc"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const actorName = "ban"
|
|
|
|
func Register(args plugins.RegistrationArguments) error {
|
|
args.RegisterActor(actorName, func() plugins.Actor { return &actor{} })
|
|
|
|
args.RegisterActorDocumentation(plugins.ActionDocumentation{
|
|
Description: "Ban user from chat",
|
|
Name: "Ban User",
|
|
Type: "ban",
|
|
|
|
Fields: []plugins.ActionDocumentationField{
|
|
{
|
|
Default: "",
|
|
Description: "Reason why the user was banned",
|
|
Key: "reason",
|
|
Name: "Reason",
|
|
Optional: true,
|
|
SupportTemplate: false,
|
|
Type: plugins.ActionDocumentationFieldTypeString,
|
|
},
|
|
},
|
|
})
|
|
|
|
return nil
|
|
}
|
|
|
|
type actor struct{}
|
|
|
|
func (a actor) Execute(c *irc.Client, m *irc.Message, r *plugins.Rule, eventData plugins.FieldCollection, attrs plugins.FieldCollection) (preventCooldown bool, err error) {
|
|
ptrStringEmpty := func(v string) *string { return &v }("")
|
|
|
|
cmd := []string{
|
|
"/ban",
|
|
plugins.DeriveUser(m, eventData),
|
|
}
|
|
|
|
if reason := attrs.MustString("reason", ptrStringEmpty); reason != "" {
|
|
cmd = append(cmd, reason)
|
|
}
|
|
|
|
return false, errors.Wrap(
|
|
c.WriteMessage(&irc.Message{
|
|
Command: "PRIVMSG",
|
|
Params: []string{
|
|
plugins.DeriveChannel(m, eventData),
|
|
strings.Join(cmd, " "),
|
|
},
|
|
}),
|
|
"sending ban",
|
|
)
|
|
}
|
|
|
|
func (a actor) IsAsync() bool { return false }
|
|
func (a actor) Name() string { return actorName }
|
|
|
|
func (a actor) Validate(attrs plugins.FieldCollection) (err error) { return nil }
|