Implement initial flavouor of ban by caps

This commit is contained in:
eleksir
2023-10-29 12:09:03 +03:00
parent 122f16c408
commit a08baa5f38
2 changed files with 23 additions and 2 deletions

21
buny.go
View File

@@ -254,8 +254,10 @@ func bunyChat(v xmpp.Chat) error {
err error err error
) )
// Действовать мы можем только в рамках тех комнат, где явно присуствуем.
for _, cRoom := range roomsConnected { for _, cRoom := range roomsConnected {
if cRoom == room { if cRoom == room {
// Перебирём правила чёрных списков.
for _, bEntry := range blackList.Blacklist { for _, bEntry := range blackList.Blacklist {
// Обработаем правила глобального чёрного списка // Обработаем правила глобального чёрного списка
if bEntry.RoomName == "" { if bEntry.RoomName == "" {
@@ -344,6 +346,25 @@ func bunyChat(v xmpp.Chat) error {
} }
} }
// Если включено, проверяем фразу на КАПС.
for _, channel := range config.Jabber.Channels {
if channel.Name == room && channel.AllCaps.Enabled {
// Нормализуем строку и вырежем из неё пробелы
normPhrase := strings.ReplaceAll(nString(v.Text), " ", "")
// Проверяем согласно тому, что длина фразы более чем сколько-то символов
if len(normPhrase) >= channel.AllCaps.MinLength {
normPhraseUpper := strings.ReplaceAll(nStringUpper(v.Text), " ", "")
if normPhrase == normPhraseUpper {
realJID := getRealJIDfromNick(v.Remote)
squash(room, realJID, false, v.Type)
}
}
}
}
break break
} }
} }

View File

@@ -30,12 +30,12 @@ type myConfig struct {
Bayes struct { Bayes struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
MinWords int64 `json:"min_words,omitempty"` MinWords int64 `json:"min_words,omitempty"`
MinLength int64 `json:"min_length,omitempty"` MinLength int `json:"min_length,omitempty"`
DefaultAction string `json:"default_action,omitempty"` DefaultAction string `json:"default_action,omitempty"`
} `json:"bayes,omitempty"` } `json:"bayes,omitempty"`
AllCaps struct { AllCaps struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
MinLength int64 `json:"min_length,omitempty"` MinLength int `json:"min_length,omitempty"`
DefaultAction string `json:"default_action,omitempty"` DefaultAction string `json:"default_action,omitempty"`
} `json:"all_caps,omitempty"` } `json:"all_caps,omitempty"`
} `json:"channels"` } `json:"channels"`