mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-08 08:10:08 +00:00
[core] Fix: Strip newlines from message templates
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
11e55fc5cb
commit
36f9133cd5
1 changed files with 10 additions and 2 deletions
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"regexp"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
|
@ -11,8 +12,12 @@ import (
|
|||
"github.com/Luzifer/twitch-bot/plugins"
|
||||
)
|
||||
|
||||
// Compile-time assertion
|
||||
var _ plugins.MsgFormatter = formatMessage
|
||||
var (
|
||||
// Compile-time assertion
|
||||
_ plugins.MsgFormatter = formatMessage
|
||||
|
||||
stripNewline = regexp.MustCompile(`(?m)\s*\n\s*`)
|
||||
)
|
||||
|
||||
func formatMessage(tplString string, m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) (string, error) {
|
||||
compiledFields := plugins.NewFieldCollection()
|
||||
|
@ -32,6 +37,9 @@ func formatMessage(tplString string, m *irc.Message, r *plugins.Rule, fields *pl
|
|||
compiledFields.Set("username", plugins.DeriveUser(m, fields))
|
||||
compiledFields.Set("channel", plugins.DeriveChannel(m, fields))
|
||||
|
||||
// Template in frontend supports newlines, messages do not
|
||||
tplString = stripNewline.ReplaceAllString(tplString, " ")
|
||||
|
||||
// Parse and execute template
|
||||
tpl, err := template.
|
||||
New(tplString).
|
||||
|
|
Loading…
Reference in a new issue