Merge pull request #1 from sglkc/master

a
This commit is contained in:
sys_32
2024-10-14 16:07:00 -07:00
committed by GitHub
5 changed files with 70 additions and 33 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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.')
}

View File

@@ -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",