add fix for filters
This commit is contained in:
parent
47b15a6318
commit
be57a14ca5
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"donat-widget/internal/model"
|
"donat-widget/internal/model"
|
||||||
"donat-widget/internal/model/api"
|
"donat-widget/internal/model/api"
|
||||||
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@ -744,7 +745,7 @@ func (donatService *ServiceDonat) GetPlayingDonat(
|
|||||||
if !filteredSettings.EnableLinks {
|
if !filteredSettings.EnableLinks {
|
||||||
response.Text = donatService.replaceLinks(response.Text)
|
response.Text = donatService.replaceLinks(response.Text)
|
||||||
}
|
}
|
||||||
|
fmt.Println(response.Text)
|
||||||
response.VoiceSpeed = voiceSettings.VoiceSpeed
|
response.VoiceSpeed = voiceSettings.VoiceSpeed
|
||||||
response.Scenery = voiceSettings.Scenery
|
response.Scenery = voiceSettings.Scenery
|
||||||
response.VoiceSoundPercent = voiceSettings.VoiceSoundPercent
|
response.VoiceSoundPercent = voiceSettings.VoiceSoundPercent
|
||||||
@ -812,9 +813,17 @@ func (donatService *ServiceDonat) replaceFilteredWords(text string, words []stri
|
|||||||
escapedWords[i] = regexp.QuoteMeta(word)
|
escapedWords[i] = regexp.QuoteMeta(word)
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern := `(?i)\b(` + strings.Join(escapedWords, "|") + `)\b`
|
// Создаем паттерны для каждого слова, чтобы находить их внутри любых последовательностей символов (кроме пробелов)
|
||||||
|
patterns := make([]string, len(escapedWords))
|
||||||
|
for i, word := range escapedWords {
|
||||||
|
patterns[i] = fmt.Sprintf(`\S*%s\S*`, word) // Ищем запрещённое слово в любом месте "слова"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Комбинируем все паттерны в одно регулярное выражение
|
||||||
|
pattern := `(?i)(` + strings.Join(patterns, "|") + `)`
|
||||||
re := regexp.MustCompile(pattern)
|
re := regexp.MustCompile(pattern)
|
||||||
|
|
||||||
|
// Заменяем все совпадения на звёздочки
|
||||||
return re.ReplaceAllStringFunc(text, func(match string) string {
|
return re.ReplaceAllStringFunc(text, func(match string) string {
|
||||||
return strings.Repeat("*", len(match))
|
return strings.Repeat("*", len(match))
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user