42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"spark-server/internal/module/message/entity"
|
|
modentity "spark-server/internal/module/moderation/entity"
|
|
)
|
|
|
|
func (s *Service) gateAccount(ctx context.Context, userID int64) error {
|
|
if s.account == nil {
|
|
return nil
|
|
}
|
|
return s.account.AssertCanSend(ctx, userID)
|
|
}
|
|
|
|
func (s *Service) moderateText(ctx context.Context, userID, conversationID int64, content *entity.Content) error {
|
|
if content == nil || content.Type != entity.TypeText || content.Text == nil || s.filter == nil {
|
|
return nil
|
|
}
|
|
body := content.Text.Body
|
|
res, err := s.filter.Scan(ctx, body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if res == nil || len(res.Hits) == 0 {
|
|
return nil
|
|
}
|
|
if s.penalty != nil {
|
|
if err := s.penalty.Apply(ctx, userID, conversationID, &modentity.ApplyInput{Hits: res.Hits}); err != nil {
|
|
return err
|
|
}
|
|
if err := s.penalty.Enforce(ctx, userID, res); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if res.Action == modentity.ActionReplace && res.ReplacedBody != "" {
|
|
content.Text.Body = res.ReplacedBody
|
|
}
|
|
return nil
|
|
}
|