mirror of
https://github.com/sys-32Dev/hoyolab-auto-daily.git
synced 2026-08-08 20:06:33 +00:00
12
.github/workflows/login.yml
vendored
12
.github/workflows/login.yml
vendored
@@ -18,8 +18,16 @@ jobs:
|
||||
node-version: "20"
|
||||
|
||||
- name: Check In
|
||||
run: node index.js ${{ vars.GAMES }}
|
||||
run: node index.js
|
||||
env:
|
||||
COOKIE: ${{ secrets.COOKIE }}
|
||||
GAMES: ${{ vars.GAMES }}
|
||||
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
|
||||
DISCORD_USER: ${{ secrets.DISCORD_USER }}
|
||||
DISCORD_USER: ${{ secrets.DISCORD_USER }}
|
||||
workflow-keepalive:
|
||||
if: github.event_name == 'schedule'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: write
|
||||
steps:
|
||||
- uses: liskin/gh-workflow-keepalive@v1
|
||||
|
||||
7
.github/workflows/version.yml
vendored
7
.github/workflows/version.yml
vendored
@@ -37,3 +37,10 @@ jobs:
|
||||
|
||||
exit 1
|
||||
fi
|
||||
workflow-keepalive:
|
||||
if: github.event_name == 'schedule'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: write
|
||||
steps:
|
||||
- uses: liskin/gh-workflow-keepalive@v1
|
||||
|
||||
17
README.md
17
README.md
@@ -10,6 +10,7 @@ Repository version:
|
||||
|
||||
- [Getting your cookie](#getting-your-cookie)
|
||||
- [Usage](#usage)
|
||||
- [Multiple Accounts](#multiple-accounts)
|
||||
- [Discord Webhook](#discord-webhook)
|
||||
- [FAQ](#faq)
|
||||
- [Is this safe?](#is-this-safe)
|
||||
@@ -109,6 +110,14 @@ You have to check in manually first to get your cookie, follow these steps (clic
|
||||
|
||||
10. You're set! Hop on your game the next day and see if you got the rewards
|
||||
|
||||
## Multiple Accounts
|
||||
|
||||
<details>
|
||||
<summary>To add other accounts, you can add another cookie and games in a new line like below.</summary>
|
||||
<img src="https://github.com/user-attachments/assets/99fd25cd-71f6-4aae-9949-11d055fadf73" />
|
||||
<img src="https://github.com/user-attachments/assets/4a56f4e1-8fb4-4137-acc6-ac30cade78f1" />
|
||||
</details>
|
||||
|
||||
## Discord Webhook
|
||||
|
||||
You may use Discord webhook to send notifications to your channel!
|
||||
@@ -133,7 +142,13 @@ You may use Discord webhook to send notifications to your channel!
|
||||
<img src="https://github.com/sglkc/hoyolab-auto-daily/assets/31957516/15b029ff-906d-472c-b356-ae9efed4477b" />
|
||||
</details>
|
||||
|
||||
5. You may trigger the check in manually and see if the messages got sent
|
||||
5. <details>
|
||||
<summary>(Optional) If you want to be tagged on check in, add `DISCORD_USER` variable with your Discord ID.</summary>
|
||||
<img src="https://github.com/user-attachments/assets/995a4b18-4c22-4dcd-9a2e-90fac74079c1" />
|
||||
<img src="https://github.com/user-attachments/assets/52dff051-abb4-4cc0-b834-685d49a06731" />
|
||||
</details>
|
||||
|
||||
6. You may trigger the check in manually and see if the messages got sent
|
||||
|
||||
## FAQ
|
||||
|
||||
|
||||
65
index.js
65
index.js
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
const cookie = process.env.COOKIE
|
||||
const cookies = process.env.COOKIE.split('\n').map(s => s.trim())
|
||||
const games = process.env.GAMES.split('\n').map(s => s.trim())
|
||||
const discordWebhook = process.env.DISCORD_WEBHOOK
|
||||
const discordUser = process.env.DISCORD_USER
|
||||
const msgDelimiter = ':'
|
||||
@@ -15,28 +15,23 @@ const endpoints = {
|
||||
}
|
||||
|
||||
let hasErrors = false
|
||||
let latestGames = []
|
||||
|
||||
async function main() {
|
||||
if (!args.length) {
|
||||
log('error', 'Argument is empty!')
|
||||
log('info', 'Usage: node index.js [zzz] [gi] [hsr] [hi3] [tot]')
|
||||
log('info', 'Example: node index.js hsr')
|
||||
log('info', ' node index.js zzz gi hsr')
|
||||
throw new Error('No argument passed.')
|
||||
async function run(cookie, games) {
|
||||
if (!games) {
|
||||
games = latestGames
|
||||
} else {
|
||||
games = games.split(' ')
|
||||
latestGames = games
|
||||
}
|
||||
|
||||
if (!cookie) {
|
||||
throw new Error('COOKIE environment variable not set!')
|
||||
}
|
||||
|
||||
// begin processing command arguments
|
||||
for (const arg of args) {
|
||||
const game = arg.toLowerCase()
|
||||
for (let game of games) {
|
||||
game = game.toLowerCase()
|
||||
|
||||
log('debug', `\n----- CHECKING IN FOR ${game} -----`)
|
||||
|
||||
if (!(game in endpoints)) {
|
||||
log('error', `Game ${arg} is invalid. Available games are: zzz, gi, hsr, hi3, and tot`)
|
||||
log('error', `Game ${game} is invalid. Available games are: zzz, gi, hsr, hi3, and tot`)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -73,6 +68,8 @@ async function main() {
|
||||
headers.set('sec-fetch-site', 'same-site')
|
||||
headers.set('sec-gpc', '1')
|
||||
|
||||
headers.set("x-rpc-signgame", game)
|
||||
|
||||
headers.set('user-agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36')
|
||||
|
||||
const res = await fetch(url, { method: 'POST', headers, body })
|
||||
@@ -105,16 +102,6 @@ async function main() {
|
||||
|
||||
log('error', game, `Error undocumented, report to Issues page if this persists`)
|
||||
}
|
||||
|
||||
// send to discord webhook if set and valid url
|
||||
if (discordWebhook && URL.canParse(discordWebhook)) {
|
||||
await discordWebhookSend()
|
||||
}
|
||||
|
||||
if (hasErrors) {
|
||||
console.log('')
|
||||
throw new Error('Error(s) occured.')
|
||||
}
|
||||
}
|
||||
|
||||
// custom log function to store messages
|
||||
@@ -158,7 +145,7 @@ async function discordWebhookSend() {
|
||||
}
|
||||
let discordMsg = ""
|
||||
if (discordUser) {
|
||||
discordMsg = `<@${discordUser}>\n`
|
||||
discordMsg = `<@${discordUser}>\n`
|
||||
}
|
||||
discordMsg += messages.map(msg => `(${msg.type.toUpperCase()}) ${msg.string}`).join('\n')
|
||||
|
||||
@@ -180,4 +167,24 @@ async function discordWebhookSend() {
|
||||
log('error', 'Error sending message to Discord webhook, please check URL and permissions')
|
||||
}
|
||||
|
||||
await main()
|
||||
if (!cookies || !cookies.length) {
|
||||
throw new Error('COOKIE environment variable not set!')
|
||||
}
|
||||
|
||||
if (!games || !games.length) {
|
||||
throw new Error('GAMES environment variable not set!')
|
||||
}
|
||||
|
||||
for (const index in cookies) {
|
||||
log('info', `-- CHECKING IN FOR ACCOUNT ${Number(index) + 1} --`)
|
||||
await run(cookies[index], games[index])
|
||||
}
|
||||
|
||||
if (discordWebhook && URL.canParse(discordWebhook)) {
|
||||
await discordWebhookSend()
|
||||
}
|
||||
|
||||
if (hasErrors) {
|
||||
console.log('')
|
||||
throw new Error('Error(s) occured.')
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hoyolab-auto-daily",
|
||||
"version": "1.0.3",
|
||||
"version": "1.1.0",
|
||||
"description": "Easiest, full free, and no BS Hoyolab games daily check-in using GitHub Actions",
|
||||
"private": true,
|
||||
"main": "index.js",
|
||||
|
||||
Reference in New Issue
Block a user