add noreplies option

This commit is contained in:
Aine
2023-04-10 14:03:43 +03:00
parent e8ade4173f
commit 84102d5b5b
6 changed files with 40 additions and 2 deletions

View File

@@ -73,6 +73,20 @@ func (b *Bot) allowSend(actorID id.UserID, targetRoomID id.RoomID) bool {
return !cfg.NoSend()
}
func (b *Bot) allowReply(actorID id.UserID, targetRoomID id.RoomID) bool {
if !b.allowUsers(actorID) {
return false
}
cfg, err := b.cfg.GetRoom(targetRoomID)
if err != nil {
b.Error(sentry.SetHubOnContext(context.Background(), sentry.CurrentHub()), targetRoomID, "failed to retrieve settings: %v", err)
return false
}
return !cfg.NoReplies()
}
func (b *Bot) isReserved(mailbox string) bool {
for _, reserved := range b.mbxc.Reserved {
if mailbox == reserved {

View File

@@ -104,6 +104,15 @@ func (b *Bot) initCommands() commandList {
sanitizer: utils.SanitizeBoolString,
allowed: b.allowOwner,
},
{
key: config.RoomNoReplies,
description: fmt.Sprintf(
"Get or set `%s` of the room (`true` - ignore matrix replies; `false` - parse matrix replies)",
config.RoomNoReplies,
),
sanitizer: utils.SanitizeBoolString,
allowed: b.allowOwner,
},
{
key: config.RoomNoSender,
description: fmt.Sprintf(

View File

@@ -19,6 +19,7 @@ const (
RoomMailbox = "mailbox"
RoomDomain = "domain"
RoomNoSend = "nosend"
RoomNoReplies = "noreplies"
RoomNoCC = "nocc"
RoomNoSender = "nosender"
RoomNoRecipient = "norecipient"
@@ -69,6 +70,10 @@ func (s Room) NoSend() bool {
return utils.Bool(s.Get(RoomNoSend))
}
func (s Room) NoReplies() bool {
return utils.Bool(s.Get(RoomNoReplies))
}
func (s Room) NoCC() bool {
return utils.Bool(s.Get(RoomNoCC))
}

View File

@@ -146,6 +146,9 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
if !b.allowSend(evt.Sender, evt.RoomID) {
return
}
if !b.allowReply(evt.Sender, evt.RoomID) {
return
}
cfg, err := b.cfg.GetRoom(evt.RoomID)
if err != nil {
b.Error(ctx, evt.RoomID, "cannot retrieve room settings: %v", err)