[ban] Enable templating for ban reason
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c884a7c532
commit
f3ad4a1332
1 changed files with 13 additions and 3 deletions
|
@ -3,14 +3,19 @@ package ban
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Luzifer/twitch-bot/plugins"
|
||||
"github.com/go-irc/irc"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/Luzifer/twitch-bot/plugins"
|
||||
)
|
||||
|
||||
const actorName = "ban"
|
||||
|
||||
var formatMessage plugins.MsgFormatter
|
||||
|
||||
func Register(args plugins.RegistrationArguments) error {
|
||||
formatMessage = args.FormatMessage
|
||||
|
||||
args.RegisterActor(actorName, func() plugins.Actor { return &actor{} })
|
||||
|
||||
args.RegisterActorDocumentation(plugins.ActionDocumentation{
|
||||
|
@ -25,7 +30,7 @@ func Register(args plugins.RegistrationArguments) error {
|
|||
Key: "reason",
|
||||
Name: "Reason",
|
||||
Optional: true,
|
||||
SupportTemplate: false,
|
||||
SupportTemplate: true,
|
||||
Type: plugins.ActionDocumentationFieldTypeString,
|
||||
},
|
||||
},
|
||||
|
@ -39,12 +44,17 @@ 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 }("")
|
||||
|
||||
reason, err := formatMessage(attrs.MustString("reason", ptrStringEmpty), m, r, eventData)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "executing reason template")
|
||||
}
|
||||
|
||||
cmd := []string{
|
||||
"/ban",
|
||||
plugins.DeriveUser(m, eventData),
|
||||
}
|
||||
|
||||
if reason := attrs.MustString("reason", ptrStringEmpty); reason != "" {
|
||||
if reason != "" {
|
||||
cmd = append(cmd, reason)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue