From d1168bf30e0144d3bce890aead251a15a2150fbd Mon Sep 17 00:00:00 2001 From: SHIKEI <92728681+Liqu001@users.noreply.github.com> Date: Fri, 15 Dec 2023 23:06:24 +0800 Subject: [PATCH] Update main.js --- main.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index cc9d81c..22f4b31 100644 --- a/main.js +++ b/main.js @@ -1,34 +1,33 @@ -const glados = async () => { - const cookie = process.env.GLADOS - if (!cookie) return +const gladosTask = async (cookie) => { + if (!cookie) return; try { const headers = { 'cookie': cookie, 'referer': 'https://glados.rocks/console/checkin', 'user-agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)', - } + }; const checkin = await fetch('https://glados.rocks/api/user/checkin', { method: 'POST', headers: { ...headers, 'content-type': 'application/json' }, body: '{"token":"glados.one"}', - }).then((r) => r.json()) + }).then((r) => r.json()); const status = await fetch('https://glados.rocks/api/user/status', { method: 'GET', headers, - }).then((r) => r.json()) + }).then((r) => r.json()); return [ 'Checkin OK', `${checkin.message}`, `Left Days ${Number(status.data.leftDays)}`, - ] + ]; } catch (error) { return [ 'Checkin Error', `${error}`, `<${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}>`, - ] + ]; } -} +}; const notify = async (contents) => { const token = process.env.NOTIFY @@ -46,7 +45,16 @@ const notify = async (contents) => { } const main = async () => { - await notify(await glados()) -} + const results = await Promise.all([ + gladosTask(process.env.GLADOS), + gladosTask(process.env.GLADOS2) + ]); + + for (const result of results) { + if (result) { + await notify(result); + } + } +}; -main() +main();