This commit is contained in:
Aine
2022-11-16 14:23:42 +02:00
parent c1d33fe3cb
commit 86cda29729
9 changed files with 276 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ package bot
import (
"context"
"net"
"regexp"
"strings"
@@ -71,6 +72,29 @@ func (b *Bot) allowSend(actorID id.UserID, targetRoomID id.RoomID) bool {
return !cfg.NoSend()
}
// IsBanned checks if address is banned
func (b *Bot) IsBanned(addr net.Addr) bool {
if !b.getBotSettings().BanlistEnabled() {
return false
}
return b.getBanlist().Has(addr)
}
// Ban an address
func (b *Bot) Ban(addr net.Addr) {
if !b.getBotSettings().BanlistEnabled() {
return
}
b.log.Debug("banning %s", addr.String())
banlist := b.getBanlist()
banlist.Add(addr)
err := b.setBanlist(banlist)
if err != nil {
b.log.Error("cannot update banlist with %s: %v", addr.String(), err)
}
}
// AllowAuth check if SMTP login (email) and password are valid
func (b *Bot) AllowAuth(email, password string) bool {
var suffix bool