mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-27 04:54:45 +03:00
d15b72a11a
A customer whose links ran past one Telegram caption could not turn the page, and one holding several configs was shown a client-card button the bot then ignored. Customers can now page long screens and only admins see the card. "Get one" lists a config's links and opens the chosen one alone with its own QR code, naming VMess links by their remark; the links pages open with the config's expiry and remaining traffic; and setup guides for five platforms are reached from the customer's home. The new per-client callbacks pass the same ownership check as the existing link screens.
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package tgbot
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/util/common"
|
|
)
|
|
|
|
// A config with no quota reports unlimited rather than zero left, which a
|
|
// customer would read as being cut off.
|
|
func remainingBytes(used, total int64) (int64, bool) {
|
|
if total <= 0 {
|
|
return 0, false
|
|
}
|
|
if used >= total {
|
|
return 0, true
|
|
}
|
|
return total - used, true
|
|
}
|
|
|
|
// headerExpiry renders the expiry the way the client card does: a negative
|
|
// value counts days from first use rather than naming a date.
|
|
func (t *Tgbot) headerExpiry(expiryTime int64) string {
|
|
switch {
|
|
case expiryTime == 0:
|
|
return t.I18nBot("tgbot.unlimited")
|
|
case expiryTime < 0:
|
|
return fmt.Sprintf("%d %s", expiryTime/-86400000, t.I18nBot("tgbot.days"))
|
|
default:
|
|
return time.UnixMilli(expiryTime).Format("2006-01-02")
|
|
}
|
|
}
|
|
|
|
// clientHeader says which config a link page shows and how much of it is left,
|
|
// so a customer holding several does not have to guess from the links.
|
|
func (t *Tgbot) clientHeader(email string) string {
|
|
traffic, err := t.inboundService.GetClientTrafficByEmail(email)
|
|
if err != nil || traffic == nil {
|
|
logger.Warning("tgbot: link page header lookup failed for", email, ":", err)
|
|
return t.clientScreenBody(email, "")
|
|
}
|
|
remaining := t.I18nBot("tgbot.unlimited")
|
|
if left, limited := remainingBytes(traffic.Up+traffic.Down, traffic.Total); limited {
|
|
remaining = common.FormatTraffic(left)
|
|
}
|
|
return t.I18nBot("tgbot.messages.clientHeader",
|
|
"Email=="+email,
|
|
"Expiry=="+t.headerExpiry(traffic.ExpiryTime),
|
|
"Remaining=="+remaining) + "\r\n\r\n"
|
|
}
|