[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 (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Luzifer/twitch-bot/plugins"
|
|
||||||
"github.com/go-irc/irc"
|
"github.com/go-irc/irc"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/Luzifer/twitch-bot/plugins"
|
||||||
)
|
)
|
||||||
|
|
||||||
const actorName = "ban"
|
const actorName = "ban"
|
||||||
|
|
||||||
|
var formatMessage plugins.MsgFormatter
|
||||||
|
|
||||||
func Register(args plugins.RegistrationArguments) error {
|
func Register(args plugins.RegistrationArguments) error {
|
||||||
|
formatMessage = args.FormatMessage
|
||||||
|
|
||||||
args.RegisterActor(actorName, func() plugins.Actor { return &actor{} })
|
args.RegisterActor(actorName, func() plugins.Actor { return &actor{} })
|
||||||
|
|
||||||
args.RegisterActorDocumentation(plugins.ActionDocumentation{
|
args.RegisterActorDocumentation(plugins.ActionDocumentation{
|
||||||
|
@ -25,7 +30,7 @@ func Register(args plugins.RegistrationArguments) error {
|
||||||
Key: "reason",
|
Key: "reason",
|
||||||
Name: "Reason",
|
Name: "Reason",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
SupportTemplate: false,
|
SupportTemplate: true,
|
||||||
Type: plugins.ActionDocumentationFieldTypeString,
|
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) {
|
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 }("")
|
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{
|
cmd := []string{
|
||||||
"/ban",
|
"/ban",
|
||||||
plugins.DeriveUser(m, eventData),
|
plugins.DeriveUser(m, eventData),
|
||||||
}
|
}
|
||||||
|
|
||||||
if reason := attrs.MustString("reason", ptrStringEmpty); reason != "" {
|
if reason != "" {
|
||||||
cmd = append(cmd, reason)
|
cmd = append(cmd, reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue