[PR #6500] [MERGED] fix(tgbot): show a disabled start-after-first-use client as days, not a 1969 date #6313

Closed
opened 2026-11-02 04:07:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6500
Author: @BlindMaster24
Created: 9/13/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei

Base: main ← Head: fix/tgbot-disabled-delayed-expiry


📝 Commits (1)

  • 14fa3fe fix(tgbot): render a disabled start-after-first-use client as days

📊 Changes

2 files changed (+63 additions, -3 deletions)

View changed files

📝 internal/web/service/tgbot/tgbot_client.go (+5 -3)
➕ internal/web/service/tgbot/tgbot_client_expiry_test.go (+58 -0)

📄 Description

Summary

Reorders the expiry branches in the Telegram bot's client card so a client whose expiry starts at first use (a negative ExpiryTime) is reported in days even while the client is disabled.

Why

Found by the automated review of #6498 (fix(discord): report a start-after-first-use client as days, not unlimited), which flagged the Telegram card as the one surface still misreading the same value. It is pre-existing, so it came here instead of into that PR.

The panel stores "starts after first connection, N days" as a negative expiry (-2592000000 for 30 days). clientInfoMsg had this order:

} else if diff > 172800 || !traffic.Enable {   // disabled clients land here
    expiryTime = time.Unix(traffic.ExpiryTime/1000, 0).Format("2006-01-02 15:04:05")
} else if traffic.ExpiryTime < 0 {             // ...so this is unreachable for them

time.Unix(-2592000, 0) is 1969-12-02 04:00:00. flag also stayed false, so the card labelled it Expire Date rather than Expire In.

User story

  1. An admin adds a client from the bot and picks Add 1 month, which the wizard turns into -30 days — "starts at first use".
  2. The customer has not connected yet, and the admin disables the client (or the traffic job disables it after it runs out).
  3. The admin taps the client to inspect it: the card reads 📅 Expire Date: 1969-12-02 04:00:00, which reads as corrupt data rather than "30 days, starting when they first connect".

The panel UI, subscriptionExpiryFromClient and adjustTraffics all key off the sign of ExpiryTime, and so does BuildClientDraftMessage in this same file; this card and the Discord card were the two that did not — #6498 fixes the Discord side, which is where this finding came from.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

New TestClientInfoShowsStartAfterFirstUseWhenDisabled (internal/web/service/tgbot/tgbot_client_expiry_test.go) builds a ClientTraffic with Enable: false and ExpiryTime: -30 * 24 * 60 * 60000, renders the card through clientInfoMsg, and asserts it contains Expire In: 30 Days and no 1969.

On the code before this commit the assertion reads client info = "📧 Email: trial@example.com\r\n📅 Expire Date: 1969-12-02 04:00:00\r\n"; with the sign branch moved up it passes. The test installs a real go-i18n bundle for the four keys the card prints, because I18nBot returns the bare key when no localizer is set.

Behaviour is unchanged for every other combination: only ExpiryTime < 0 moves; positive-and-far, positive-and-near, enabled and disabled all still take the branches they took before.

Honesty about local verification

I could not build or run the tests on this machine: the SQLite driver is CGo and there is no C compiler here (CGO_ENABLED=0 cannot build internal/database, so the tgbot package does not compile either). gofmt is clean, and the build/test verdict here comes from CI, not from a local run. I reverted the fix and re-read the assertion path rather than executing it.

Screenshots / recordings

N/A — Telegram message text, covered by the test above.

Breaking changes

None.

Checklist

  • I tested the change locally and confirmed the described behavior. (no local toolchain — CI is the build for this PR)
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass. (no frontend change in this PR)
  • I updated the Wiki / README / API docs if user-facing behavior changed. (no docs describe this card)
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6500 **Author:** [@BlindMaster24](https://github.com/BlindMaster24) **Created:** 9/13/2026 **Status:** ✅ Merged **Merged:** 9/13/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/tgbot-disabled-delayed-expiry` --- ### 📝 Commits (1) - [`14fa3fe`](https://github.com/MHSanaei/3x-ui/commit/14fa3fe22538dd44a500f6de90ce25e250db9330) fix(tgbot): render a disabled start-after-first-use client as days ### 📊 Changes **2 files changed** (+63 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/tgbot/tgbot_client.go` (+5 -3) ➕ `internal/web/service/tgbot/tgbot_client_expiry_test.go` (+58 -0) </details> ### 📄 Description ## Summary Reorders the expiry branches in the Telegram bot's client card so a client whose expiry starts at first use (a negative `ExpiryTime`) is reported in days even while the client is disabled. ## Why Found by the automated review of #6498 (`fix(discord): report a start-after-first-use client as days, not unlimited`), which flagged the Telegram card as the one surface still misreading the same value. It is pre-existing, so it came here instead of into that PR. The panel stores "starts after first connection, N days" as a **negative** expiry (`-2592000000` for 30 days). `clientInfoMsg` had this order: ```go } else if diff > 172800 || !traffic.Enable { // disabled clients land here expiryTime = time.Unix(traffic.ExpiryTime/1000, 0).Format("2006-01-02 15:04:05") } else if traffic.ExpiryTime < 0 { // ...so this is unreachable for them ``` `time.Unix(-2592000, 0)` is `1969-12-02 04:00:00`. `flag` also stayed false, so the card labelled it **Expire Date** rather than **Expire In**. ### User story 1. An admin adds a client from the bot and picks **Add 1 month**, which the wizard turns into `-30 days` — "starts at first use". 2. The customer has not connected yet, and the admin disables the client (or the traffic job disables it after it runs out). 3. The admin taps the client to inspect it: the card reads `📅 Expire Date: 1969-12-02 04:00:00`, which reads as corrupt data rather than "30 days, starting when they first connect". The panel UI, `subscriptionExpiryFromClient` and `adjustTraffics` all key off the sign of `ExpiryTime`, and so does `BuildClientDraftMessage` in this same file; this card and the Discord card were the two that did not — #6498 fixes the Discord side, which is where this finding came from. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [x] Telegram bot ## How was this tested? New `TestClientInfoShowsStartAfterFirstUseWhenDisabled` (`internal/web/service/tgbot/tgbot_client_expiry_test.go`) builds a `ClientTraffic` with `Enable: false` and `ExpiryTime: -30 * 24 * 60 * 60000`, renders the card through `clientInfoMsg`, and asserts it contains `Expire In: 30 Days` and no `1969`. On the code before this commit the assertion reads `client info = "📧 Email: trial@example.com\r\n📅 Expire Date: 1969-12-02 04:00:00\r\n"`; with the sign branch moved up it passes. The test installs a real go-i18n bundle for the four keys the card prints, because `I18nBot` returns the bare key when no localizer is set. Behaviour is unchanged for every other combination: only `ExpiryTime < 0` moves; positive-and-far, positive-and-near, enabled and disabled all still take the branches they took before. ### Honesty about local verification I could not build or run the tests on this machine: the SQLite driver is CGo and there is no C compiler here (`CGO_ENABLED=0` cannot build `internal/database`, so the `tgbot` package does not compile either). `gofmt` is clean, and the build/test verdict here comes from CI, not from a local run. I reverted the fix and re-read the assertion path rather than executing it. ## Screenshots / recordings N/A — Telegram message text, covered by the test above. ## Breaking changes None. ## Checklist - [ ] I tested the change locally and confirmed the described behavior. (no local toolchain — CI is the build for this PR) - [x] I added or updated tests for the new behavior (when applicable). - [ ] `go build ./...` and the test suite pass locally. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. (no frontend change in this PR) - [x] I updated the Wiki / README / API docs if user-facing behavior changed. (no docs describe this card) - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:52 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6313
No description provided.