Skip to content

Commit

Permalink
fix incorrect display of the original check results for /spam replaye…
Browse files Browse the repository at this point in the history
…d msg, add name of the supper banned it
  • Loading branch information
umputun committed Feb 19, 2024
1 parent d433e73 commit f85a6f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/events/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,17 @@ func (a *admin) DirectSpamReport(update tbapi.Update) error {

// make a message with spam info and send to admin chat
spamInfo := []string{}
resp := a.bot.OnMessage(bot.Message{Text: update.Message.Text, From: bot.User{ID: origMsg.From.ID}})
resp := a.bot.OnMessage(bot.Message{Text: msgTxt, From: bot.User{ID: origMsg.From.ID}})
spamInfoText := "**can't get spam info**"
for _, check := range resp.CheckResults {
spamInfo = append(spamInfo, "- "+escapeMarkDownV1Text(check.String()))
}
if len(spamInfo) > 0 {
spamInfoText = strings.Join(spamInfo, "\n")
}
newMsgText := fmt.Sprintf("**original detection results for %s (%d)**\n\n%s\n\n%s\n\n\n*the user banned and message deleted*",
escapeMarkDownV1Text(origMsg.From.UserName), origMsg.From.ID, msgTxt, escapeMarkDownV1Text(spamInfoText))
newMsgText := fmt.Sprintf("**original detection results for %s (%d)**\n\n%s\n\n%s\n\n\n*the user banned by %q and message deleted*",
escapeMarkDownV1Text(origMsg.From.UserName), origMsg.From.ID, msgTxt, escapeMarkDownV1Text(spamInfoText),
escapeMarkDownV1Text(update.Message.From.UserName))
if err := send(tbapi.NewMessage(a.adminChatID, newMsgText), a.tbAPI); err != nil {
errs = multierror.Append(errs, fmt.Errorf("failed to send spam detection results to admin chat: %w", err))
}
Expand Down
5 changes: 5 additions & 0 deletions app/events/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ func TestTelegramListener_DoWithDirectSpamReport(t *testing.T) {
require.Equal(t, 2, len(mockAPI.SendCalls()))
assert.Equal(t, "startup", mockAPI.SendCalls()[0].C.(tbapi.MessageConfig).Text)
assert.Contains(t, mockAPI.SendCalls()[1].C.(tbapi.MessageConfig).Text, "detection results")
assert.Contains(t, mockAPI.SendCalls()[1].C.(tbapi.MessageConfig).Text, `the user banned by "superuser1"`)

require.Equal(t, 1, len(b.OnMessageCalls()))
assert.Equal(t, "text 123", b.OnMessageCalls()[0].Msg.Text)

require.Equal(t, 1, len(b.UpdateSpamCalls()))
assert.Equal(t, "text 123", b.UpdateSpamCalls()[0].Msg)
Expand All @@ -543,6 +547,7 @@ func TestTelegramListener_DoWithDirectSpamReport(t *testing.T) {
assert.Equal(t, int(0), mockAPI.RequestCalls()[1].C.(tbapi.DeleteMessageConfig).MessageID)
assert.Equal(t, int64(123), mockAPI.RequestCalls()[2].C.(tbapi.BanChatMemberConfig).ChatID)
assert.Equal(t, int64(666), mockAPI.RequestCalls()[2].C.(tbapi.BanChatMemberConfig).UserID)

}

func TestTelegramListener_DoWithAdminUnBan(t *testing.T) {
Expand Down

0 comments on commit f85a6f4

Please sign in to comment.