mirror of
https://github.com/sys-32Dev/hoyolab-auto-daily.git
synced 2026-10-07 20:10:03 +00:00
feat: make check-in language configurable via HOYOLAB_LANG variable
The check-in request hardcoded `lang=en-us`, so the reward messages HoYoLAB shows in game and in the check-in history were always English. Read the locale from an optional `HOYOLAB_LANG` repository variable instead, defaulting to `en-us`. The name is prefixed rather than a plain `LANGUAGE` to avoid colliding with the GNU gettext variable of that name when running index.js locally. `||` is used rather than `??` because an unset repository variable is injected as an empty string by Actions, which `??` would pass through as an empty `lang`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1
.github/workflows/login.yml
vendored
1
.github/workflows/login.yml
vendored
@@ -30,6 +30,7 @@ jobs:
|
||||
DISCORD_USER: ${{ secrets.DISCORD_USER }}
|
||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
||||
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||
HOYOLAB_LANG: ${{ vars.HOYOLAB_LANG }}
|
||||
workflow-keepalive:
|
||||
if: github.event_name == 'schedule'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
15
README.md
15
README.md
@@ -11,6 +11,7 @@ Repository version:
|
||||
- [Getting your cookie](#getting-your-cookie)
|
||||
- [Usage](#usage)
|
||||
- [Multiple Accounts](#multiple-accounts)
|
||||
- [Language](#language)
|
||||
- [Discord Webhook](#discord-webhook)
|
||||
- [Telegram](#telegram)
|
||||
- [FAQ](#faq)
|
||||
@@ -119,6 +120,20 @@ You have to check in manually first to get your cookie, follow these steps (clic
|
||||
<img src="https://github.com/user-attachments/assets/4a56f4e1-8fb4-4137-acc6-ac30cade78f1" />
|
||||
</details>
|
||||
|
||||
## Language
|
||||
|
||||
Check in requests are made in English (`en-us`) by default. The language decides how
|
||||
HoYoLAB localizes the check in, so the reward messages you see in game and in the
|
||||
check in history follow it.
|
||||
|
||||
To change it, create a new repository *variable* (Settings > Secrets and variables >
|
||||
Actions > Variables) named `HOYOLAB_LANG` with one of the values HoYoLAB supports:
|
||||
|
||||
`zh-cn`, `zh-tw`, `de-de`, `en-us`, `es-es`, `fr-fr`, `id-id`, `it-it`, `ja-jp`,
|
||||
`ko-kr`, `pt-pt`, `ru-ru`, `th-th`, `tr-tr`, `vi-vn`
|
||||
|
||||
Leaving the variable unset keeps the current `en-us` behaviour.
|
||||
|
||||
## Discord Webhook
|
||||
|
||||
You may use Discord webhook to send notifications to your channel!
|
||||
|
||||
9
index.js
9
index.js
@@ -9,6 +9,11 @@ const discordWebhook = process.env.DISCORD_WEBHOOK
|
||||
const discordUser = process.env.DISCORD_USER
|
||||
const telegramToken = process.env.TELEGRAM_TOKEN
|
||||
const telegramChat = process.env.TELEGRAM_CHAT_ID
|
||||
// Locale sent to the check-in API, which decides the language of the reward
|
||||
// messages shown in-game and in the HoYoLAB check-in history.
|
||||
// `||` (not `??`) is intentional: an unset repository variable is injected as an
|
||||
// empty string by Actions, and an empty `lang` would be sent to the API.
|
||||
const language = process.env.HOYOLAB_LANG?.trim() || 'en-us'
|
||||
const msgDelimiter = ':'
|
||||
const icon = { info: '✅', error: '❌' }
|
||||
const messages = []
|
||||
@@ -52,10 +57,10 @@ async function run(cookie, games) {
|
||||
const url = new URL(endpoint)
|
||||
const actId = url.searchParams.get('act_id')
|
||||
|
||||
url.searchParams.set('lang', 'en-us')
|
||||
url.searchParams.set('lang', language)
|
||||
|
||||
const body = JSON.stringify({
|
||||
lang: 'en-us',
|
||||
lang: language,
|
||||
act_id: actId
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user