[PR #6498] [MERGED] fix(discord): report a start-after-first-use client as days, not unlimited #6310

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

📋 Pull Request Information

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

Base: main ← Head: fix/discord-usage-delayed-expiry


📝 Commits (1)

  • efc6639 fix(discord): report a start-after-first-use client as days, not unlimited

📊 Changes

2 files changed (+117 additions, -1 deletions)

View changed files

📝 internal/web/service/discord/gateway.go (+6 -1)
➕ internal/web/service/discord/gateway_delayed_expiry_test.go (+111 -0)

📄 Description

Summary

!usage now renders a client whose expiry is the "Start After First Use" duration as N Days, the same way the panel and the Telegram bot already render it, instead of labelling it Unlimited.

Why

sendUsage (internal/web/service/discord/gateway.go) started from tr("unlimited") and only replaced it for a positive timestamp:

expireStr := tr("unlimited")
if client.ExpiryTime > 0 {
    expireStr = time.Unix(client.ExpiryTime/1000, 0).Format("2006-01-02 15:04:05")
}

A negative expiryTime is not "no expiry" in this panel — it is the Start After First Use mode, stored as the duration negated and turned into an absolute deadline by adjustTraffics on the client's first traffic tick (internal/web/service/inbound_traffic.go, the UPDATE ... WHERE expiry_time < 0 block). The Telegram bot renders exactly this value as days (internal/web/service/tgbot/tgbot_client.go, the client_ExpiryTime < 0 case), and the frontend edits it as delayedStart (Start After First Use, internal/web/translation/en-US.json). So the Discord embed was the one surface telling an operator that a client which does expire never will.

Operator's story: they hand out 30-day trial keys with "Start After First Use" so the clock starts when the customer first connects. Checking one with !usage trial@example.com, the embed reads Expiry: Unlimited while the panel's client list shows the same client counting down — the two disagree, and the safest reading of the Discord answer ("this key never expires") is the wrong one.

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 (client expiry display)
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot (internal/web/service/discord, the Discord bot added in #6486)

How was this tested?

New TestUsageExpiryForDelayedStart drives !usage <email> through handleMessage and the REST client against an httptest server, and reads the expiry field of the embed that would reach Discord.

  • A client stored as -2592000000 ms — what the panel writes for Start After First Use: 30 days — must come back as 30 Days. Without the change it comes back as Unlimited:
    delayed start shows "Unlimited", want "30 Days".
  • A client with an absolute deadline (4102444800000 ms) must still come back as a formatted date, so the new branch does not swallow the case that already worked.

The whole internal/web/service/discord package suite passes with the change, and go vet is clean for the package.

Caveat, stated rather than glossed: this machine has no C compiler, so the CGo mattn/go-sqlite3 driver cannot build here; the suite above ran through a local pure-Go SQLite build of the driver, and CI is the authoritative run.

Screenshots / recordings

N/A — no UI change.

Breaking changes

None. The value shown for a delayed-start client changes from a wrong label to the one the rest of the panel already uses; no key, setting or endpoint is touched, and tgbot.days is reused rather than a new i18n key added.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally. (no C compiler here — CI verifies the CGo build)
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed. (no endpoint, setting or i18n key changed)
  • 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/6498 **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/discord-usage-delayed-expiry` --- ### 📝 Commits (1) - [`efc6639`](https://github.com/MHSanaei/3x-ui/commit/efc6639f8965414f3fcf571bed54c7bde7052876) fix(discord): report a start-after-first-use client as days, not unlimited ### 📊 Changes **2 files changed** (+117 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/discord/gateway.go` (+6 -1) ➕ `internal/web/service/discord/gateway_delayed_expiry_test.go` (+111 -0) </details> ### 📄 Description ## Summary `!usage` now renders a client whose expiry is the "Start After First Use" duration as `N Days`, the same way the panel and the Telegram bot already render it, instead of labelling it `Unlimited`. ## Why `sendUsage` (`internal/web/service/discord/gateway.go`) started from `tr("unlimited")` and only replaced it for a positive timestamp: ```go expireStr := tr("unlimited") if client.ExpiryTime > 0 { expireStr = time.Unix(client.ExpiryTime/1000, 0).Format("2006-01-02 15:04:05") } ``` A negative `expiryTime` is not "no expiry" in this panel — it is the *Start After First Use* mode, stored as the duration negated and turned into an absolute deadline by `adjustTraffics` on the client's first traffic tick (`internal/web/service/inbound_traffic.go`, the `UPDATE ... WHERE expiry_time < 0` block). The Telegram bot renders exactly this value as days (`internal/web/service/tgbot/tgbot_client.go`, the `client_ExpiryTime < 0` case), and the frontend edits it as `delayedStart` (`Start After First Use`, `internal/web/translation/en-US.json`). So the Discord embed was the one surface telling an operator that a client which does expire never will. Operator's story: they hand out 30-day trial keys with "Start After First Use" so the clock starts when the customer first connects. Checking one with `!usage trial@example.com`, the embed reads `Expiry: Unlimited` while the panel's client list shows the same client counting down — the two disagree, and the safest reading of the Discord answer ("this key never expires") is the wrong one. ## 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) - [x] Statistics / traffic counters (client expiry display) - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [x] Telegram bot (`internal/web/service/discord`, the Discord bot added in #6486) ## How was this tested? New `TestUsageExpiryForDelayedStart` drives `!usage <email>` through `handleMessage` and the REST client against an `httptest` server, and reads the expiry field of the embed that would reach Discord. - A client stored as `-2592000000` ms — what the panel writes for *Start After First Use: 30 days* — must come back as `30 Days`. Without the change it comes back as `Unlimited`: `delayed start shows "Unlimited", want "30 Days"`. - A client with an absolute deadline (`4102444800000` ms) must still come back as a formatted date, so the new branch does not swallow the case that already worked. The whole `internal/web/service/discord` package suite passes with the change, and `go vet` is clean for the package. Caveat, stated rather than glossed: this machine has no C compiler, so the CGo `mattn/go-sqlite3` driver cannot build here; the suite above ran through a local pure-Go SQLite build of the driver, and CI is the authoritative run. ## Screenshots / recordings N/A — no UI change. ## Breaking changes None. The value shown for a delayed-start client changes from a wrong label to the one the rest of the panel already uses; no key, setting or endpoint is touched, and `tgbot.days` is reused rather than a new i18n key added. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [ ] `go build ./...` and the test suite pass locally. (no C compiler here — CI verifies the CGo build) - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. (no endpoint, setting or i18n key changed) - [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:50 +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#6310
No description provided.