From ce22c9dc8c0a56bb8046822c990eb50f51a1202c Mon Sep 17 00:00:00 2001 From: hccluck Date: Wed, 26 Jan 2022 11:26:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=B8=B8=E6=88=8F=E5=A5=96=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/juejin_helper.yml | 3 +- README.md | 3 +- index.js | 48 ++-- package-lock.json | 362 ++++++++++++++++++++++++++-- package.json | 8 +- src/config.js | 4 +- src/dipLucky.js | 2 +- src/game/Game.js | 255 ++++++++++++++++++++ src/game/autoGame.js | 116 +++++++++ src/game/run.js | 11 + src/getPoint.js | 24 ++ 11 files changed, 784 insertions(+), 52 deletions(-) create mode 100644 src/game/Game.js create mode 100644 src/game/autoGame.js create mode 100644 src/game/run.js create mode 100644 src/getPoint.js diff --git a/.github/workflows/juejin_helper.yml b/.github/workflows/juejin_helper.yml index 751dafa..827673f 100644 --- a/.github/workflows/juejin_helper.yml +++ b/.github/workflows/juejin_helper.yml @@ -33,4 +33,5 @@ jobs: USER: ${{ secrets.USER }} PASS: ${{ secrets.PASS }} TO: ${{ secrets.TO }} - run: npm ci && node index.js "${COOKIE}" "${USER}" "${PASS}" "${TO}" + UID: ${{ secrets.UID }} + run: npm ci && node index.js "${COOKIE}" "${USER}" "${PASS}" "${TO}" "${UID}" diff --git a/README.md b/README.md index 93a18a1..bfb6a34 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## 定时任务脚本 -掘金自动签到 签到后会获得一次免费抽奖机会,自动触发免费抽奖,自动触发沾喜气。 +掘金自动签到 签到后会获得一次免费抽奖机会,自动触发免费抽奖,自动触发沾喜气,自动获取游戏奖励。 执行结束发送邮件通知签到结果。 使用方法:fork 本仓库 @@ -14,6 +14,7 @@ | USER | 发送邮件的邮箱地址,该邮箱需要开启 SMTP | 否,如不想邮件提醒,则可随意填一个值 | | PASS | 该邮箱的 SMTP 密码 | 否,如不想邮件提醒,则可随意填一个值 | | TO | 接收邮件的邮箱 | 否,如不想邮件提醒,则可随意填一个值 | +| UID | 游戏id `控制台执行( window.__NUXT__.state.auth.user.id )获得` | 否 | `注意:掘金的cookie大概有一个月以上的有效期,所以需要定期更新Secret` diff --git a/index.js b/index.js index 2a5442f..d902edf 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,17 @@ -const fetch = require('node-fetch'); const sign_in = require('./src/signIn'); const draw = require('./src/draw'); const dipLucky = require('./src/dipLucky'); const sendMail = require('./src/sendMail'); +const getPoint = require('./src/getPoint'); -const { headers } = require('./src/config'); +const { autoGame } = require('./src/game/autoGame'); (async () => { + // 上次分数 + const yesterday_score = await getPoint(); + + console.log(`昨日矿石:${yesterday_score}`); + let sign_res = ''; try { @@ -26,14 +31,17 @@ const { headers } = require('./src/config'); console.log(draw_res); + let game_res = '挖矿成功!'; + try { + await autoGame(); + } catch (error) { + game_res = '挖矿失败!'; + } + // 当前分数 - const { data } = await fetch('https://api.juejin.cn/growth_api/v1/get_cur_point', { - headers, - method: 'GET', - credentials: 'include' - }).then((res) => res.json()); + const now_score = await getPoint(); - console.log(`当前矿石:${data}`); + console.log(`当前矿石:${now_score}`); let dip_res; try { @@ -45,17 +53,19 @@ const { headers } = require('./src/config'); console.log(dip_res); try { - await sendMail({ - from: '掘金', - subject: '定时任务', - html: ` -

自动签到通知

-

签到结果:${sign_res}

-

抽奖结果:${draw_res}

-

沾喜气结果:${dip_res}

-

当前矿石:${data}


- ` - }); + const html = ` +

自动签到通知

+

沾喜气结果:${dip_res}

+

当前矿石:${now_score}

+

较昨日增长:${now_score - yesterday_score}

+

签到结果:${sign_res}

+

抽奖结果:${draw_res}

+

游戏结果:${game_res}


+ `; + + console.log(html); + + await sendMail({ from: '掘金', subject: '定时任务', html }); console.log('邮件发送成功!'); } catch (error) { diff --git a/package-lock.json b/package-lock.json index c4dd61c..6b2298d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,45 +1,357 @@ { "name": "public_actions", "version": "1.0.0", - "lockfileVersion": 2, + "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "name": "public_actions", + "dependencies": { + "@sindresorhus/is": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.3.0.tgz", + "integrity": "sha512-wwOvh0eO3PiTEivGJWiZ+b946SlMSb4pe+y+Ur/4S87cwo09pYi+FWHHnbrM3W9W7cBYKDqQXcrFYjYUCOJUEQ==" + }, + "@szmarczak/http-timer": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz", + "integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==", + "requires": { + "defer-to-connect": "^2.0.0" + } + }, + "@types/cacheable-request": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz", + "integrity": "sha512-B3xVo+dlKM6nnKTcmm5ZtY/OL8bOAOd2Olee9M1zft65ox50OzjEHW91sDiU9j6cvW8Ejg1/Qkf4xd2kugApUA==", + "requires": { + "@types/http-cache-semantics": "*", + "@types/keyv": "*", + "@types/node": "*", + "@types/responselike": "*" + } + }, + "@types/http-cache-semantics": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", + "integrity": "sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==" + }, + "@types/keyv": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.3.tgz", + "integrity": "sha512-FXCJgyyN3ivVgRoml4h94G/p3kY+u/B86La+QptcqJaWtBWtmc6TtkNfS40n9bIvyLteHh7zXOtgbobORKPbDg==", + "requires": { + "@types/node": "*" + } + }, + "@types/node": { + "version": "17.0.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.12.tgz", + "integrity": "sha512-4YpbAsnJXWYK/fpTVFlMIcUIho2AYCi4wg5aNPrG1ng7fn/1/RZfCIpRCiBX+12RVa34RluilnvCqD+g3KiSiA==" + }, + "@types/responselike": { "version": "1.0.0", - "license": "ISC", + "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", + "integrity": "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==", + "requires": { + "@types/node": "*" + } + }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" + }, + "cacheable-lookup": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz", + "integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==" + }, + "cacheable-request": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.2.tgz", + "integrity": "sha512-pouW8/FmiPQbuGpkXQ9BAPv/Mo5xDGANgSNXzTzJ8DrKGuXOssM4wIQRjfanNRh3Yu5cfYPvcorqbhg2KIJtew==", + "requires": { + "clone-response": "^1.0.2", + "get-stream": "^5.1.0", + "http-cache-semantics": "^4.0.0", + "keyv": "^4.0.0", + "lowercase-keys": "^2.0.0", + "normalize-url": "^6.0.1", + "responselike": "^2.0.0" + } + }, + "clone-response": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", + "integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=", + "requires": { + "mimic-response": "^1.0.0" + } + }, + "decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "requires": { + "mimic-response": "^3.1.0" + }, "dependencies": { - "node-fetch": "^2.6.1", - "nodemailer": "^6.6.3" + "mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==" + } } }, - "node_modules/node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", - "engines": { - "node": "4.x || >=6.0.0" + "defer-to-connect": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz", + "integrity": "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==" + }, + "ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "requires": { + "safe-buffer": "^5.0.1" } }, - "node_modules/nodemailer": { - "version": "6.6.3", - "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.3.tgz", - "integrity": "sha512-faZFufgTMrphYoDjvyVpbpJcYzwyFnbAMmQtj1lVBYAUSm3SOy2fIdd9+Mr4UxPosBa0JRw9bJoIwQn+nswiew==", - "engines": { - "node": ">=6.0.0" + "end-of-stream": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "requires": { + "once": "^1.4.0" } - } - }, - "dependencies": { + }, + "get-stream": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", + "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", + "requires": { + "pump": "^3.0.0" + } + }, + "got": { + "version": "11.8.2", + "resolved": "https://registry.npmjs.org/got/-/got-11.8.2.tgz", + "integrity": "sha512-D0QywKgIe30ODs+fm8wMZiAcZjypcCodPNuMz5H9Mny7RJ+IjJ10BdmGW7OM7fHXP+O7r6ZwapQ/YQmMSvB0UQ==", + "requires": { + "@sindresorhus/is": "^4.0.0", + "@szmarczak/http-timer": "^4.0.5", + "@types/cacheable-request": "^6.0.1", + "@types/responselike": "^1.0.0", + "cacheable-lookup": "^5.0.3", + "cacheable-request": "^7.0.1", + "decompress-response": "^6.0.0", + "http2-wrapper": "^1.0.0-beta.5.2", + "lowercase-keys": "^2.0.0", + "p-cancelable": "^2.0.0", + "responselike": "^2.0.0" + } + }, + "http-cache-semantics": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", + "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" + }, + "http2-wrapper": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz", + "integrity": "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==", + "requires": { + "quick-lru": "^5.1.1", + "resolve-alpn": "^1.0.0" + } + }, + "json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==" + }, + "jsonwebtoken": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", + "integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==", + "requires": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^5.6.0" + } + }, + "jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "requires": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "requires": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, + "keyv": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.5.tgz", + "integrity": "sha512-531pkGLqV3BMg0eDqqJFI0R1mkK1Nm5xIP2mM6keP5P8WfFtCkg2IOwplTUmlGoTgIg9yQYZ/kdihhz89XH3vA==", + "requires": { + "json-buffer": "3.0.1" + } + }, + "lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=" + }, + "lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=" + }, + "lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M=" + }, + "lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" + }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" + }, + "lowercase-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", + "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==" + }, + "mimic-response": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", + "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" + }, + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, "node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "requires": { + "whatwg-url": "^5.0.0" + } }, "nodemailer": { "version": "6.6.3", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.3.tgz", "integrity": "sha512-faZFufgTMrphYoDjvyVpbpJcYzwyFnbAMmQtj1lVBYAUSm3SOy2fIdd9+Mr4UxPosBa0JRw9bJoIwQn+nswiew==" + }, + "normalize-url": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz", + "integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==" + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "p-cancelable": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", + "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==" + }, + "pump": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", + "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "quick-lru": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", + "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==" + }, + "resolve-alpn": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz", + "integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==" + }, + "responselike": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz", + "integrity": "sha512-xH48u3FTB9VsZw7R+vvgaKeLKzT6jOogbQhEe/jewwnZgzPcnyWui2Av6JpoYZF/91uueC+lqhWqeURw5/qhCw==", + "requires": { + "lowercase-keys": "^2.0.0" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + }, + "webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + }, + "whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "requires": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" } } } diff --git a/package.json b/package.json index d0e42a9..e3e8cad 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "public_actions", "version": "1.0.0", - "description": "定时任务 自动签到 自动抽奖", + "description": "定时任务 自动签到 自动抽奖 自动粘喜气 自动游戏挖矿", "main": "index.js", "scripts": { "serve": "node index.js" @@ -11,14 +11,16 @@ "url": "git+https://github.com/hccluck/public_actions.git" }, "keywords": [], - "author": "", + "author": "hccluck", "license": "ISC", "bugs": { "url": "https://github.com/hccluck/public_actions/issues" }, "homepage": "https://github.com/hccluck/public_actions#readme", "dependencies": { - "node-fetch": "^2.6.1", + "got": "^11.8.2", + "jsonwebtoken": "^8.5.1", + "node-fetch": "^2.6.7", "nodemailer": "^6.6.3" } } diff --git a/src/config.js b/src/config.js index 0872ee0..9f38c93 100644 --- a/src/config.js +++ b/src/config.js @@ -1,4 +1,4 @@ -const [cookie, user, pass, to] = process.argv.slice(2); +const [cookie, user, pass, to, uid] = process.argv.slice(2); const headers = { 'content-type': 'application/json; charset=utf-8', @@ -12,4 +12,4 @@ const headers = { cookie }; -module.exports = { headers, user, pass, to }; +module.exports = { headers, user, pass, to, uid }; diff --git a/src/dipLucky.js b/src/dipLucky.js index c70ddc9..a3fa8ed 100644 --- a/src/dipLucky.js +++ b/src/dipLucky.js @@ -22,7 +22,7 @@ async function dipLucky() { body: JSON.stringify({ lottery_history_id: list.data.lotteries[0].history_id }) }).then((res) => res.json()); - if (res.err_no !== 0) return Promise.reject('网络异常!'); + if (res.err_no !== 0) return Promise.reject('可能是由于cookie导致的网络异常!'); if (res.data.has_dip) return `今日已经沾过喜气!喜气值:${res.data.total_value}`; diff --git a/src/game/Game.js b/src/game/Game.js new file mode 100644 index 0000000..3dcbf4b --- /dev/null +++ b/src/game/Game.js @@ -0,0 +1,255 @@ +const got = require('got') +const jwt = require('jsonwebtoken') + +const GET_TOKEN_URL = 'https://juejin.cn/get/token' +const HEADER = { + 'user-agent': + 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36' +} + +const HOST_BASE = 'https://juejin-game.bytedance.com/game/sea-gold' +const START_GAME_URL = HOST_BASE + '/game/start?' +const LOGIN_GAME_URL = HOST_BASE + '/user/login?' +const GET_INFO_URL = HOST_BASE + '/home/info?' +const COMMAND_URL = HOST_BASE + '/game/command?' +const OVER_GAME_URL = HOST_BASE + '/game/over?' +const FRESH_MAP_URL = HOST_BASE + '/game/fresh_map?' +const ROLE_LIST = { + CLICK: 2, + YOYO: 1, + HAWKING: 3 +} + +const PUBLIC_KEY = `-----BEGIN EC PARAMETERS----- +BggqhkjOPQMBBw== +-----END EC PARAMETERS----- +-----BEGIN EC PRIVATE KEY----- +MHcCAQEEIDB7KMVQd+eeKt7AwDMMUaT7DE3Sl0Mto3LEojnEkRiAoAoGCCqGSM49 +AwEHoUQDQgAEEkViJDU8lYJUenS6IxPlvFJtUCDNF0c/F/cX07KCweC4Q/nOKsoU +nYJsb4O8lMqNXaI1j16OmXk9CkcQQXbzfg== +-----END EC PRIVATE KEY----- +` +class Game { + #uid + #username + #cookie + #authorization + #gameId + + constructor(uid, cookie) { + this.#uid = uid + this.#cookie = cookie + } + + /** + * @desc 获取authorization授权 + * @returns + */ + #getToken = () => { + const cookie = this.#cookie + return got.post(GET_TOKEN_URL, { + hooks: { + beforeRequest: [ + options => { + Object.assign(options.headers, { + ...HEADER, + cookie + }) + } + ] + } + }) + } + + /** + * @desc 获取用户信息 + * @returns + */ + #getInfo = () => { + const URL = GET_INFO_URL + `uid=${this.#uid}&time=` + new Date().getTime() + const authorization = this.#authorization + return got.get(URL, { + hooks: { + beforeRequest: [ + options => { + Object.assign(options.headers, { + ...HEADER, + authorization: authorization + }) + } + ] + } + }) + } + + /** + * @desc 登录游戏 + * @returns + */ + #loginGame = () => { + const URL = LOGIN_GAME_URL + `uid=${this.#uid}&time=` + new Date().getTime() + const body = { name: this.#username } + const authorization = this.#authorization + return got.post(URL, { + hooks: { + beforeRequest: [ + options => { + Object.assign(options.headers, { + ...HEADER, + authorization: authorization + }) + } + ] + }, + json: body + }) + } + + /** + * @desc 开始游戏 + * @param {Number} roleId 角色id + */ + #startGame = roleId => { + const URL = START_GAME_URL + `uid=${this.#uid}&time=` + new Date().getTime() + const body = { roleId } + const authorization = this.#authorization + return got.post(URL, { + hooks: { + beforeRequest: [ + options => { + Object.assign(options.headers, { + ...HEADER, + authorization: authorization + }) + } + ] + }, + json: body + }) + } + + /** + * @desc 移动 + * @param {Array} command 移动参数 例(向上一步,向右6步):{"command":["U", {"times":6,"command":["R"]}]} + */ + move = command => { + const NOW_TIME = new Date().getTime() + const URL = COMMAND_URL + `uid=${this.#uid}&time=` + NOW_TIME + const body = { command } + const authorization = this.#authorization + const xttgameid = this.#getSign(NOW_TIME) + return got.post(URL, { + hooks: { + beforeRequest: [ + options => { + Object.assign(options.headers, { + ...HEADER, + authorization: authorization, + 'x-tt-gameid': xttgameid + }) + } + ] + }, + json: body + }) + } + + /** + * @desc 计算签名 + * @param {Number} t 13位时间戳 + * @returns {String} sign + */ + #getSign = t => { + return jwt.sign( + { + gameId: this.#gameId, + time: t + }, + PUBLIC_KEY, + { + algorithm: 'ES256', + expiresIn: 2592e3, + header: { + alg: 'ES256', + typ: 'JWT' + } + } + ) + } + + /** + * @desc 结束游戏 + */ + outGame = () => { + const URL = OVER_GAME_URL + `uid=${this.#uid}&time=` + new Date().getTime() + const body = { isButton: 1 } + const authorization = this.#authorization + return got.post(URL, { + hooks: { + beforeRequest: [ + options => { + Object.assign(options.headers, { + ...HEADER, + authorization: authorization + }) + } + ] + }, + json: body + }) + } + + /** + * @desc 刷新地图 + */ + freshMap = () => { + const URL = FRESH_MAP_URL + `uid=${this.#uid}&time=` + new Date().getTime() + const body = {} + const authorization = this.#authorization + return got.post(URL, { + hooks: { + beforeRequest: [ + options => { + Object.assign(options.headers, { + ...HEADER, + authorization: authorization + }) + } + ] + }, + json: body + }) + } + + /** + * @desc 启动游戏 + * @returns {Boolean} 是否启动成功 + */ + openGame = async () => { + // 1.获取授权 + let res = await this.#getToken().json() + this.#authorization = 'Bearer ' + res.data + + // 2.获取用户名 + res = await this.#getInfo().json() + this.#username = res.data.userInfo.name + const gameStatus = res.data.gameStatus + + // 3.登录游戏 + await this.#loginGame().json() + + if (gameStatus !== 0) { + // 如果已经在游戏中那么先退出游戏 + await this.outGame() + } + + // 4.开始游戏,获取游戏id + res = await this.#startGame(ROLE_LIST.CLICK).json() + this.#gameId = res.data.gameId + + // 5.游戏启动成功返回游戏信息 + return this.#gameId !== undefined ? res.data : undefined + } +} + +exports.Game = Game \ No newline at end of file diff --git a/src/game/autoGame.js b/src/game/autoGame.js new file mode 100644 index 0000000..7691d9f --- /dev/null +++ b/src/game/autoGame.js @@ -0,0 +1,116 @@ +const { headers, uid } = require('../config'); + +const { Game } = require('./Game'); + +const NAGETIVE_DIRECTION = { + U: 'D', + L: 'R', + D: 'U', + R: 'L' +}; +const COLUMN = 6; +const OBSTACLE = 6; + +const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time)); + +const random = (max, min = 0) => Math.floor(Math.random() * (max - min + 1) + min); + +/** + * @desc 一维数组转二维数组 + * @param {Array} arr 原数据 + * @param {Number} num 每个维度的元素数量 + */ +function ArrayOneToTwo(arr, num) { + let arrList = []; + arr.map((item, index) => { + if (index % num == 0) { + arrList.push([item]); + } else { + arrList[arrList.length - 1].push(item); + } + }); + return arrList; +} + +/** + * @desc 计算行走轨迹 + * @param {Array} maps 地图 + */ +const getTarck = (maps) => { + const mapsTrack = [ + [3, 1, 'U'], + [2, 2, 'L'], + [4, 2, 'D'], + [3, 3, 'R'] + ]; + const mapsTree = ArrayOneToTwo(maps, COLUMN); + + // 过滤掉有障碍物的位置 + const trackXY = mapsTrack.filter((item) => { + const xy = mapsTree[item[0]][item[1]]; + return xy !== OBSTACLE; + }); + + // 移动后反方向移动回初始位置 + const trackList = trackXY + .map((item) => { + return [item[2], NAGETIVE_DIRECTION[item[2]]]; + }) + .flat(); + return trackList; +}; + +let runNum = 0; +let retry = false; // 报错后,尝试再次执行 +const autoGame = async () => { + if (!uid) return Promise.reject('未配置UID'); + + try { + runNum++; + if (runNum > 500) return; // 防止死循环 + let exp = new Game(uid, headers.cookie); + + let gameData = await exp.openGame(); + + console.log(gameData !== undefined ? 'Game Start🎮' : 'Game Start Error❌'); + if (!gameData) return Promise.reject('未配置UID'); + + const { mapData } = gameData; + const track = getTarck(mapData); + + await sleep(2000); + await exp.move(track); + + await sleep(2000); + const res = await exp.outGame(); + + res.body = JSON.parse(res.body); + console.log( + `Game over, 本次获得: ${res.body.data.realDiamond}, 今日已获得: ${res.body.data.todayDiamond}, 今日上限: ${res.body.data.todayLimitDiamond}` + ); + + if (res.body.data.realDiamond < 40) { + // 奖励小于40刷新下地图 + await sleep(2000); + await exp.freshMap(); + } + // 没达到今日上限继续自动游戏 + if (res.body.data.todayDiamond < res.body.data.todayLimitDiamond) { + const time = random(15000, 10000); + console.log(`${time}ms后开始下一轮游戏🎮,请稍等~`); + await sleep(time); + await autoGame(); + } else { + console.log('今日奖励已达上限!'); + } + } catch (e) { + console.log('捕获到错误 => ', e); + if (retry) return Promise.reject(e); + console.log('20s后尝试再次执行🎮'); + retry = true; + await sleep(20000); // 设置10s执行一次,防止接口调用太过频繁,服务器报500的错 + await autoGame(); + } +}; + +exports.autoGame = autoGame; diff --git a/src/game/run.js b/src/game/run.js new file mode 100644 index 0000000..8d43f87 --- /dev/null +++ b/src/game/run.js @@ -0,0 +1,11 @@ +const { uid } = require('../config') + +const { autoGame } = require('./autoGame') + +function running() { + if (!uid) return + autoGame() + console.log('game running...') +} + +running() diff --git a/src/getPoint.js b/src/getPoint.js new file mode 100644 index 0000000..89ff44a --- /dev/null +++ b/src/getPoint.js @@ -0,0 +1,24 @@ +/* + * + * 查询当前分数 + * + **/ + +const fetch = require('node-fetch'); +const { headers } = require('./config'); + +async function get_cur_point() { + try { + const { data } = await fetch('https://api.juejin.cn/growth_api/v1/get_cur_point', { + headers, + method: 'GET', + credentials: 'include' + }).then((res) => res.json()); + + return data; + } catch (error) { + return 0; + } +} + +module.exports = get_cur_point;