3x-ui/internal/web/service/tgbot
sdhfsl 536f9a6338
fix(tgbot): localize QR caption via I18nBot (#6564)
* fix(panel): accept 2FA codes from adjacent TOTP windows

CheckUser compared only gotp.Now(), so a code submitted at the end of
its 30s window (or with slight client/server clock drift) failed with
'invalid 2fa code', while the immediate retry in the next window
succeeded. Accept current +/-1 window, the standard TOTP skew
tolerance.

Fixes MHSanaei/3x-ui#6535

* fix(panel): share TOTP skew tolerance with VerifyTwoFactorCode

Move the +/-1 window helper to internal/util/totp so both 2FA
acceptance points use it: login (CheckUser) and disable/rebind plus
username/password changes (VerifyTwoFactorCode). Also shrink comments
to the 2-line house rule and anchor the unit test mid-window to avoid
a step-boundary flake.

Addresses review on #6546 (MEDIUM + 2 LOWs).

* fix(tgbot): localize QR caption via I18nBot

sendClientQRLinks hardcoded English 'QRCode for client <email>:',
bypassing I18nBot, so non-English bot languages (e.g. ru-RU) still
got English. Add tgbot.answers.qrCodeForClient key with Email param
in all 13 locales and route the caption through I18nBot.

Fixes MHSanaei/3x-ui#6562

* fix(tgbot): repair locale JSON syntax, harden QR i18n test

- Add missing separators so all 13 locale files parse again.
- Rewrite the regression test to read the real shipped files
  (fails on malformed JSON or missing key).
- Add TestTgbotLocalesQrKeyValid covering every locale file.

* chore(tgbot): drop QR caption tests that cannot catch the bug

TestQRCodeForClientLocalizes never calls sendClientQRLinks: it registers
two messages in a synthetic bundle and asserts on I18nBot, a passthrough
to go-i18n. With the tgbot_client.go line reverted to the hardcoded
English caption, both it and TestTgbotLocalesQrKeyValid still pass, so
neither certifies the fix.

The malformed-locale class they were added for is already pinned twice:
the discord package's TestMain loads every translation file through
locale.InitLocalizer and panics on invalid JSON, and
frontend/src/test/i18n-dead-keys.test.ts parses all 13 locales and
checks each carries the en-US key set. Both go red on the #6564 syntax
error this PR first shipped.

---------

Co-authored-by: sdhfsl <sdhfsl@users.noreply.github.com>
Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
2026-09-16 12:23:42 +02:00
..
numeric_input.go refactor(tgbot): extract the shared numeric keypad builder 2026-09-10 21:07:57 +02:00
numeric_input_test.go test(tgbot): detect open-coded keypad transitions (#6214) 2026-08-15 15:27:02 +02:00
tgbot.go fix(tgbot): keep the add-client draft with the chat that owns it (#6499) 2026-09-13 19:48:54 +02:00
tgbot_add_client_expiry_test.go refactor(tgbot): make the add-client expiry presets say what they do (#6503) 2026-09-13 19:57:46 +02:00
tgbot_admin_list_race_test.go fix(tgbot): read the admin list and running flag under their mutex (#6491) 2026-09-13 11:46:36 +02:00
tgbot_callback_auth_test.go Repo-wide self-correcting audit: 54 verified bug fixes (#5970) 2026-07-17 00:33:06 +02:00
tgbot_client.go fix(tgbot): localize QR caption via I18nBot (#6564) 2026-09-16 12:23:42 +02:00
tgbot_client_draft_per_chat_test.go fix(tgbot): keep the add-client draft with the chat that owns it (#6499) 2026-09-13 19:48:54 +02:00
tgbot_client_expiry_test.go fix(tgbot): render a disabled start-after-first-use client as days (#6500) 2026-09-13 19:48:14 +02:00
tgbot_client_links_authz_test.go fix(tgbot): require client ownership for non-admin link callbacks (#6489) 2026-09-13 11:46:14 +02:00
tgbot_declined_callback_test.go fix(tgbot): answer the callbacks the bot cannot route (#6493) 2026-09-13 11:47:22 +02:00
tgbot_delete_after_test.go Repo-wide self-correcting audit: 54 verified bug fixes (#5970) 2026-07-17 00:33:06 +02:00
tgbot_draft_render_test.go refactor(tgbot): make the add-client expiry presets say what they do (#6503) 2026-09-13 19:57:46 +02:00
tgbot_event.go feat(memory): add memory threshold alerts (#5366) 2026-06-21 17:45:33 +02:00
tgbot_inbound.go fix(tgbot): keep the add-client draft with the chat that owns it (#6499) 2026-09-13 19:48:54 +02:00
tgbot_report.go fix(tgbot): read the admin list and running flag under their mutex (#6491) 2026-09-13 11:46:36 +02:00
tgbot_report_batching_test.go fix(tgbot): send the admin traffic reports as one message (#6490) 2026-09-13 12:52:55 +02:00
tgbot_router.go refactor(tgbot): make the add-client expiry presets say what they do (#6503) 2026-09-13 19:57:46 +02:00
tgbot_send.go fix(tgbot): read the admin list and running flag under their mutex (#6491) 2026-09-13 11:46:36 +02:00
tgbot_send_test.go fix(tgbot): use a token telego accepts in the edit-message tests 2026-09-06 17:32:01 +02:00
tgbot_stale_button_test.go fix(tgbot): guard the mock Telegram server's call counts 2026-09-13 12:01:56 +02:00
tgbot_test.go refactor: focused service files, leaf subpackages, and an internal/ layout (#5167) 2026-06-10 15:19:22 +02:00