Skip to content

Commit

Permalink
multiple accounts using newline
Browse files Browse the repository at this point in the history
  • Loading branch information
sglkc committed Oct 13, 2024
1 parent 2ccfca1 commit afc00ef
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -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')
const games = process.env.GAMES.split('\n')
const discordWebhook = process.env.DISCORD_WEBHOOK
const discordUser = process.env.DISCORD_USER
const msgDelimiter = ':'
Expand All @@ -15,23 +15,14 @@ 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.')
}

if (!cookie) {
throw new Error('COOKIE environment variable not set!')
}
async function run(cookie, games=latestGames) {
latestGames = games
games = games.split(' ')

// 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} -----`)

Expand Down Expand Up @@ -112,11 +103,6 @@ async function main() {
if (discordWebhook && URL.canParse(discordWebhook)) {
await discordWebhookSend()
}

if (hasErrors) {
console.log('')
throw new Error('Error(s) occured.')
}
}

// custom log function to store messages
Expand Down Expand Up @@ -160,7 +146,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')

Expand All @@ -182,4 +168,20 @@ 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 (hasErrors) {
console.log('')
throw new Error('Error(s) occured.')
}

0 comments on commit afc00ef

Please sign in to comment.