32 lines
933 B
Go
32 lines
933 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
modentity "spark-server/internal/module/moderation/entity"
|
|
)
|
|
|
|
// GateText scans user-authored text outside chat (moments, square, nickname, announcement).
|
|
// A nil service or blank text is unchanged. Replace returns the masked body.
|
|
// Reject, mute, and disable record the hit and return ErrContentBlocked.
|
|
func (s *Service) GateText(ctx context.Context, userID int64, text string) (string, error) {
|
|
if s == nil || strings.TrimSpace(text) == "" {
|
|
return text, nil
|
|
}
|
|
res, err := s.Scan(ctx, text)
|
|
if err != nil || res == nil || len(res.Hits) == 0 {
|
|
return text, err
|
|
}
|
|
if err := s.Apply(ctx, userID, 0, &modentity.ApplyInput{Hits: res.Hits}); err != nil {
|
|
return text, err
|
|
}
|
|
if err := s.Enforce(ctx, userID, res); err != nil {
|
|
return text, err
|
|
}
|
|
if res.Action == modentity.ActionReplace && res.ReplacedBody != "" {
|
|
return res.ReplacedBody, nil
|
|
}
|
|
return text, nil
|
|
}
|