From f85a6f419acab935c6f60ce4c41245a3318ec552 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 19 Feb 2024 11:43:35 -0600 Subject: [PATCH] fix incorrect display of the original check results for /spam replayed msg, add name of the supper banned it --- app/events/admin.go | 7 ++++--- app/events/listener_test.go | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/events/admin.go b/app/events/admin.go index c46153da..3cc1f0f2 100644 --- a/app/events/admin.go +++ b/app/events/admin.go @@ -167,7 +167,7 @@ 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())) @@ -175,8 +175,9 @@ func (a *admin) DirectSpamReport(update tbapi.Update) error { 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)) } diff --git a/app/events/listener_test.go b/app/events/listener_test.go index d5187621..73ca054b 100644 --- a/app/events/listener_test.go +++ b/app/events/listener_test.go @@ -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) @@ -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) {