Merge branch 'sanitize-on-get-option' into 'main'
Sanitize settings on Get() and add convenience getters See merge request etke.cc/postmoogle!8
This commit is contained in:
@@ -102,12 +102,12 @@ func (b *Bot) Send(ctx context.Context, from, to, subject, plaintext, html strin
|
||||
}
|
||||
|
||||
var text strings.Builder
|
||||
if !utils.Bool(settings.Get("nosender")) {
|
||||
if !settings.NoSender() {
|
||||
text.WriteString("From: ")
|
||||
text.WriteString(from)
|
||||
text.WriteString("\n\n")
|
||||
}
|
||||
if !utils.Bool(settings.Get("nosubject")) {
|
||||
if !settings.NoSubject() {
|
||||
text.WriteString("# ")
|
||||
text.WriteString(subject)
|
||||
text.WriteString("\n\n")
|
||||
|
||||
18
bot/data.go
18
bot/data.go
@@ -7,6 +7,8 @@ import (
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"gitlab.com/etke.cc/postmoogle/utils"
|
||||
)
|
||||
|
||||
const settingskey = "cc.etke.postmoogle.settings"
|
||||
@@ -39,7 +41,21 @@ func (s settings) Allowed(noowner bool, userID id.UserID) bool {
|
||||
|
||||
// Get option
|
||||
func (s settings) Get(key string) string {
|
||||
return s[strings.ToLower(strings.TrimSpace(key))]
|
||||
value := s[strings.ToLower(strings.TrimSpace(key))]
|
||||
|
||||
sanitizer, exists := sanitizers[key]
|
||||
if exists {
|
||||
return sanitizer(value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func (s settings) NoSender() bool {
|
||||
return utils.Bool(s.Get("nosender"))
|
||||
}
|
||||
|
||||
func (s settings) NoSubject() bool {
|
||||
return utils.Bool(s.Get("nosubject"))
|
||||
}
|
||||
|
||||
// Set option
|
||||
|
||||
Reference in New Issue
Block a user