mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6991] [MERGED] fix(tgbot): restore current ban log delivery and skip empty files #6564
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6564
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6991
Author: @HamedSanaei
Created: 10/28/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @MHSanaei
Base:
main← Head:fix/tgbot-ban-logs-6990📝 Commits (1)
7585272fix(tgbot): restore ban log delivery and skip empty files📊 Changes
2 files changed (+260 additions, -16 deletions)
View changed files
➕
internal/web/service/tgbot/ban_logs_test.go(+222 -0)📝
internal/web/service/tgbot/screen_views.go(+38 -16)📄 Description
Summary
tgbot.noResultnotice only when neither file is available to upload. Log upload failures separately and still attempt the second file after a failure of the first.httptest.Serverthat inspects actual Telegram document uploads.Root Cause
The Telegram bot rewrite in #6760 replaced v3.10.2's
sendBanLogswithsendBanLogsFile, retaining onlyGetIPLimitBannedPrevLogPath()and dropping the zero-byte check.ClearLogsJobrotates the current banned-IP log into the previous log daily, so the bot stopped delivering today's bans until that rotation, and an empty previous log was submitted to Telegram as a document.The fix checks both paths in order. Each file and its 60-second upload context are cleaned up before processing the next file. A nonempty file counts as available before the upload, so a Telegram error cannot produce a misleading no-results notice.
Testing
Executed with Go 1.27.3:
gofmt -w internal/web/service/tgbot/screen_views.go internal/web/service/tgbot/ban_logs_test.go— completed.go test ./internal/web/service/tgbot/ -count=1— passed on Windows.go vet ./internal/web/service/tgbot/...— passed.go test -race ./internal/web/service/tgbot/ -count=1— passed in the Linuxgolang:1.27.3-bookwormcontainer.golangci-lint run ./internal/web/service/tgbot/...— passed, 0 issues (v2.15.0).git diff --checkandgit diff --cached --check— passed.The regression table covers 13 scenarios: both files nonempty; either file alone; either file empty; both empty; both missing; mixed empty/missing files; a directory at the previous log path; failure of the first of two uploads; and failure of either sole nonempty file. An additional test covers an unavailable bot. Assertions check document order, filenames and bytes, localized notices, upload-error logging, chat/topic routing, hide buttons, notification behavior, unchanged file contents, and file-handle cleanup on Windows. All new API tests use temporary logs and a local HTTP server, with no live Telegram credentials or external network access.
Compatibility
This restores the previous/current delivery order from v3.10.2 while preserving the existing v3.11.0 notice mechanism, chat ID,
adminTopic, hide buttons, and notification settings. Daily rotation and log contents are unchanged. No dependencies, configuration changes, or database migrations are required.Live Telegram delivery and the full repository
make verifywere not run; the Telegram API is simulated, including upload rejection.Related Issue
Fixes #6990
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
[PR #6991] fix(tgbot): restore current ban log delivery and skip empty filesto [PR #6991] [MERGED] fix(tgbot): restore current ban log delivery and skip empty files