Skip to content

Commit

Permalink
fix getCleanMessage to prevent spam result checks published to spam a…
Browse files Browse the repository at this point in the history
…nd ham dynamic samples
  • Loading branch information
umputun committed Jan 31, 2024
1 parent bf1f692 commit b3b7b90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/events/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func (a *admin) getCleanMessage(msg string) (string, error) {

spamInfoLine := len(msgLines)
for i, line := range msgLines {
if strings.HasPrefix(line, "spam detection results") {
if strings.HasPrefix(line, "spam detection results") || strings.HasPrefix(line, "**spam detection results**") {
spamInfoLine = i - 1
break
}
Expand Down
20 changes: 20 additions & 0 deletions app/events/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ func TestAdmin_getCleanMessage(t *testing.T) {
}
}

func TestAdmin_getCleanMessage2(t *testing.T) {
msg := `permanently banned {157419590 new_Nikita Νικήτας}
и да, этим надо заниматься каждый день по несколько часов. За месяц увидишь ощутимый результат
**spam detection results**
- stopword: ham, not found
- emoji: ham, 0/2
- similarity: ham, 0.15/0.50
- classifier: spam, probability of spam: 71.70%
- cas: ham, record not found
_unbanned by umputun in 1m5s_`

a := &admin{}
result, err := a.getCleanMessage(msg)
assert.NoError(t, err)
assert.Equal(t, "и да, этим надо заниматься каждый день по несколько часов. За месяц увидишь ощутимый результат", result)
}

func TestAdmin_parseCallbackData(t *testing.T) {
var tests = []struct {
name string
Expand Down

0 comments on commit b3b7b90

Please sign in to comment.