add fix for filters

This commit is contained in:
harold 2025-04-29 00:35:56 +05:00
parent 47b15a6318
commit be57a14ca5

View File

@ -4,6 +4,7 @@ import (
"context"
"donat-widget/internal/model"
"donat-widget/internal/model/api"
"fmt"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"log/slog"
@ -744,7 +745,7 @@ func (donatService *ServiceDonat) GetPlayingDonat(
if !filteredSettings.EnableLinks {
response.Text = donatService.replaceLinks(response.Text)
}
fmt.Println(response.Text)
response.VoiceSpeed = voiceSettings.VoiceSpeed
response.Scenery = voiceSettings.Scenery
response.VoiceSoundPercent = voiceSettings.VoiceSoundPercent
@ -812,9 +813,17 @@ func (donatService *ServiceDonat) replaceFilteredWords(text string, words []stri
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)
// Заменяем все совпадения на звёздочки
return re.ReplaceAllStringFunc(text, func(match string) string {
return strings.Repeat("*", len(match))
})