Skip to content

Commit

Permalink
Make forwarded message during dry mode less confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthGandalf authored and umputun committed Sep 19, 2024
1 parent 035f473 commit 97aeeaf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/events/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const (
func (a *admin) ReportBan(banUserStr string, msg *bot.Message) {
log.Printf("[DEBUG] report to admin chat, ban msgsData for %s, group: %d", banUserStr, a.adminChatID)
text := strings.ReplaceAll(escapeMarkDownV1Text(msg.Text), "\n", " ")
forwardMsg := fmt.Sprintf("**permanently banned [%s](tg://user?id=%d)**\n\n%s\n\n", banUserStr, msg.From.ID, text)
would := ""
if a.dry {
would = "would have "
}
forwardMsg := fmt.Sprintf("**%spermanently banned [%s](tg://user?id=%d)**\n\n%s\n\n", would, banUserStr, msg.From.ID, text)
if err := a.sendWithUnbanMarkup(forwardMsg, "change ban", msg.From, msg.ID, a.adminChatID); err != nil {
log.Printf("[WARN] failed to send admin message, %v", err)
}
Expand Down
17 changes: 17 additions & 0 deletions app/events/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,20 @@ func TestAdmin_extractUsername(t *testing.T) {
})
}
}

func TestAdmin_dryModeForwardMessage(t *testing.T) {
mockAPI := &mocks.TbAPIMock{
SendFunc: func(c tbapi.Chattable) (tbapi.Message, error) {
return tbapi.Message{}, nil
},
}
adm := admin{
tbAPI: mockAPI,
dry: true,
}
msg := &bot.Message{}

adm.ReportBan("testUser", msg)
assert.Contains(t, mockAPI.SendCalls()[0].C.(tbapi.MessageConfig).Text, "would have permanently banned [testUser]")

}

0 comments on commit 97aeeaf

Please sign in to comment.