From 9cc9eea6c967bfc1dbfc3662e38632510d320f1b Mon Sep 17 00:00:00 2001 From: derek Date: Fri, 4 Feb 2022 19:41:25 +0800 Subject: [PATCH 01/27] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4api?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- scripts/api/api.js | 57 ------------------ scripts/api/juejin-api.js | 67 --------------------- scripts/api/juejin-game-api.js | 105 --------------------------------- scripts/checkin.js | 9 ++- scripts/seaGold.js | 24 ++++---- yarn.lock | 74 ++++++++++++----------- 7 files changed, 63 insertions(+), 276 deletions(-) delete mode 100644 scripts/api/api.js delete mode 100644 scripts/api/juejin-api.js delete mode 100644 scripts/api/juejin-game-api.js diff --git a/package.json b/package.json index 3f6ba950..a88acbce 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ }, "dependencies": { "fast-astar": "^1.0.6", - "jsonwebtoken": "^8.5.1", - "node-fetch": "^2.6.1", + "juejin-helper": "^0.1.0", "nodemailer": "^6.7.0" }, "repository": { diff --git a/scripts/api/api.js b/scripts/api/api.js deleted file mode 100644 index 8b9e6241..00000000 --- a/scripts/api/api.js +++ /dev/null @@ -1,57 +0,0 @@ -const fetch = require("node-fetch"); - -class Api { - baseURL = ""; - headers = { - "content-type": "application/json; charset=utf-8", - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36", - "accept-encoding": "gzip, deflate, br", - "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7", - "sec-ch-ua": `"Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"`, - "sec-ch-ua-mobile": "?0", - accept: "*/*", - credentials: "include" - }; - - requestInterceptor = config => config; - responseInterceptor = res => res; - - async request(config) { - config = this.requestInterceptor({ - baseURL: config.baseURL || this.baseURL, - url: config.url, - method: (config.method || "get").toLocaleUpperCase(), - headers: { - ...this.headers, - ...config.headers - }, - data: config.data - }); - - const response = await fetch(config.baseURL + config.url, { - method: config.method, - headers: config.headers, - body: config.method !== "GET" ? JSON.stringify(config.data) : undefined - }); - - return this.responseInterceptor(await response.json()); - } - - async get(url, config) { - return this.request({ - ...config, - url, - method: "get" - }); - } - - async post(url, config) { - return this.request({ - ...config, - url, - method: "post" - }); - } -} - -module.exports = Api; diff --git a/scripts/api/juejin-api.js b/scripts/api/juejin-api.js deleted file mode 100644 index a1e3bd60..00000000 --- a/scripts/api/juejin-api.js +++ /dev/null @@ -1,67 +0,0 @@ -const Api = require("./api"); -const env = require("../utils/env"); - -class JuejinApi extends Api { - constructor() { - super(); - this.baseURL = "https://api.juejin.cn"; - this.headers.referer = "https://juejin.cn/"; - this.headers.cookie = env.COOKIE; - } - - responseInterceptor = res => { - if (res.err_no) { - throw new Error(res.err_msg); - } - return res.data; - } - - async getToken() { - return this.get("/get/token", { - baseURL: "https://juejin.cn" - }); - } - - async getUserInfo() { - return this.get("/user_api/v1/user/get"); - } - - async getLotteryConfig() { - return this.get("/growth_api/v1/lottery_config/get"); - } - - async getCurrentPoint() { - return this.get("/growth_api/v1/get_cur_point"); - } - - async drawLottery() { - return this.post("/growth_api/v1/lottery/draw"); - } - - async checkIn() { - return this.post("/growth_api/v1/check_in"); - } - - async getLotteriesLuckyUsers() { - return this.post("/growth_api/v1/lottery_history/global_big", { - data: { - page_no: 1, - page_size: 5 - } - }); - } - - async dipLucky(lottery_history_id) { - return this.post("/growth_api/v1/lottery_lucky/dip_lucky", { - data: { - lottery_history_id - } - }); - } - - async getMyLucky() { - return this.post("/growth_api/v1/lottery_lucky/my_lucky"); - } -} - -module.exports = new JuejinApi; diff --git a/scripts/api/juejin-game-api.js b/scripts/api/juejin-game-api.js deleted file mode 100644 index 7c2d5389..00000000 --- a/scripts/api/juejin-game-api.js +++ /dev/null @@ -1,105 +0,0 @@ -const Api = require("./api"); -const jwt = require("jsonwebtoken"); - -class JuejinGameApi extends Api { - user = null; - - constructor() { - super(); - this.baseURL = "https://juejin-game.bytedance.com/game"; - this.headers.referer = "https://juejin.cn/"; - } - - setUser(user) { - this.user = user; - } - - setToken(token) { - this.headers.Authorization = `Bearer ${token}`; - } - - requestInterceptor = config => { - if (this.user) { - config.url += (config.url.indexOf("?") === -1 ? "?" : "&") + `uid=${this.user.user_id}&time=${Date.now()}`; - } - return config; - }; - - responseInterceptor = res => { - if (res.code !== 0) { - throw new Error(res.message); - } - return res.data; - } - - async gameLogin() { - return this.post("/sea-gold/user/login", { - data: { - name: this.user.user_name - } - }); - } - - async gameInfo() { - return this.get("/sea-gold/home/info"); - } - - async gameStart() { - return this.post("/sea-gold/game/start", { - data: { - roleId: 3 - } - }); - } - - async gameOver() { - // const result = { - // activity: "", - // deep: 3, - // gameDiamond: 34, // 当局获取 - // originMapData: [], - // passLine: [{ x: 0, y: 0 }, { x: 0, y: 1 }], - // picoDiamond: 0, - // realDiamond: 34, // 真实获取 - // todayDiamond: 34, // 今日获取 - // todayLimitDiamond: 1500 // 今日最大获取 - // }; - return this.post("/sea-gold/game/over", { - data: { - isButton: 1 - } - }); - } - - async gameCommand(gameId, command = []) { - // const result = { - // appendMapData: [], - // blockData: { moveUp: 14, moveDown: 14, moveLeft: 2, moveRight: 5, jump: 3, loop: 3 }, - // curPos: { x: 0, y: 2 }, - // gameDiamond: 34 - // } - const privateKey = "-----BEGIN EC PARAMETERS-----\nBggqhkjOPQMBBw==\n-----END EC PARAMETERS-----\n-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIDB7KMVQd+eeKt7AwDMMUaT7DE3Sl0Mto3LEojnEkRiAoAoGCCqGSM49\nAwEHoUQDQgAEEkViJDU8lYJUenS6IxPlvFJtUCDNF0c/F/cX07KCweC4Q/nOKsoU\nnYJsb4O8lMqNXaI1j16OmXk9CkcQQXbzfg==\n-----END EC PRIVATE KEY-----\n"; - const token = jwt.sign({ - gameId: gameId, - time: new Date().getTime() - }, privateKey, { - algorithm: "ES256", - expiresIn: 2592e3, - header: { - alg: "ES256", - typ: "JWT" - } - }); - return this.post("/sea-gold/game/command", { - headers: { - "x-tt-gameid": token - }, - data: { - command - // command: ["R", { times: 2, command: ["R"] }, "2"] - } - }); - } -} - -module.exports = new JuejinGameApi; diff --git a/scripts/checkin.js b/scripts/checkin.js index 32065fad..acaa927f 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -1,7 +1,8 @@ -const api = require("./api/juejin-api"); +const JuejinHelper = require("juejin-helper"); const console = require("./utils/logger"); const utils = require("./utils/utils"); const email = require("./utils/email"); +const env = require("./utils/env"); async function run(args) { const state = { @@ -19,6 +20,10 @@ async function run(args) { await utils.wait(100); console.clear(); + const juejin = new JuejinHelper(); + await juejin.login(env.COOKIE); + const api = juejin.growth(); + try { const checkInResult = await api.checkIn(); const incrPoint = checkInResult.incr_point; @@ -107,6 +112,8 @@ async function run(args) { await utils.wait(state.simulateSpeed); } + await juejin.logout(); + console.logGroupEnd("奖品实况"); console.log(`当前余额:${state.sumPoint} 矿石`); diff --git a/scripts/seaGold.js b/scripts/seaGold.js index 845522eb..0c863124 100644 --- a/scripts/seaGold.js +++ b/scripts/seaGold.js @@ -1,24 +1,26 @@ -const api = require("./api/juejin-api"); -const juejinGameApi = require("./api/juejin-game-api"); +const JuejinHelper = require("juejin-helper"); const utils = require("./utils/utils"); const { Grid, Astar } = require("fast-astar"); const console = require("./utils/logger"); const email = require("./utils/email"); +const env = require("./utils/env"); async function run(args) { console.clear(); class SeaGold { static async init() { - const user = await api.getUserInfo(); - const token = await api.getToken(); - juejinGameApi.setUser(user); - juejinGameApi.setToken(token); + const juejin = new JuejinHelper(); + await juejin.login(env.COOKIE); const seaGold = new this(); + const gameApi = juejin.seagold(); + seaGold.gameApi = gameApi; await seaGold.init(); return seaGold; } + gameApi = null; + nodeRules = [ { code: 0, hasBounty: false, isWall: false, name: "空地" }, { code: 2, hasBounty: true, isWall: false, name: "矿石", isBest: true }, @@ -63,12 +65,12 @@ async function run(args) { } async init() { - const loginInfo = await juejinGameApi.gameLogin(); + const loginInfo = await this.gameApi.gameLogin(); if (!loginInfo.isAuth) { throw Error("玩家未授权, 请前往掘金授权!"); } console.log(`玩家: ${loginInfo.name}`); - const info = await juejinGameApi.gameInfo(); + const info = await this.gameApi.gameInfo(); this.userInfo = { uid: info.userInfo.uid, name: info.userInfo.name, @@ -112,7 +114,7 @@ async function run(args) { async gameStart() { if (this.isGaming) return; - const gameInfo = await juejinGameApi.gameStart(); + const gameInfo = await this.gameApi.gameStart(); this.gameInfo = { gameId: gameInfo.gameId, @@ -129,7 +131,7 @@ async function run(args) { async gameOver() { if (!this.isGaming) return; - const gameOverInfo = await juejinGameApi.gameOver(); + const gameOverInfo = await this.gameApi.gameOver(); this.userInfo.todayDiamond = gameOverInfo.todayDiamond; this.userInfo.todayLimitDiamond = gameOverInfo.todayLimitDiamond; // console.log("|==================|"); @@ -150,7 +152,7 @@ async function run(args) { console.log("当局游戏资源耗尽"); return false; } - const gameCommandInfo = await juejinGameApi.gameCommand(this.gameInfo.gameId, commands); + const gameCommandInfo = await this.gameApi.gameCommand(this.gameInfo.gameId, commands); this.gameInfo.curPos = gameCommandInfo.curPos; this.gameInfo.blockData = gameCommandInfo.blockData; this.gameInfo.gameDiamond = gameCommandInfo.gameDiamond; diff --git a/yarn.lock b/yarn.lock index 6e3974e8..b8cc563d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4,24 +4,24 @@ buffer-equal-constant-time@1.0.1: version "1.0.1" - resolved "https://registry.npm.taobao.org/buffer-equal-constant-time/download/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819" + resolved "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819" integrity sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk= ecdsa-sig-formatter@1.0.11: version "1.0.11" - resolved "https://registry.nlark.com/ecdsa-sig-formatter/download/ecdsa-sig-formatter-1.0.11.tgz#ae0f0fa2d85045ef14a817daa3ce9acd0489e5bf" - integrity sha1-rg8PothQRe8UqBfao86azQSJ5b8= + resolved "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz#ae0f0fa2d85045ef14a817daa3ce9acd0489e5bf" + integrity sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ== dependencies: safe-buffer "^5.0.1" fast-astar@^1.0.6: version "1.0.6" - resolved "https://registry.npmmirror.com/fast-astar/download/fast-astar-1.0.6.tgz#e4cae258839bc6406c49df1eaa80077eda74723c" - integrity sha1-5MriWIObxkBsSd8eqoAHftp0cjw= + resolved "https://registry.npmjs.org/fast-astar/-/fast-astar-1.0.6.tgz#e4cae258839bc6406c49df1eaa80077eda74723c" + integrity sha512-r23aD+DIl2Y/XdhP/Z3kDyi9dJ4BID6z49gjc+lQo1fLBqi9uEkaevcX4v0bqHGxjwc7GKbt/OPRM/UwTCfiEw== jsonwebtoken@^8.5.1: version "8.5.1" - resolved "https://registry.npmmirror.com/jsonwebtoken/download/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d" + resolved "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d" integrity sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w== dependencies: jws "^3.2.2" @@ -35,10 +35,18 @@ jsonwebtoken@^8.5.1: ms "^2.1.1" semver "^5.6.0" +juejin-helper@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/juejin-helper/-/juejin-helper-0.1.0.tgz#92d42a41d6ce2e9049d69c627022cd2282a2ecfb" + integrity sha512-07+3aWYiTVcaQPyCFTFY6WIWg5wsWn6QvfZ2XuPIPD7337zcDaVVzrrgL4tivJJ4eyHlMBLkLifFZnFu6VpR7g== + dependencies: + jsonwebtoken "^8.5.1" + node-fetch "^2.6.1" + jwa@^1.4.1: version "1.4.1" - resolved "https://registry.npm.taobao.org/jwa/download/jwa-1.4.1.tgz#743c32985cb9e98655530d53641b66c8645b039a" - integrity sha1-dDwymFy56YZVUw1TZBtmyGRbA5o= + resolved "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz#743c32985cb9e98655530d53641b66c8645b039a" + integrity sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA== dependencies: buffer-equal-constant-time "1.0.1" ecdsa-sig-formatter "1.0.11" @@ -46,87 +54,87 @@ jwa@^1.4.1: jws@^3.2.2: version "3.2.2" - resolved "https://registry.nlark.com/jws/download/jws-3.2.2.tgz#001099f3639468c9414000e99995fa52fb478304" - integrity sha1-ABCZ82OUaMlBQADpmZX6UvtHgwQ= + resolved "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz#001099f3639468c9414000e99995fa52fb478304" + integrity sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA== dependencies: jwa "^1.4.1" safe-buffer "^5.0.1" lodash.includes@^4.3.0: version "4.3.0" - resolved "https://registry.npmmirror.com/lodash.includes/download/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f" + resolved "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f" integrity sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8= lodash.isboolean@^3.0.3: version "3.0.3" - resolved "https://registry.npmmirror.com/lodash.isboolean/download/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6" - integrity sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg== + resolved "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6" + integrity sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY= lodash.isinteger@^4.0.4: version "4.0.4" - resolved "https://registry.npm.taobao.org/lodash.isinteger/download/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343" + resolved "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343" integrity sha1-YZwK89A/iwTDH1iChAt3sRzWg0M= lodash.isnumber@^3.0.3: version "3.0.3" - resolved "https://registry.npm.taobao.org/lodash.isnumber/download/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc" + resolved "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc" integrity sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w= lodash.isplainobject@^4.0.6: version "4.0.6" - resolved "https://registry.npm.taobao.org/lodash.isplainobject/download/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" + resolved "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs= lodash.isstring@^4.0.1: version "4.0.1" - resolved "https://registry.npmmirror.com/lodash.isstring/download/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" + resolved "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE= lodash.once@^4.0.0: version "4.1.1" - resolved "https://registry.npm.taobao.org/lodash.once/download/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac" + resolved "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac" integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w= ms@^2.1.1: version "2.1.3" - resolved "https://registry.npmmirror.com/ms/download/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" - integrity sha1-V0yBOM4dK1hh8LRFedut1gxmFbI= + resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== node-fetch@^2.6.1: - version "2.6.6" - resolved "https://registry.npmmirror.com/node-fetch/download/node-fetch-2.6.6.tgz?cache=0&sync_timestamp=1636395469986&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fnode-fetch%2Fdownload%2Fnode-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89" - integrity sha1-F1GnwBg06OFpd1hzLp77burfr4k= + version "2.6.7" + resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" + integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== dependencies: whatwg-url "^5.0.0" nodemailer@^6.7.0: - version "6.7.0" - resolved "https://registry.npmmirror.com/nodemailer/download/nodemailer-6.7.0.tgz?cache=0&sync_timestamp=1634009331140&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fnodemailer%2Fdownload%2Fnodemailer-6.7.0.tgz#86614722c4e0c33d1b5b02aecb90d6d629932b0d" - integrity sha1-hmFHIsTgwz0bWwKuy5DW1imTKw0= + version "6.7.2" + resolved "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.2.tgz#44b2ad5f7ed71b7067f7a21c4fedabaec62b85e0" + integrity sha512-Dz7zVwlef4k5R71fdmxwR8Q39fiboGbu3xgswkzGwczUfjp873rVxt1O46+Fh0j1ORnAC6L9+heI8uUpO6DT7Q== safe-buffer@^5.0.1: version "5.2.1" - resolved "https://registry.npm.taobao.org/safe-buffer/download/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" - integrity sha1-Hq+fqb2x/dTsdfWPnNtOa3gn7sY= + resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" + integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== semver@^5.6.0: version "5.7.1" - resolved "https://registry.npm.taobao.org/semver/download/semver-5.7.1.tgz?cache=0&sync_timestamp=1616463540350&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" - integrity sha1-qVT5Ma66UI0we78Gnv8MAclhFvc= + resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" + integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== tr46@~0.0.3: version "0.0.3" - resolved "https://registry.npmmirror.com/tr46/download/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" + resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= webidl-conversions@^3.0.0: version "3.0.1" - resolved "https://registry.nlark.com/webidl-conversions/download/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" + resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= whatwg-url@^5.0.0: version "5.0.0" - resolved "https://registry.npmmirror.com/whatwg-url/download/whatwg-url-5.0.0.tgz?cache=0&sync_timestamp=1634673865107&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fwhatwg-url%2Fdownload%2Fwhatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" + resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0= dependencies: tr46 "~0.0.3" From dad60cfd21f72ac5d2b0690b924ba7fa754cf95b Mon Sep 17 00:00:00 2001 From: derek Date: Fri, 4 Feb 2022 20:04:15 +0800 Subject: [PATCH 02/27] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/test.js | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 scripts/test.js diff --git a/scripts/test.js b/scripts/test.js new file mode 100644 index 00000000..45a8049d --- /dev/null +++ b/scripts/test.js @@ -0,0 +1,93 @@ +const JuejinHelper = require('juejin-helper'); +const email = require("./utils/email"); +const env = require("./utils/env"); + +const CheckInState = { + no: -1, + success: 1, + error: 0 +} + +class CheckIn { + state = { + simulateSpeed: 100, // ms/进行一次抽奖 + sumPoint: 0, + pointCost: 0, + supplyPoint: 0, + freeCount: 0, + luckyValue: 0, + lottery: [], + counter: 0, + prize: {}, + checkInState: CheckInState.no + }; + + juejin = new JuejinHelper(); + + static async run() { + email({ + subject: "掘金每日签到", + html: ` +
+ +
签到成功 +700 矿石
+
沾喜气 +10 幸运值
+
矿石 98559
+
+
幸运值
+
+
+
+
1385/6000
+
+
All In矿石预估累计幸运值比: 119.10%
+
+
免费抽奖 1 次
+
我的奖品
+
    +
  • [第1抽]:30矿石
  • +
+
+
` + }); + } +} + +CheckIn.run(); + +// async function run() { +// const checkin = new CheckIn(); +// const juejin = new JuejinHelper(); +// await juejin.login(mockCookie); +// console.log(checkin.hello, juejin.getUser()); +// } +// +// run(); From 1d61b736024d124cae6a4bd13358d3887cc8df2f Mon Sep 17 00:00:00 2001 From: dbl5201314 <2239146847@qq.com> Date: Fri, 11 Feb 2022 18:35:30 +0800 Subject: [PATCH 03/27] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index f6a9b010..303f3661 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,7 @@ DevTools截图: [![海底掘金挑战赛](https://user-images.githubusercontent.com/24502299/151397151-0d69998a-2310-4a32-945f-c8e0035ed65d.png)](https://juejin.cn/game/haidijuejin/) -## 赞赏 -### ☕️微信赞赏!鼓励升级! -微信赞赏 + ## 许可 From 38b9315f9cfc5b1334a2061666a02e0dffcdfd19 Mon Sep 17 00:00:00 2001 From: dbl5201314 <2239146847@qq.com> Date: Fri, 11 Feb 2022 18:36:07 +0800 Subject: [PATCH 04/27] Update README.md --- README.md | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) diff --git a/README.md b/README.md index 303f3661..dc220a80 100644 --- a/README.md +++ b/README.md @@ -1,55 +1,4 @@ -
- - 稀土掘金 - -
-

JuejinHelper-稀土掘金助手

- -

签到、抽奖、沾喜气、海底掘金游戏、自动化工作流。

- -## 使用 - -自动化执行任务: 掘金每日签到, 沾喜气, 免费抽奖, 海底掘金游戏, 最后将结果报告邮件通知订阅人。\ -自动化运行时间: 北京时间上午06:30 - -1. [Fork 仓库](https://github.com/iDerekLi/juejin-helper) - -2. 仓库 -> Settings -> Secrets -> New repository secret, 添加Secrets变量如下: - - | Name | Value | - | --- | --- | - | COOKIE | 掘金网站Cookie, 打开浏览器,登录 [掘金](https://juejin.cn/), 打开控制台DevTools -> Network,复制 cookie, **掘金Cookie有效期约1个月需定期更新.** | - | EMAIL_USER | 发件人邮箱地址(需要开启 SMTP) | - | EMAIL_PASS | 发件人邮箱密码(SMTP密码) | - | EMAIL_TO | 订阅人邮箱地址(收件人). 如需多人订阅使用 `, ` 分割, 例如: `a@163.com, b@qq.com` | - -3. 仓库 -> Actions, 检查Workflows并启用。 - -## 预览 - -| 掘金每日签到 | 海底掘金游戏 | -|:-----------:| :-------------:| -| ![掘金每日签到](https://user-images.githubusercontent.com/24502299/150481822-b488d30c-93b6-4d73-9e28-56c04a9413fb.png) | ![海底掘金游戏](https://user-images.githubusercontent.com/24502299/150625136-5649d2fe-b204-40aa-b8b5-7f54a44e018d.png) | - -## 问题 - -### 如何获取Cookie - -掘金网站Cookie, 打开浏览器,登录 [掘金](https://juejin.cn/), 打开控制台DevTools(快捷键F12) -> Network,复制 cookie, **掘金Cookie有效期约1个月需定期更新.** - -DevTools截图: -getcookie - -### 如何授权海底掘金游戏 - -运行自动化后通知订阅人 `玩家未授权, 请前往掘金授权!`, 说明您是新玩家从始至终未进行海底掘金游戏, 需要先进行游戏授权. - -授权步骤: 登陆 [掘金](https://juejin.cn/) -> 每日签到 -> 海底掘金挑战赛(点击进入游戏, 点击授权, 最好再随意玩一局). 后续就可以由掘金助手自动处理. - -或点击👇这个海报帮您直达海底掘金挑战赛 - -[![海底掘金挑战赛](https://user-images.githubusercontent.com/24502299/151397151-0d69998a-2310-4a32-945f-c8e0035ed65d.png)](https://juejin.cn/game/haidijuejin/) From 88236d7bb7159754926c291e004fb9ddf722d58f Mon Sep 17 00:00:00 2001 From: Derek Date: Tue, 15 Feb 2022 09:43:47 +0800 Subject: [PATCH 05/27] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B2=BE?= =?UTF-8?q?=E5=96=9C=E6=B0=94=E6=9C=AA=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7df6d182..d8c2951c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store node_modules +dist # local env files .env.local diff --git a/package.json b/package.json index a88acbce..b7193f02 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "fast-astar": "^1.0.6", - "juejin-helper": "^0.1.0", + "juejin-helper": "^0.1.2", "nodemailer": "^6.7.0" }, "repository": { From da74a0b48bd08a02f08581ca7badb0302eb8f5e0 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 2 Mar 2022 15:01:52 +0800 Subject: [PATCH 06/27] =?UTF-8?q?fix(email):=20=E4=BF=AE=E5=A4=8D=E6=9C=AA?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=82=AE=E7=AE=B1=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/utils/email.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/utils/email.js b/scripts/utils/email.js index b24ed3d1..2330fe5e 100644 --- a/scripts/utils/email.js +++ b/scripts/utils/email.js @@ -9,10 +9,20 @@ async function main({ subject, text, html }) { pass: env.EMAIL_PASS, // generated ethereal password }; + if (!auth.user || !auth.pass) { + console.warn("邮箱功能不可用, 请先配置邮箱用户和密码"); + return; + } + const transporter = nodemailer.createTransport({ host: "smtp." + auth.user.match(/@(.*)/)[1], secure: true, - auth + port: 465, + auth, + tls: { + // do not fail on invalid certs + rejectUnauthorized: false + } }); const template = ` From cfe4abc58c2d419d98d70cb3b77954c254d06ef9 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 2 Mar 2022 15:03:08 +0800 Subject: [PATCH 07/27] =?UTF-8?q?refactor(checkin):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更友好的错误捕获 --- scripts/checkin.js | 239 +++++++++++++++++++++++---------------------- 1 file changed, 120 insertions(+), 119 deletions(-) diff --git a/scripts/checkin.js b/scripts/checkin.js index acaa927f..7e2d28db 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -1,150 +1,151 @@ const JuejinHelper = require("juejin-helper"); -const console = require("./utils/logger"); const utils = require("./utils/utils"); const email = require("./utils/email"); const env = require("./utils/env"); -async function run(args) { - const state = { - simulateSpeed: 100, // ms/进行一次抽奖 - sumPoint: 0, - pointCost: 0, - supplyPoint: 0, - freeCount: 0, - luckyValue: 0, - lottery: [], - counter: 0, - prize: {} - }; - - await utils.wait(100); - console.clear(); - - const juejin = new JuejinHelper(); - await juejin.login(env.COOKIE); - const api = juejin.growth(); - - try { - const checkInResult = await api.checkIn(); - const incrPoint = checkInResult.incr_point; - console.log(`签到成功 +${incrPoint} 矿石`); - - const sumPoint = checkInResult.sum_point; - state.sumPoint = sumPoint; - } catch (e) { - console.log(e.message); - - const sumPoint = await api.getCurrentPoint(); - state.sumPoint = sumPoint; - } +class CheckIn { + username = ""; + todayStatus = 0; // 未签到 + incrPoint = 0; + sumPoint = 0; // 当前矿石数 + contCount = 0; // 连续签到天数 + sumCount = 0; // 累计签到天数 + dipStatus = 0; + dipValue = 0; // 沾喜气 + luckyValue = 0; + lottery = []; // 奖池 + pointCost = 0; // 一次抽奖消耗 + freeCount = 0; // 免费抽奖次数 + drawLotteryHistory = {}; + lotteryCount = 0; + luckyValueProbability = 0; + + async run() { + const juejin = new JuejinHelper(); + try { + await juejin.login(env.COOKIE); + } catch (e) { + console.error(e); + throw new Error("登录失败, 请尝试更新Cookies!"); + } + + this.username = juejin.getUser().user_name; + + const growth = juejin.growth(); + + const todayStatus = await growth.getTodayStatus(); + if (!todayStatus) { + const checkInResult = await growth.checkIn(); - try { - const luckyusersResult = await api.getLotteriesLuckyUsers(); + this.incrPoint = checkInResult.incr_point; + this.sumPoint = checkInResult.sum_point; + this.todayStatus = 1; // 本次签到 + } else { + this.todayStatus = 2; // 已签到 + } + + const counts = await growth.getCounts(); + this.contCount = counts.cont_count; + this.sumCount = counts.sum_count; + + const luckyusersResult = await growth.getLotteriesLuckyUsers(); if (luckyusersResult.count > 0) { const no1LuckyUser = luckyusersResult.lotteries[0]; - const dipLuckyResult = await api.dipLucky(no1LuckyUser.history_id); + const dipLuckyResult = await growth.dipLucky(no1LuckyUser.history_id); if (dipLuckyResult.has_dip) { - console.log(`今天你已经沾过喜气,明天再来吧!`); + this.dipStatus = 2; } else { - console.log(`沾喜气 +${dipLuckyResult.dip_value} 幸运值`); + this.dipStatus = 1; + this.dipValue = dipLuckyResult.dip_value; } } - } catch {} - - console.log(`当前余额:${state.sumPoint} 矿石`); - - const luckyResult = await api.getMyLucky(); - state.luckyValue = luckyResult.total_value; - console.log(`当前幸运值:${state.luckyValue}/6000`); - - const lotteryConfig = await api.getLotteryConfig(); - state.lottery = lotteryConfig.lottery; - state.pointCost = lotteryConfig.point_cost; - state.freeCount = lotteryConfig.free_count; - state.sumPoint += state.freeCount * state.pointCost; - - const getProbabilityOfWinning = sumPoint => { - const pointCost = state.pointCost; - const luckyValueCost = 10; - const totalDrawsNumber = sumPoint / pointCost; - let supplyPoint = 0; - for(let i = 0, length = Math.floor(totalDrawsNumber * 0.65); i < length; i++) { - supplyPoint += Math.ceil(Math.random() * 100) + + const luckyResult = await growth.getMyLucky(); + this.luckyValue = luckyResult.total_value; + + const lotteryConfig = await growth.getLotteryConfig(); + this.lottery = lotteryConfig.lottery; + this.pointCost = lotteryConfig.point_cost; + this.freeCount = lotteryConfig.free_count; + this.lotteryCount = 0; + + let freeCount = this.freeCount; + while (freeCount > 0) { + const result = await growth.drawLottery(); + this.drawLotteryHistory[result.lottery_id] = (this.drawLotteryHistory[result.lottery_id] || 0) + 1; + this.luckyValue = result.total_lucky_value + freeCount--; + this.lotteryCount++; + await utils.wait(utils.randomRangeNumber(300, 1000)); } - const luckyValue = (sumPoint + supplyPoint) / pointCost * luckyValueCost + state.luckyValue; - return luckyValue / 6000; - } - console.log(`预测梭哈矿石累计幸运值比率: ${(getProbabilityOfWinning(state.sumPoint) * 100).toFixed(2) + "%"}`); - - console.log(`免费抽奖次数: ${state.freeCount}`); - console.log(`准备免费抽奖!`); - - console.logGroupStart("奖品实况"); - - const getSupplyPoint = draw => { - const maybe = [ - ["lottery_id", "6981716980386496552"], - ["lottery_name", "随机矿石"], - ["lottery_type", 1] - ]; - if (maybe.findIndex(([prop, value]) => draw[prop] === value) !== -1) { - const supplyPoint = Number.parseInt(draw.lottery_name); - if (!isNaN(supplyPoint)) { - return supplyPoint; + + this.sumPoint = await growth.getCurrentPoint(); + + const getProbabilityOfWinning = sumPoint => { + const pointCost = this.pointCost; + const luckyValueCost = 10; + const totalDrawsNumber = sumPoint / pointCost; + let supplyPoint = 0; + for(let i = 0, length = Math.floor(totalDrawsNumber * 0.65); i < length; i++) { + supplyPoint += Math.ceil(Math.random() * 100) } + const luckyValue = (sumPoint + supplyPoint) / pointCost * luckyValueCost + this.luckyValue; + return luckyValue / 6000; } - return 0; - }; - - const lottery = async () => { - const result = await api.drawLottery(); - state.sumPoint -= state.pointCost; - state.sumPoint += getSupplyPoint(result); - state.luckyValue += result.draw_lucky_value; - state.counter++; - state.prize[result.lottery_name] = (state.prize[result.lottery_name] || 0) + 1; - console.log(`[第${state.counter}抽]:${result.lottery_name}`); - }; - - while (state.freeCount > 0) { - await lottery(); - state.freeCount--; - await utils.wait(state.simulateSpeed); - } - await juejin.logout(); + this.luckyValueProbability = getProbabilityOfWinning(this.sumPoint); - console.logGroupEnd("奖品实况"); + console.log(`预测梭哈矿石累计幸运值比率: ${(this.luckyValueProbability * 100).toFixed(2) + "%"}`); - console.log(`当前余额:${state.sumPoint} 矿石`); + await juejin.logout(); + } - const recordInfo = []; - recordInfo.push("=====[战绩详情]====="); - if (state.counter > 0) { - const prizeList = []; - for (const key in state.prize) { - prizeList.push(`${key}: ${state.prize[key]}`); - } - recordInfo.push(...prizeList); - recordInfo.push("-------------------"); - recordInfo.push(`共计: ${state.counter}`); - } else { - recordInfo.push("暂无奖品"); + toString() { + const drawLotteryHistory = Object.entries(this.drawLotteryHistory).map(([lottery_id, count]) => { + const lotteryItem = this.lottery.find(item => item.lottery_id === lottery_id); + if (lotteryItem) { + return `${lotteryItem.lottery_name}: ${count}`; + } + return `${lottery_id}: ${count}` + }).join("\n"); + + return ` +用户: ${this.username} +${this.todayStatus === 1 ? `签到成功 +${this.incrPoint} 矿石` : + this.todayStatus === 2 ? "今日已完成签到" : "签到失败"} +${this.dipStatus === 1 ? `沾喜气 +${this.dipValue} 幸运值` : + this.dipStatus === 2 ? "今日已经沾过喜气" : "沾喜气失败"} +连续签到天数 ${this.contCount} +累计签到天数 ${this.sumCount} +当前矿石数 ${this.sumPoint} +当前幸运值 ${this.luckyValue}/6000 +预测All In矿石累计幸运值比率 ${(this.luckyValueProbability * 100).toFixed(2) + "%"} +抽奖总次数 ${this.lotteryCount} +免费抽奖次数 ${this.freeCount} +${this.lotteryCount > 0 ? "============\n" + drawLotteryHistory + "\n============" : ""} + `.trim(); } - recordInfo.push("+++++++++++++++++++"); - recordInfo.push(`幸运值: ${state.luckyValue}/6000`); - recordInfo.push("==================="); - console.log(recordInfo.join("\n ")); +} + +async function run(args) { + const checkin = new CheckIn(); + await utils.wait(utils.randomRangeNumber(1000, 5000)); // 初始等待1-5s + await checkin.run(); // 执行 + const content = checkin.toString(); + + console.log(content); // 打印结果 email({ subject: "掘金每日签到", - text: console.toString() + text: content }); } run(process.argv.splice(2)).catch(error => { + console.error(error); + email({ subject: "掘金每日签到", - html: `Error
${error.message}
` + html: `Error
${error.message}
` }); }); From 38ca7ba19a72b56b1fafed50c26f4383f6f5d554 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 2 Mar 2022 15:05:11 +0800 Subject: [PATCH 08/27] =?UTF-8?q?chore(checkin):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=E6=89=A7=E8=A1=8C=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/checkin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkin.yml b/.github/workflows/checkin.yml index 898686d6..8a791660 100644 --- a/.github/workflows/checkin.yml +++ b/.github/workflows/checkin.yml @@ -2,7 +2,7 @@ name: CheckIn on: schedule: - - cron: "30 22 * * *" # 北京时间上午06:30 + - cron: "40 22 * * *" # 北京时间上午06:40 workflow_dispatch: jobs: CheckIn: From ff5ef6cb26e8dd671512c607619469b7efe85357 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 2 Mar 2022 15:08:20 +0800 Subject: [PATCH 09/27] =?UTF-8?q?chore(checkin):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E6=89=93=E5=8D=B0=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/checkin.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/checkin.js b/scripts/checkin.js index 7e2d28db..0d41ef28 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -95,8 +95,6 @@ class CheckIn { this.luckyValueProbability = getProbabilityOfWinning(this.sumPoint); - console.log(`预测梭哈矿石累计幸运值比率: ${(this.luckyValueProbability * 100).toFixed(2) + "%"}`); - await juejin.logout(); } From 655cea77ab519c12bd15a7d758d0f0c6b5f7bc09 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 2 Mar 2022 15:13:06 +0800 Subject: [PATCH 10/27] =?UTF-8?q?chore(checkin):=20=E6=9A=B4=E9=9C=B2?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/checkin.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/checkin.js b/scripts/checkin.js index 0d41ef28..7be887db 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -146,4 +146,6 @@ run(process.argv.splice(2)).catch(error => { subject: "掘金每日签到", html: `Error
${error.message}
` }); + + throw error; }); From 6b6df19b90571576bab17ed0c4a8ef0567338c4b Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 2 Mar 2022 18:47:12 +0800 Subject: [PATCH 11/27] =?UTF-8?q?chore(checkin):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/checkin.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/checkin.js b/scripts/checkin.js index 7be887db..24345aaf 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -140,11 +140,9 @@ async function run(args) { } run(process.argv.splice(2)).catch(error => { - console.error(error); - email({ subject: "掘金每日签到", - html: `Error
${error.message}
` + html: `Error
${error.message}
` }); throw error; From 2f326a4732ca378ee8eaf6588423491910569472 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 2 Mar 2022 18:49:03 +0800 Subject: [PATCH 12/27] =?UTF-8?q?refactor(seaGold):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=B5=B7=E5=BA=95=E6=8E=98=E9=87=91=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/seaGold.js | 634 +++++++++++++++++++++++---------------------- 1 file changed, 325 insertions(+), 309 deletions(-) diff --git a/scripts/seaGold.js b/scripts/seaGold.js index 0c863124..34c5c48c 100644 --- a/scripts/seaGold.js +++ b/scripts/seaGold.js @@ -1,51 +1,59 @@ const JuejinHelper = require("juejin-helper"); const utils = require("./utils/utils"); const { Grid, Astar } = require("fast-astar"); -const console = require("./utils/logger"); const email = require("./utils/email"); const env = require("./utils/env"); -async function run(args) { - console.clear(); - - class SeaGold { - static async init() { - const juejin = new JuejinHelper(); - await juejin.login(env.COOKIE); - const seaGold = new this(); - const gameApi = juejin.seagold(); - seaGold.gameApi = gameApi; - await seaGold.init(); - return seaGold; - } - - gameApi = null; - - nodeRules = [ - { code: 0, hasBounty: false, isWall: false, name: "空地" }, - { code: 2, hasBounty: true, isWall: false, name: "矿石", isBest: true }, - { code: 3, hasBounty: false, isWall: false, name: "星星" }, - { code: 4, hasBounty: false, isWall: true, name: "贝壳" }, - { code: 5, hasBounty: false, isWall: true, name: "水母" }, - { code: 6, hasBounty: false, isWall: true, name: "石头" }, - { code: 10, hasBounty: true, isWall: false, name: "上指令" }, - { code: 11, hasBounty: true, isWall: false, name: "下指令" }, - { code: 12, hasBounty: true, isWall: false, name: "左指令" }, - { code: 13, hasBounty: true, isWall: false, name: "右指令" }, - { code: 14, hasBounty: true, isWall: false, name: "跳跃指令" }, - { code: 15, hasBounty: true, isWall: false, name: "循环指令" } - ]; - - debug = false; - userInfo = { - uid: "", - name: "", - todayDiamond: 0, // 今日获取矿石数 - todayLimitDiamond: 1500, // 今日限制获取矿石数 - maxTodayDiamond: 0 // 今日最大矿石数 - }; +class SeaGold { + gameApi = null; + + nodeRules = [ + { code: 0, hasBounty: false, isWall: false, name: "空地" }, + { code: 2, hasBounty: true, isWall: false, name: "矿石", isBest: true }, + { code: 3, hasBounty: false, isWall: false, name: "星星" }, + { code: 4, hasBounty: false, isWall: true, name: "贝壳" }, + { code: 5, hasBounty: false, isWall: true, name: "水母" }, + { code: 6, hasBounty: false, isWall: true, name: "石头" }, + { code: 10, hasBounty: true, isWall: false, name: "上指令" }, + { code: 11, hasBounty: true, isWall: false, name: "下指令" }, + { code: 12, hasBounty: true, isWall: false, name: "左指令" }, + { code: 13, hasBounty: true, isWall: false, name: "右指令" }, + { code: 14, hasBounty: true, isWall: false, name: "跳跃指令" }, + { code: 15, hasBounty: true, isWall: false, name: "循环指令" } + ]; + + debug = false; + userInfo = { + uid: "", + name: "", + todayDiamond: 0, // 今日获取矿石数 + todayLimitDiamond: 1500, // 今日限制获取矿石数 + maxTodayDiamond: 0 // 今日最大矿石数 + }; + + gameInfo = { + gameId: "", + mapData: [], + curPos: { x: 0, y: 0 }, + blockData: { + moveUp: 0, + moveDown: 0, + moveLeft: 0, + moveRight: 0, + jump: 0, + loop: 0 + }, + gameDiamond: 0 + }; + + history = []; + + get isGaming() { + return this.gameInfo && this.gameInfo.gameId !== ""; + } - gameInfo = { + resetGame() { + this.gameInfo = { gameId: "", mapData: [], curPos: { x: 0, y: 0 }, @@ -59,344 +67,352 @@ async function run(args) { }, gameDiamond: 0 }; + } - get isGaming() { - return this.gameInfo && this.gameInfo.gameId !== ""; + restoreGame(gameInfo) { + this.gameInfo = { + gameId: gameInfo.gameId, + mapData: this.makeMap(gameInfo.mapData, 6), + curPos: gameInfo.curPos, + blockData: gameInfo.blockData, + gameDiamond: gameInfo.gameDiamond } + } - async init() { - const loginInfo = await this.gameApi.gameLogin(); - if (!loginInfo.isAuth) { - throw Error("玩家未授权, 请前往掘金授权!"); - } - console.log(`玩家: ${loginInfo.name}`); - const info = await this.gameApi.gameInfo(); - this.userInfo = { - uid: info.userInfo.uid, - name: info.userInfo.name, - todayDiamond: info.userInfo.todayDiamond, - todayLimitDiamond: info.userInfo.todayLimitDiamond, - maxTodayDiamond: info.userInfo.maxTodayDiamond - }; - if (info.gameStatus === 1) { - this.restoreGame(info.gameInfo); - } else { - this.resetGame(); - } - } + async gameStart() { + if (this.isGaming) return; + const roleId = Math.ceil(Math.random() * 3); + const gameInfo = await this.gameApi.gameStart({ roleId }); + + this.gameInfo = { + roleId, + gameId: gameInfo.gameId, + mapData: this.makeMap(gameInfo.mapData, 6), + curPos: gameInfo.curPos, + blockData: gameInfo.blockData, + gameDiamond: 0 + }; + } - resetGame() { - this.gameInfo = { - gameId: "", - mapData: [], - curPos: { x: 0, y: 0 }, - blockData: { - moveUp: 0, - moveDown: 0, - moveLeft: 0, - moveRight: 0, - jump: 0, - loop: 0 - }, - gameDiamond: 0 - }; - } + async gameOver() { + if (!this.isGaming) return; + const gameOverInfo = await this.gameApi.gameOver(); + this.userInfo.todayDiamond = gameOverInfo.todayDiamond; + this.userInfo.todayLimitDiamond = gameOverInfo.todayLimitDiamond; - restoreGame(gameInfo) { - this.gameInfo = { - gameId: gameInfo.gameId, - mapData: this.makeMap(gameInfo.mapData, 6), - curPos: gameInfo.curPos, - blockData: gameInfo.blockData, - gameDiamond: gameInfo.gameDiamond - } - } + this.history.push({ + gameId: this.gameInfo.gameId, + gameDiamond: gameOverInfo.gameDiamond, + realDiamond: gameOverInfo.realDiamond, + todayDiamond: gameOverInfo.todayDiamond, + todayLimitDiamond: gameOverInfo.todayLimitDiamond + }); - async gameStart() { - if (this.isGaming) return; - const gameInfo = await this.gameApi.gameStart(); - - this.gameInfo = { - gameId: gameInfo.gameId, - mapData: this.makeMap(gameInfo.mapData, 6), - curPos: gameInfo.curPos, - blockData: gameInfo.blockData, - gameDiamond: 0 - }; - - console.log("╔══════游戏开始══════╗"); - console.log(`gameId: ${this.gameInfo.gameId}`); - console.log(`curPos(${this.gameInfo.curPos.x},${this.gameInfo.curPos.y}): ${this.gameInfo.gameDiamond} 矿石`); - } + this.resetGame(); - async gameOver() { - if (!this.isGaming) return; - const gameOverInfo = await this.gameApi.gameOver(); - this.userInfo.todayDiamond = gameOverInfo.todayDiamond; - this.userInfo.todayLimitDiamond = gameOverInfo.todayLimitDiamond; - // console.log("|==================|"); - const gameDiamond = this.gameInfo.gameDiamond; - console.log(`游戏清算: ${gameDiamond} 矿石`); - console.log("╚══════游戏结束══════╝"); - this.resetGame(); - return gameDiamond; - } + return gameOverInfo; + } - async executeGameCommand() { - const bmmap = this.getBMMap(); - const curNode = this.getNode(this.gameInfo.curPos); - const bestNode = this.getBestNode(bmmap); - const path = this.getRoutePath(bmmap, curNode, bestNode); - const commands = this.getCommands(path); - if (commands.length <= 0) { - console.log("当局游戏资源耗尽"); - return false; - } - const gameCommandInfo = await this.gameApi.gameCommand(this.gameInfo.gameId, commands); - this.gameInfo.curPos = gameCommandInfo.curPos; - this.gameInfo.blockData = gameCommandInfo.blockData; - this.gameInfo.gameDiamond = gameCommandInfo.gameDiamond; - console.log(`curPos(${this.gameInfo.curPos.x},${this.gameInfo.curPos.y}): ${this.gameInfo.gameDiamond} 矿石`); - return true; + async executeGameCommand() { + const bmmap = this.getBMMap(); + const curNode = this.getNode(this.gameInfo.curPos); + const bestNode = this.getBestNode(bmmap); + const path = this.getRoutePath(bmmap, curNode, bestNode); + const commands = this.getCommands(path); + if (commands.length <= 0) { + return false; } + const gameCommandInfo = await this.gameApi.gameCommand(this.gameInfo.gameId, commands); + this.gameInfo.curPos = gameCommandInfo.curPos; + this.gameInfo.blockData = gameCommandInfo.blockData; + this.gameInfo.gameDiamond = gameCommandInfo.gameDiamond; - getCommand(start, end) { - const [sx, sy] = start; - const [ex, ey] = end; + return true; + } - if (sx === ex && sy !== ey) { - return sy > ey ? "U" : "D"; - } + getCommand(start, end) { + const [sx, sy] = start; + const [ex, ey] = end; - if (sy === ey && sx !== ex) { - return sx > ex ? "L" : "R"; - } + if (sx === ex && sy !== ey) { + return sy > ey ? "U" : "D"; + } - return null; + if (sy === ey && sx !== ex) { + return sx > ex ? "L" : "R"; } - getCommands(path) { - const commands = []; - for(let i=0; i${i+1}`); - } - commands.push(cmd); + return null; + } + + getCommands(path) { + const commands = []; + for(let i=0; i${i+1}`); } - return commands; + commands.push(cmd); } + return commands; + } - getNodePosition(map, node) { - for (let y = 0; y < map.length; y++) { - const list = map[y]; - for (let x = 0; x < list.length; x++) { - const cNode = list[x]; - if (cNode === node) { - return { x, y }; - } + getNodePosition(map, node) { + for (let y = 0; y < map.length; y++) { + const list = map[y]; + for (let x = 0; x < list.length; x++) { + const cNode = list[x]; + if (cNode === node) { + return { x, y }; } } - return { x: 0, y: 0 }; } + return { x: 0, y: 0 }; + } - getRoutePath(map, startNode, endNode) { - const maze = this.generateMapMaze(map); - const startPos = this.getNodePosition(map, startNode); - const endPos = this.getNodePosition(map, endNode); + getRoutePath(map, startNode, endNode) { + const maze = this.generateMapMaze(map); + const startPos = this.getNodePosition(map, startNode); + const endPos = this.getNodePosition(map, endNode); - if (this.debug) { - console.log("地图", this.getMaze(map)); - console.log("开始位置", startPos); - console.log("结束位置", endPos); - } + if (this.debug) { + console.log("地图", this.getMaze(map)); + console.log("开始位置", startPos); + console.log("结束位置", endPos); + } - const astar = new Astar(maze); - const path = astar.search( - [startPos.x, startPos.y], - [endPos.x, endPos.y], - { - rightAngle: true, - optimalResult: true - } - ); + const astar = new Astar(maze); + const path = astar.search( + [startPos.x, startPos.y], + [endPos.x, endPos.y], + { + rightAngle: true, + optimalResult: true + } + ); - return path; - } + return path; + } - makeMap(mapData, grid = 6) { - const map = []; - for (let i = 0, y = 0; i < mapData.length; i+=grid, y++) { - const row = []; - map.push(row); - for (let x = 0; x < grid; x++) { - const cell = mapData[i + x]; - row.push(this.createMapNode(x, y, cell)); - } + makeMap(mapData, grid = 6) { + const map = []; + for (let i = 0, y = 0; i < mapData.length; i+=grid, y++) { + const row = []; + map.push(row); + for (let x = 0; x < grid; x++) { + const cell = mapData[i + x]; + row.push(this.createMapNode(x, y, cell)); } - return map; } + return map; + } - createMapNode(x, y, secret) { - const rule = this.getNodeRule(secret); - return { - code: rule.code, - bounty: rule.hasBounty ? this.getBounty(secret, rule.code) : 0, - x, - y, - isWall: rule.isWall, - isBest: !!rule.isBest - } + createMapNode(x, y, secret) { + const rule = this.getNodeRule(secret); + return { + code: rule.code, + bounty: rule.hasBounty ? this.getBounty(secret, rule.code) : 0, + x, + y, + isWall: rule.isWall, + isBest: !!rule.isBest } + } - // 获取范围地图 - getBMMap() { - const { mapData, blockData, curPos } = this.gameInfo; - const minX = Math.max(curPos.x - blockData.moveLeft, 0); - const maxX = Math.min(curPos.x + blockData.moveRight, mapData[0].length - 1); - const minY = Math.max(curPos.y - blockData.moveUp, 0); - const maxY = Math.min(curPos.y + blockData.moveDown, mapData.length - 1); - - const map = []; - for (let y = minY; y <= maxY; y++) { - const row = []; map.push(row); - for (let x = minX; x <= maxX; x++) { - row.push(mapData[y][x]); - } + // 获取范围地图 + getBMMap() { + const { mapData, blockData, curPos } = this.gameInfo; + const minX = Math.max(curPos.x - blockData.moveLeft, 0); + const maxX = Math.min(curPos.x + blockData.moveRight, mapData[0].length - 1); + const minY = Math.max(curPos.y - blockData.moveUp, 0); + const maxY = Math.min(curPos.y + blockData.moveDown, mapData.length - 1); + + const map = []; + for (let y = minY; y <= maxY; y++) { + const row = []; map.push(row); + for (let x = minX; x <= maxX; x++) { + row.push(mapData[y][x]); } - - return map; } - getNode(pos) { - return this.gameInfo.mapData[pos.y][pos.x]; - } + return map; + } - getBestNode(map) { - let bestNode = null; - map.forEach(row => { - row.forEach(node => { - if (node.isBest && bestNode === null) { - bestNode = node; - } else if (node.isBest && node.bounty > bestNode.bounty) { - bestNode = node; - } - }); - }); - return bestNode; - } + getNode(pos) { + return this.gameInfo.mapData[pos.y][pos.x]; + } - getMaze(map) { - return map.map((row, y) => { - return row.map((node, x) => { - if (node.isWall) { - return 1; - } else { - return 0; - } - }); + getBestNode(map) { + let bestNode = null; + map.forEach(row => { + row.forEach(node => { + if (node.isBest && bestNode === null) { + bestNode = node; + } else if (node.isBest && node.bounty > bestNode.bounty) { + bestNode = node; + } }); - } + }); + return bestNode; + } - // 生成迷宫 - generateMapMaze(map) { - const grid = new Grid({ - col: map[0].length, - row: map.length + getMaze(map) { + return map.map((row, y) => { + return row.map((node, x) => { + if (node.isWall) { + return 1; + } else { + return 0; + } }); + }); + } - map.forEach((row, y) => { - row.forEach((node, x) => { - if (node.isWall) { - grid.set([x, y], 'value', 1); - } - }); + // 生成迷宫 + generateMapMaze(map) { + const grid = new Grid({ + col: map[0].length, + row: map.length + }); + + map.forEach((row, y) => { + row.forEach((node, x) => { + if (node.isWall) { + grid.set([x, y], 'value', 1); + } }); + }); - return grid; - } + return grid; + } - getNodeRule(secret) { - return this.nodeRules.find(rule => { - const reg = new RegExp(`^${rule.code}`); - return reg.test(secret); - }); - } + getNodeRule(secret) { + return this.nodeRules.find(rule => { + const reg = new RegExp(`^${rule.code}`); + return reg.test(secret); + }); + } - getBounty(secret, key) { - const reg = new RegExp(`^${key}([0-9]*)`); - const match = secret.toString().match(reg); - if (match) { - const materials = Number.parseInt(match[1]); - return !isNaN(materials) ? materials : 0; - } - return 0; + getBounty(secret, key) { + const reg = new RegExp(`^${key}([0-9]*)`); + const match = secret.toString().match(reg); + if (match) { + const materials = Number.parseInt(match[1]); + return !isNaN(materials) ? materials : 0; } + return 0; } - const seaGold = await SeaGold.init(); + async run() { + const loginInfo = await this.gameApi.gameLogin(); + if (!loginInfo.isAuth) { + throw Error(`掘友 ${loginInfo.name} 未授权, 请前往掘金授权!`); + } + + const info = await this.gameApi.gameInfo(); + this.userInfo = { + uid: info.userInfo.uid, + name: info.userInfo.name, + todayDiamond: info.userInfo.todayDiamond, + todayLimitDiamond: info.userInfo.todayLimitDiamond, + maxTodayDiamond: info.userInfo.maxTodayDiamond + }; - async function runOnceGame() { - try { - if (seaGold.isGaming) { - await seaGold.gameOver(); + const runEndTime = new Date(); + runEndTime.setMinutes(runEndTime.getMinutes() + 30); + let runTime = new Date(); + + const runGame = async () => { + if (this.isGaming) { + return await this.gameOver(); } - await seaGold.gameStart(); - let run = true; - while (run) { + + await this.gameStart(); + + while (await this.executeGameCommand()) { await utils.wait(utils.randomRangeNumber(1000, 1500)); - run = await seaGold.executeGameCommand(); + + if (runTime >= runEndTime) { + throw Error(`掘金游戏异常: 服务运行时间过长.`); + } + + runTime = new Date(); } - return await seaGold.gameOver(); - } catch (e) { - await seaGold.gameOver(); - throw e; + + return await this.gameOver(); } - } - console.log(`今日开采限制: ${seaGold.userInfo.todayLimitDiamond} 矿石`); - if (seaGold.userInfo.todayDiamond >= seaGold.userInfo.todayLimitDiamond) { - console.log(`今日开采已达上限!`); - } else { + const maxZeroCount = 5; let zeroCount = 0; - const runEndTime = new Date(); - runEndTime.setMinutes(runEndTime.getMinutes() + 30); - let runTime = new Date(); - console.log(`准备挖矿!`); - console.log(`当前进度: ${seaGold.userInfo.todayDiamond}/${seaGold.userInfo.todayLimitDiamond} 矿石`); - while (seaGold.userInfo.todayDiamond < seaGold.userInfo.todayLimitDiamond) { + + if (info.gameStatus === 1) { + this.restoreGame(info.gameInfo); + await runGame(); + } else { + this.resetGame(); + } + + while (this.userInfo.todayDiamond < this.userInfo.todayLimitDiamond) { if (runTime >= runEndTime) { - console.log("掘金游戏异常: 服务运行时间过长."); - throw new Error(console.toString()); - } - await utils.wait(utils.randomRangeNumber(1000, 1500)); - const gameDiamond = await runOnceGame(); - if (gameDiamond === 0) { - zeroCount++; + throw Error(`掘金游戏异常: 服务运行时间过长.`); } + if (zeroCount > maxZeroCount) { - console.log("掘金游戏异常: 您 0 矿石游戏对局次数过多."); - throw new Error(console.toString()); + throw new Error("掘金游戏异常: 您 0 矿石游戏对局次数过多."); + } + + await utils.wait(utils.randomRangeNumber(1000, 5000)); + const gameOverInfo = await runGame(); + + if (gameOverInfo.gameDiamond === 0) { + zeroCount++; } - console.log(`当前进度: ${seaGold.userInfo.todayDiamond}/${seaGold.userInfo.todayLimitDiamond} 矿石`); + runTime = new Date(); } + } - if (seaGold.userInfo.todayDiamond >= seaGold.userInfo.todayLimitDiamond) { - console.log(`今日开采已达上限!`); - } + toString() { + const userInfo = this.userInfo; + const gameLives = this.history.map(game => `${game.gameId}\n 挖取 ${game.gameDiamond}\n 获得 ${game.realDiamond}`).join("\n"); + + return ` +掘友: ${userInfo.name} +今日限制矿石数 ${userInfo.todayLimitDiamond} +${userInfo.todayDiamond < userInfo.todayLimitDiamond ? `今日获取矿石数 ${userInfo.todayDiamond}` : "今日获取已达上限"} +${this.history.length ? `\n游戏记录\n${gameLives}` : ""} +`.trim(); } +} + +async function run(args) { + const juejin = new JuejinHelper(); + await juejin.login(env.COOKIE); + + const seaGold = new SeaGold(); + seaGold.gameApi = juejin.seagold(); + + await seaGold.run(); + + const content = seaGold.toString(); + + console.log(content); email({ subject: "海底掘金游戏", - text: console.toString() + text: content }); } run(process.argv.splice(2)).catch(error => { - console.log(error); email({ subject: "海底掘金游戏", - html: `Error
${error.message}
如版本过低请前往升级: juejin-helper
` + html: ` +Error +
${error.message}
+
如果版本过低请前往升级: juejin-helper
+`.trim() }); + + throw error; }); From 44e59df97017d9d92044cd5df1df712e97b50051 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 2 Mar 2022 18:49:36 +0800 Subject: [PATCH 13/27] =?UTF-8?q?chore(checkin):=20=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/checkin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkin.js b/scripts/checkin.js index 24345aaf..4914be88 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -108,7 +108,7 @@ class CheckIn { }).join("\n"); return ` -用户: ${this.username} +掘友: ${this.username} ${this.todayStatus === 1 ? `签到成功 +${this.incrPoint} 矿石` : this.todayStatus === 2 ? "今日已完成签到" : "签到失败"} ${this.dipStatus === 1 ? `沾喜气 +${this.dipValue} 幸运值` : From 5279e7348f8a4ca2874b2eceedbb49739b59e9d7 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 2 Mar 2022 18:54:44 +0800 Subject: [PATCH 14/27] =?UTF-8?q?chore(seaGold):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/seaGold.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/seaGold.js b/scripts/seaGold.js index 34c5c48c..4d581b7a 100644 --- a/scripts/seaGold.js +++ b/scripts/seaGold.js @@ -304,6 +304,10 @@ class SeaGold { } async run() { + const juejin = new JuejinHelper(); + await juejin.login(env.COOKIE); + this.gameApi = juejin.seagold(); + const loginInfo = await this.gameApi.gameLogin(); if (!loginInfo.isAuth) { throw Error(`掘友 ${loginInfo.name} 未授权, 请前往掘金授权!`); @@ -370,6 +374,8 @@ class SeaGold { runTime = new Date(); } + + await juejin.logout(); } toString() { @@ -386,11 +392,9 @@ ${this.history.length ? `\n游戏记录\n${gameLives}` : ""} } async function run(args) { - const juejin = new JuejinHelper(); - await juejin.login(env.COOKIE); - const seaGold = new SeaGold(); - seaGold.gameApi = juejin.seagold(); + + await utils.wait(utils.randomRangeNumber(1000, 5000)); // 初始等待1-5s await seaGold.run(); From 089e2b686029931716095e67c366fe6c24ae3fbb Mon Sep 17 00:00:00 2001 From: Derek Li Date: Thu, 3 Mar 2022 08:58:41 +0800 Subject: [PATCH 15/27] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6a9b010..a2a3f01d 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ | 掘金每日签到 | 海底掘金游戏 | |:-----------:| :-------------:| -| ![掘金每日签到](https://user-images.githubusercontent.com/24502299/150481822-b488d30c-93b6-4d73-9e28-56c04a9413fb.png) | ![海底掘金游戏](https://user-images.githubusercontent.com/24502299/150625136-5649d2fe-b204-40aa-b8b5-7f54a44e018d.png) | +| ![掘金每日签到](https://user-images.githubusercontent.com/24502299/156475511-342cfcd8-3b66-4b9c-8614-215e0b4e08a1.jpg) | ![海底掘金游戏](https://user-images.githubusercontent.com/24502299/156475550-c8cc459a-3b27-4ca6-a07b-902b65bea7a9.jpg) | ## 问题 From 0f51a7f21d84dabb80e400a646db6368d8c7eeb0 Mon Sep 17 00:00:00 2001 From: Derek Li Date: Thu, 3 Mar 2022 09:00:42 +0800 Subject: [PATCH 16/27] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6a9b010..a2a3f01d 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ | 掘金每日签到 | 海底掘金游戏 | |:-----------:| :-------------:| -| ![掘金每日签到](https://user-images.githubusercontent.com/24502299/150481822-b488d30c-93b6-4d73-9e28-56c04a9413fb.png) | ![海底掘金游戏](https://user-images.githubusercontent.com/24502299/150625136-5649d2fe-b204-40aa-b8b5-7f54a44e018d.png) | +| ![掘金每日签到](https://user-images.githubusercontent.com/24502299/156475511-342cfcd8-3b66-4b9c-8614-215e0b4e08a1.jpg) | ![海底掘金游戏](https://user-images.githubusercontent.com/24502299/156475550-c8cc459a-3b27-4ca6-a07b-902b65bea7a9.jpg) | ## 问题 From dd0f4b1af46bb13d64e28aabc2c30f8e054044bf Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 17 Mar 2022 10:47:05 +0800 Subject: [PATCH 17/27] =?UTF-8?q?chore:=20=E5=8D=87=E7=BA=A7=E6=8E=98?= =?UTF-8?q?=E9=87=91=E5=8A=A9=E6=89=8B=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- yarn.lock | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b7193f02..c9b5d913 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "juejin-helper", - "version": "1.0.0", + "version": "1.4.0", "description": "稀土掘金助手:签到、抽奖、沾喜气、海底淘金、自动化工作流。", "author": "Derek Li", "license": "MIT", @@ -11,7 +11,7 @@ }, "dependencies": { "fast-astar": "^1.0.6", - "juejin-helper": "^0.1.2", + "juejin-helper": "^0.1.4", "nodemailer": "^6.7.0" }, "repository": { diff --git a/yarn.lock b/yarn.lock index b8cc563d..08d4bfb1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -35,13 +35,14 @@ jsonwebtoken@^8.5.1: ms "^2.1.1" semver "^5.6.0" -juejin-helper@^0.1.0: - version "0.1.0" - resolved "https://registry.npmjs.org/juejin-helper/-/juejin-helper-0.1.0.tgz#92d42a41d6ce2e9049d69c627022cd2282a2ecfb" - integrity sha512-07+3aWYiTVcaQPyCFTFY6WIWg5wsWn6QvfZ2XuPIPD7337zcDaVVzrrgL4tivJJ4eyHlMBLkLifFZnFu6VpR7g== +juejin-helper@^0.1.4: + version "0.1.4" + resolved "https://registry.npmmirror.com/juejin-helper/-/juejin-helper-0.1.4.tgz#921933b63cd21276dfd928f953a80fe87b454d45" + integrity sha512-14xMEhYgT+RhtmU13IJfMAeZwGwKwSzr+VjO5tCLtxP/MfrpEzSvmEOCKVRwITfJ3e2+NQyU//i+6jFVL9+9/Q== dependencies: jsonwebtoken "^8.5.1" node-fetch "^2.6.1" + uuid "^8.3.2" jwa@^1.4.1: version "1.4.1" @@ -127,6 +128,11 @@ tr46@~0.0.3: resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= +uuid@^8.3.2: + version "8.3.2" + resolved "https://registry.npmmirror.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" From c92c24530b5f0572ff322f0b86aa1c47c0a470b2 Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 17 Mar 2022 11:22:35 +0800 Subject: [PATCH 18/27] =?UTF-8?q?feat:=20=E7=AD=BE=E5=88=B0=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=B7=BB=E5=8A=A0=E4=BA=8B=E4=BB=B6=E5=9F=8B=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/checkin.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/scripts/checkin.js b/scripts/checkin.js index 4914be88..588af57f 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -20,6 +20,10 @@ class CheckIn { lotteryCount = 0; luckyValueProbability = 0; + calledSdkSetting = false; + calledTrackGrowthEvent = false; + calledTrackOnloadEvent = false; + async run() { const juejin = new JuejinHelper(); try { @@ -95,6 +99,44 @@ class CheckIn { this.luckyValueProbability = getProbabilityOfWinning(this.sumPoint); + // 调用埋点 + const sdk = juejin.sdk(); + + try { + await sdk.slardarSDKSetting(); + this.calledSdkSetting = true; + } catch { + this.calledSdkSetting = false; + } + + try { + const result = await sdk.mockTrackGrowthEvent(); + if (result && result.e === 0) { + this.calledTrackGrowthEvent = true; + } else { + throw result; + } + } catch { + this.calledTrackGrowthEvent = false; + } + + try { + const result = await sdk.mockTrackOnloadEvent(); + if (result && result.e === 0) { + this.calledTrackOnloadEvent = true; + } else { + throw result; + } + } catch { + this.calledTrackOnloadEvent = false; + } + + console.log("------事件埋点追踪-------"); + console.log(`SDK状态: ${this.calledSdkSetting ? "加载成功" : "加载失败"}`); + console.log(`成长API事件埋点: ${this.calledTrackGrowthEvent ? "调用成功" : "调用失败"}`); + console.log(`OnLoad事件埋点: ${this.calledTrackOnloadEvent ? "调用成功" : "调用失败"}`); + console.log("-------------------------"); + await juejin.logout(); } @@ -120,7 +162,7 @@ ${this.dipStatus === 1 ? `沾喜气 +${this.dipValue} 幸运值` : 预测All In矿石累计幸运值比率 ${(this.luckyValueProbability * 100).toFixed(2) + "%"} 抽奖总次数 ${this.lotteryCount} 免费抽奖次数 ${this.freeCount} -${this.lotteryCount > 0 ? "============\n" + drawLotteryHistory + "\n============" : ""} +${this.lotteryCount > 0 ? "==============\n" + drawLotteryHistory + "\n==============" : ""} `.trim(); } } From 28a5707312d1e2ebc47a5af7be362a893c27bbad Mon Sep 17 00:00:00 2001 From: dbl5201314 <2239146847@qq.com> Date: Wed, 6 Apr 2022 15:20:10 +0800 Subject: [PATCH 19/27] Update README.md --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index dc220a80..f6b17a14 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ - - -## 许可 - -[MIT](./LICENSE) +test From 3b93d438d37d148e9a6dfbd83e06825625951880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=93=E5=AE=9D=E6=9E=97?= Date: Thu, 23 Jun 2022 10:45:52 +0800 Subject: [PATCH 20/27] 121 --- .github/PULL_REQUEST_TEMPLATE.md | 7 + .github/workflows/checkin.yml | 6 + .github/workflows/seaGold.yml | 6 + .prettierrc.json | 8 + CONTRIBUTING.md | 41 +++++ README.md | 46 +++++ package.json | 9 + scripts/checkin.js | 192 ++++++++++++++++++++- scripts/juejin-console-script.js | 214 ----------------------- scripts/lottery.js | 137 --------------- scripts/seaGold.js | 288 ++++++++++++++++++++++++++++++- scripts/utils/dingding.js | 20 +++ scripts/utils/email.js | 16 +- scripts/utils/env.js | 22 ++- scripts/utils/logger.js | 84 --------- scripts/utils/pushMessage.js | 12 ++ scripts/utils/pushplus.js | 41 +++++ scripts/utils/utils.js | 12 +- yarn.lock | 12 ++ 19 files changed, 725 insertions(+), 448 deletions(-) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .prettierrc.json create mode 100644 CONTRIBUTING.md delete mode 100644 scripts/juejin-console-script.js delete mode 100644 scripts/lottery.js create mode 100644 scripts/utils/dingding.js delete mode 100644 scripts/utils/logger.js create mode 100644 scripts/utils/pushMessage.js create mode 100644 scripts/utils/pushplus.js diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..513f4228 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,7 @@ + diff --git a/.github/workflows/checkin.yml b/.github/workflows/checkin.yml index 898686d6..4f2fa72f 100644 --- a/.github/workflows/checkin.yml +++ b/.github/workflows/checkin.yml @@ -13,9 +13,15 @@ jobs: - name: Run Project env: COOKIE: ${{ secrets.COOKIE }} + COOKIE_2: ${{ secrets.COOKIE_2 }} + COOKIE_3: ${{ secrets.COOKIE_3 }} + COOKIE_4: ${{ secrets.COOKIE_4 }} + COOKIE_5: ${{ secrets.COOKIE_5 }} EMAIL_USER: ${{ secrets.EMAIL_USER }} EMAIL_PASS: ${{ secrets.EMAIL_PASS }} EMAIL_TO: ${{ secrets.EMAIL_TO }} + DINGDING_WEBHOOK: ${{ secrets.DINGDING_WEBHOOK }} + PUSHPLUS_TOKEN: ${{ secrets.PUSHPLUS_TOKEN }} run: | yarn yarn checkin diff --git a/.github/workflows/seaGold.yml b/.github/workflows/seaGold.yml index c9d87123..0d5ddb11 100644 --- a/.github/workflows/seaGold.yml +++ b/.github/workflows/seaGold.yml @@ -13,9 +13,15 @@ jobs: - name: Run Project env: COOKIE: ${{ secrets.COOKIE }} + COOKIE_2: ${{ secrets.COOKIE_2 }} + COOKIE_3: ${{ secrets.COOKIE_3 }} + COOKIE_4: ${{ secrets.COOKIE_4 }} + COOKIE_5: ${{ secrets.COOKIE_5 }} EMAIL_USER: ${{ secrets.EMAIL_USER }} EMAIL_PASS: ${{ secrets.EMAIL_PASS }} EMAIL_TO: ${{ secrets.EMAIL_TO }} + DINGDING_WEBHOOK: ${{ secrets.DINGDING_WEBHOOK }} + PUSHPLUS_TOKEN: ${{ secrets.PUSHPLUS_TOKEN }} run: | yarn yarn seaGold diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000..824ac82b --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,8 @@ +{ + "tabWidth": 2, + "semi": true, + "singleQuote": false, + "printWidth": 100, + "trailingComma": "none", + "bracketSpacing": false +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..a07b7eba --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,41 @@ +# 参与贡献 + +## 分支介绍 + +- `package` 掘金API发布npm包,供给自动化工作流使用。 +- `workflows` 自动化工作流开发分支。 +- `main` 是 workflows 分支的稳定版。 + +**处理自动化相关逻辑:** +base: `workflows` <- compare `your branch` + +**处理JueJinAPI相关逻辑:** +base: `package` <- compare `your branch` + +## workflows 分支 + +### 安装 + +- `yarn` 安装依赖 + +### 环境变量 + +- `/scripts/utils/env.js` 替换本地测试所需的环境变量 + +```javascript +module.exports = { + COOKIE: "测试掘金Cookie", + // ... +}; +``` + +### 本地运行 + +- `yarn checkin` 运行掘金签到脚本 +- `yarn seagold` 运行海底掘金游戏脚本 + +## package 分支 + +- `yarn` 安装依赖 +- `yarn dev` 启动开发模式 +- `node tests/your-test.js` 测试一个模块 diff --git a/README.md b/README.md index f6a9b010..ec522f47 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +<<<<<<< Updated upstream +======= +<<<<<<< HEAD + test +======= +>>>>>>> Stashed changes
稀土掘金 @@ -6,17 +12,26 @@

JuejinHelper-稀土掘金助手

+<<<<<<< Updated upstream

签到、抽奖、沾喜气、海底掘金游戏、自动化工作流。

## 使用 自动化执行任务: 掘金每日签到, 沾喜气, 免费抽奖, 海底掘金游戏, 最后将结果报告邮件通知订阅人。\ +======= +

签到、抽奖、沾喜气、消除Bug、海底掘金游戏、自动化工作流。

+ +## 使用 + +自动化执行任务: 掘金每日签到, 沾喜气, 免费抽奖, 消除Bug, 海底掘金游戏, 最后将结果报告邮件通知订阅人。\ +>>>>>>> Stashed changes 自动化运行时间: 北京时间上午06:30 1. [Fork 仓库](https://github.com/iDerekLi/juejin-helper) 2. 仓库 -> Settings -> Secrets -> New repository secret, 添加Secrets变量如下: +<<<<<<< Updated upstream | Name | Value | | --- | --- | | COOKIE | 掘金网站Cookie, 打开浏览器,登录 [掘金](https://juejin.cn/), 打开控制台DevTools -> Network,复制 cookie, **掘金Cookie有效期约1个月需定期更新.** | @@ -25,12 +40,29 @@ | EMAIL_TO | 订阅人邮箱地址(收件人). 如需多人订阅使用 `, ` 分割, 例如: `a@163.com, b@qq.com` | 3. 仓库 -> Actions, 检查Workflows并启用。 +======= + | Name | Value | Required | + | --- | --- | --- | + | COOKIE | 掘金网站Cookie | 是 | + | COOKIE_2 | 多用户, 当需要同时运行多个掘金用户时所需, 支持最多 **5** 名用户(即COOKIE + COOKIE_2 - COOKIE_5) | 否 | + | EMAIL_USER | 发件人邮箱地址(需要开启 SMTP) | 否 | + | EMAIL_PASS | 发件人邮箱密码(SMTP密码) | 否 | + | EMAIL_TO | 订阅人邮箱地址(收件人). 如需多人订阅使用 `, ` 分割, 例如: `a@163.com, b@qq.com` | 否 | + | DINGDING_WEBHOOK | 钉钉机器人WEBHOOK | 否 | + | PUSHPLUS_TOKEN | [Pushplus](http://www.pushplus.plus/) 官网申请,支持微信消息推送 | 否 | + +4. 仓库 -> Actions, 检查Workflows并启用。 +>>>>>>> Stashed changes ## 预览 | 掘金每日签到 | 海底掘金游戏 | |:-----------:| :-------------:| +<<<<<<< Updated upstream | ![掘金每日签到](https://user-images.githubusercontent.com/24502299/150481822-b488d30c-93b6-4d73-9e28-56c04a9413fb.png) | ![海底掘金游戏](https://user-images.githubusercontent.com/24502299/150625136-5649d2fe-b204-40aa-b8b5-7f54a44e018d.png) | +======= +| ![掘金每日签到](https://user-images.githubusercontent.com/24502299/156475511-342cfcd8-3b66-4b9c-8614-215e0b4e08a1.jpg) | ![海底掘金游戏](https://user-images.githubusercontent.com/24502299/156475550-c8cc459a-3b27-4ca6-a07b-902b65bea7a9.jpg) | +>>>>>>> Stashed changes ## 问题 @@ -51,10 +83,24 @@ DevTools截图: [![海底掘金挑战赛](https://user-images.githubusercontent.com/24502299/151397151-0d69998a-2310-4a32-945f-c8e0035ed65d.png)](https://juejin.cn/game/haidijuejin/) +<<<<<<< Updated upstream ## 赞赏 ### ☕️微信赞赏!鼓励升级! +======= +## 贡献 + +这个项目的存在要感谢所有做出贡献的人。 请先阅读 [[Contribute](CONTRIBUTING.md)]。 +您可以将任何想法作为 [拉取请求](https://github.com/iDerekLi/juejin-helper/pulls) 或 [GitHub问题](https://github.com/iDerekLi/juejin-helper/issues) 提交。 + +## 赞赏 +### ☕️微信赞赏! +>>>>>>> Stashed changes 微信赞赏 ## 许可 [MIT](./LICENSE) +<<<<<<< Updated upstream +======= +>>>>>>> upstream/main +>>>>>>> Stashed changes diff --git a/package.json b/package.json index 3f6ba950..43b39826 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,12 @@ { "name": "juejin-helper", +<<<<<<< Updated upstream "version": "1.0.0", "description": "稀土掘金助手:签到、抽奖、沾喜气、海底淘金、自动化工作流。", +======= + "version": "1.5.1", + "description": "稀土掘金助手:签到、抽奖、沾喜气、消除Bug、海底掘金游戏、自动化工作流。", +>>>>>>> Stashed changes "author": "Derek Li", "license": "MIT", "scripts": { @@ -11,8 +16,12 @@ }, "dependencies": { "fast-astar": "^1.0.6", +<<<<<<< Updated upstream "jsonwebtoken": "^8.5.1", "node-fetch": "^2.6.1", +======= + "juejin-helper": "^1.5.1", +>>>>>>> Stashed changes "nodemailer": "^6.7.0" }, "repository": { diff --git a/scripts/checkin.js b/scripts/checkin.js index 32065fad..b69ae862 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -1,6 +1,7 @@ const api = require("./api/juejin-api"); const console = require("./utils/logger"); const utils = require("./utils/utils"); +<<<<<<< Updated upstream const email = require("./utils/email"); async function run(args) { @@ -32,6 +33,67 @@ async function run(args) { const sumPoint = await api.getCurrentPoint(); state.sumPoint = sumPoint; } +======= +const pushMessage = require("./utils/pushMessage"); +const env = require("./utils/env"); + +class CheckIn { + username = ""; + cookie = ""; + todayStatus = 0; // 未签到 + incrPoint = 0; + sumPoint = 0; // 当前矿石数 + contCount = 0; // 连续签到天数 + sumCount = 0; // 累计签到天数 + dipStatus = 0; + dipValue = 0; // 沾喜气 + luckyValue = 0; + lottery = []; // 奖池 + pointCost = 0; // 一次抽奖消耗 + freeCount = 0; // 免费抽奖次数 + drawLotteryHistory = {}; + lotteryCount = 0; + luckyValueProbability = 0; + bugStatus = 0; + collectBugCount = 0; + userOwnBug = 0; + + calledSdkSetting = false; + calledTrackGrowthEvent = false; + calledTrackOnloadEvent = false; + + constructor(cookie) { + this.cookie = cookie; + } + + async run() { + const juejin = new JuejinHelper(); + try { + await juejin.login(this.cookie); + } catch (e) { + console.error(e); + throw new Error("登录失败, 请尝试更新Cookies!"); + } + + this.username = juejin.getUser().user_name; + + const growth = juejin.growth(); + + const todayStatus = await growth.getTodayStatus(); + if (!todayStatus) { + const checkInResult = await growth.checkIn(); + + this.incrPoint = checkInResult.incr_point; + this.sumPoint = checkInResult.sum_point; + this.todayStatus = 1; // 本次签到 + } else { + this.todayStatus = 2; // 已签到 + } + + const counts = await growth.getCounts(); + this.contCount = counts.cont_count; + this.sumCount = counts.sum_count; +>>>>>>> Stashed changes try { const luckyusersResult = await api.getLotteriesLuckyUsers(); @@ -44,6 +106,7 @@ async function run(args) { console.log(`沾喜气 +${dipLuckyResult.dip_value} 幸运值`); } } +<<<<<<< Updated upstream } catch {} console.log(`当前余额:${state.sumPoint} 矿石`); @@ -106,10 +169,68 @@ async function run(args) { state.freeCount--; await utils.wait(state.simulateSpeed); } +======= + + const luckyResult = await growth.getMyLucky(); + this.luckyValue = luckyResult.total_value; + + const lotteryConfig = await growth.getLotteryConfig(); + this.lottery = lotteryConfig.lottery; + this.pointCost = lotteryConfig.point_cost; + this.freeCount = lotteryConfig.free_count; + this.lotteryCount = 0; + + let freeCount = this.freeCount; + while (freeCount > 0) { + const result = await growth.drawLottery(); + this.drawLotteryHistory[result.lottery_id] = + (this.drawLotteryHistory[result.lottery_id] || 0) + 1; + this.luckyValue = result.total_lucky_value; + freeCount--; + this.lotteryCount++; + await utils.wait(utils.randomRangeNumber(300, 1000)); + } + + this.sumPoint = await growth.getCurrentPoint(); + + const getProbabilityOfWinning = (sumPoint) => { + const pointCost = this.pointCost; + const luckyValueCost = 10; + const totalDrawsNumber = sumPoint / pointCost; + let supplyPoint = 0; + for (let i = 0, length = Math.floor(totalDrawsNumber * 0.65); i < length; i++) { + supplyPoint += Math.ceil(Math.random() * 100); + } + const luckyValue = ((sumPoint + supplyPoint) / pointCost) * luckyValueCost + this.luckyValue; + return luckyValue / 6000; + }; +>>>>>>> Stashed changes console.logGroupEnd("奖品实况"); +<<<<<<< Updated upstream console.log(`当前余额:${state.sumPoint} 矿石`); +======= + // 收集bug + const bugfix = juejin.bugfix(); + + const competition = await bugfix.getCompetition(); + const bugfixInfo = await bugfix.getUser(competition); + this.userOwnBug = bugfixInfo.user_own_bug; + + try { + const notCollectBugList = await bugfix.getNotCollectBugList(); + await bugfix.collectBugBatch(notCollectBugList); + this.bugStatus = 1; + this.collectBugCount = notCollectBugList.length; + this.userOwnBug += this.collectBugCount; + } catch (e) { + this.bugStatus = 2; + } + + // 调用埋点 + const sdk = juejin.sdk(); +>>>>>>> Stashed changes const recordInfo = []; recordInfo.push("=====[战绩详情]====="); @@ -124,6 +245,7 @@ async function run(args) { } else { recordInfo.push("暂无奖品"); } +<<<<<<< Updated upstream recordInfo.push("+++++++++++++++++++"); recordInfo.push(`幸运值: ${state.luckyValue}/6000`); recordInfo.push("==================="); @@ -133,10 +255,76 @@ async function run(args) { subject: "掘金每日签到", text: console.toString() }); +======= + + toString() { + const drawLotteryHistory = Object.entries(this.drawLotteryHistory) + .map(([lottery_id, count]) => { + const lotteryItem = this.lottery.find((item) => item.lottery_id === lottery_id); + if (lotteryItem) { + return `${lotteryItem.lottery_name}: ${count}`; + } + return `${lottery_id}: ${count}`; + }) + .join("\n"); + + return ` +掘友: ${this.username} +${ + this.todayStatus === 1 + ? `签到成功 +${this.incrPoint} 矿石` + : this.todayStatus === 2 + ? "今日已完成签到" + : "签到失败" +} +${ + this.dipStatus === 1 + ? `沾喜气 +${this.dipValue} 幸运值` + : this.dipStatus === 2 + ? "今日已经沾过喜气" + : "沾喜气失败" +} +${ + this.bugStatus === 1 + ? this.collectBugCount > 0 + ? `收集Bug +${this.collectBugCount}` + : "没有可收集Bug" + : "收集Bug失败" +} +连续签到天数 ${this.contCount} +累计签到天数 ${this.sumCount} +当前矿石数 ${this.sumPoint} +当前未消除Bug数量 ${this.userOwnBug} +当前幸运值 ${this.luckyValue}/6000 +预测All In矿石累计幸运值比率 ${(this.luckyValueProbability * 100).toFixed(2) + "%"} +抽奖总次数 ${this.lotteryCount} +免费抽奖次数 ${this.freeCount} +${this.lotteryCount > 0 ? "==============\n" + drawLotteryHistory + "\n==============" : ""} +`.trim(); + } } -run(process.argv.splice(2)).catch(error => { - email({ +async function run(args) { + const cookies = utils.getUsersCookie(env); + for (let cookie of cookies) { + const checkin = new CheckIn(cookie); + + await utils.wait(utils.randomRangeNumber(1000, 5000)); // 初始等待1-5s + await checkin.run(); // 执行 + + const content = checkin.toString(); + console.log(content); // 打印结果 + + pushMessage({ + subject: "掘金每日签到", + text: content + }); + } +>>>>>>> Stashed changes +} + +run(process.argv.splice(2)).catch((error) => { + pushMessage({ subject: "掘金每日签到", html: `Error
${error.message}
` }); diff --git a/scripts/juejin-console-script.js b/scripts/juejin-console-script.js deleted file mode 100644 index 886b7059..00000000 --- a/scripts/juejin-console-script.js +++ /dev/null @@ -1,214 +0,0 @@ -!(({ api, console, utils }) => { - const state = { - simulateSpeed: 100, // ms/进行一次抽奖 - sumPoint: 0, - pointCost: 0, - supplyPoint: 0, - freeCount: 0, - luckyValue: 0, - lottery: [], - counter: 0, - prize: {} - }; - - !(async () => { - await utils.wait(100); - console.clear(); - - try { - const checkInResult = await api.checkIn(); - console.log(checkInResult); - const incrPoint = checkInResult.incr_point; - console.log(`签到成功 +${incrPoint} 矿石`); - - const sumPoint = checkInResult.sum_point; - state.sumPoint = sumPoint; - } catch (e) { - console.log(e.message); - - const sumPoint = await api.getCurrentPoint(); - state.sumPoint = sumPoint; - } - - try { - const luckyusersResult = await api.getLotteriesLuckyUsers(); - if (luckyusersResult.count > 0) { - const no1LuckyUser = luckyusersResult.lotteries[0]; - const dipLuckyResult = await api.dipLucky(no1LuckyUser.history_id); - if (dipLuckyResult.has_dip) { - console.log(`今天你已经沾过喜气,明天再来吧!`); - } else { - console.log(`沾喜气 +${dipLuckyResult.dip_value} 幸运值`); - } - } - } catch {} - - console.log(`当前余额:${state.sumPoint} 矿石`); - - const luckyResult = await api.getMyLucky(); - state.luckyValue = luckyResult.total_value; - console.log(`当前幸运值:${state.luckyValue}/6000`); - - const lotteryConfig = await api.getLotteryConfig(); - state.lottery = lotteryConfig.lottery; - state.pointCost = lotteryConfig.point_cost; - state.freeCount = lotteryConfig.free_count; - state.sumPoint += state.freeCount * state.pointCost; - console.log(`免费抽奖次数: ${state.freeCount}`); - - const getProbabilityOfWinning = sumPoint => { - const pointCost = 200; - const luckyValueCost = 10; - const totalDrawsNumber = sumPoint / pointCost; - const perhapsSupplyNumber = Math.floor(totalDrawsNumber * (2 / 3)); - let supplyPoint = 0; - for(let i = 0; i < perhapsSupplyNumber; i++) { - supplyPoint += Math.ceil(Math.random() * 100) - } - const luckyValue = (sumPoint + supplyPoint) / pointCost * luckyValueCost + state.luckyValue; - return luckyValue / 6000; - } - - console.log(`预测您必中奖幸运概率: ${(getProbabilityOfWinning(state.sumPoint) * 100).toFixed(2) + "%"}`); - - console.log(`准备梭哈!`); - - console.logGroupStart("奖品实况"); - - const getSupplyPoint = draw => { - const maybe = [ - ["lottery_id", "6981716980386496552"], - ["lottery_name", "随机矿石"], - ["lottery_type", 1] - ]; - if (maybe.findIndex(([prop, value]) => draw[prop] === value) !== -1) { - const supplyPoint = Number.parseInt(draw.lottery_name); - if (!isNaN(supplyPoint)) { - return supplyPoint; - } - } - return 0; - }; - - const lottery = async () => { - const result = await api.drawLottery(); - state.sumPoint -= state.pointCost; - state.sumPoint += getSupplyPoint(result); - state.luckyValue += result.draw_lucky_value; - state.counter++; - state.prize[result.lottery_name] = (state.prize[result.lottery_name] || 0) + 1; - console.log(`[第${state.counter}抽]:${result.lottery_name}`); - }; - - while (state.freeCount > 0) { - await lottery(); - state.freeCount--; - await utils.wait(state.simulateSpeed); - } - - // while (state.sumPoint >= state.pointCost) { - // await lottery(); - // await utils.wait(state.simulateSpeed); - // } - - console.logGroupEnd("奖品实况"); - - console.log(`弹药不足,当前余额:${state.sumPoint} 矿石`); - console.log(`养精蓄锐来日再战!`); - - const recordInfo = []; - recordInfo.push("=====[战绩详情]====="); - if (state.counter > 0) { - const prizeList = []; - for (const key in state.prize) { - prizeList.push(`${key}: ${state.prize[key]}`); - } - recordInfo.push(...prizeList); - recordInfo.push("-------------------"); - recordInfo.push(`共计: ${state.counter}`); - } else { - recordInfo.push("暂无奖品"); - } - recordInfo.push("+++++++++++++++++++"); - recordInfo.push(`幸运值: ${state.luckyValue}/6000`); - recordInfo.push("==================="); - console.log(recordInfo.join("\n")); - })(); -})( - (() => { - const cs = (() => { - const result = []; - return { - done: () => (typeof completion === "function" && completion(result), (result.length = 0)), - log: msg => (result.push(msg), console.log(msg)), - clear: () => ((result.length = 0), console.clear()), - logGroupStart: name => console.group(name), - logGroupEnd: name => console.groupEnd(name) - }; - })(); - - const api = (() => { - return { - async fetch({ path, method, data }) { - return fetch(`https://api.juejin.cn/growth_api/v1${path}`, { - headers: { - cookie: document.cookie - }, - method: method, - body: JSON.stringify(data), - credentials: "include" - }) - .then(res => res.json()) - .then(res => { - if (res.err_no) { - throw new Error(res.err_msg); - } - return res.data; - }); - }, - async get(path) { - return this.fetch({ path, method: "GET" }); - }, - async post(path, data) { - return this.fetch({ path, method: "POST", data }); - }, - async getLotteryConfig() { - return this.get("/lottery_config/get"); - }, - async getCurrentPoint() { - return this.get("/get_cur_point"); - }, - async drawLottery() { - return this.post("/lottery/draw"); - }, - async checkIn() { - return this.post("/check_in"); - }, - async getLotteriesLuckyUsers() { - return this.post("/lottery_history/global_big", { - page_no: 1, - page_size: 5 - }); - }, - async dipLucky(lottery_history_id) { - return this.post("/lottery_lucky/dip_lucky", { - lottery_history_id - }); - }, - async getMyLucky() { - return this.post("/lottery_lucky/my_lucky"); - } - }; - })(); - - const utils = (() => { - return { - async wait(time = 0) { - return new Promise(resolve => setTimeout(resolve, time)); - } - }; - })(); - - return { console: cs, api, utils }; - })() -); diff --git a/scripts/lottery.js b/scripts/lottery.js deleted file mode 100644 index 73b5b25d..00000000 --- a/scripts/lottery.js +++ /dev/null @@ -1,137 +0,0 @@ -const api = require("./utils/juejin-api"); -const console = require("./utils/logger"); -const utils = require("./utils/utils"); -const email = require("./utils/email"); - -async function run(args) { - const state = { - simulateSpeed: 100, // ms/进行一次抽奖 - sumPoint: 0, - pointCost: 0, - supplyPoint: 0, - freeCount: 0, - luckyValue: 0, - lottery: [], - counter: 0, - prize: {} - }; - - await utils.wait(100); - console.clear(); - - try { - const checkInResult = await api.checkIn(); - console.log(checkInResult); - const incrPoint = checkInResult.incr_point; - console.log(`签到成功 +${incrPoint} 矿石`); - - const sumPoint = checkInResult.sum_point; - state.sumPoint = sumPoint; - } catch (e) { - console.log(e.message); - - const sumPoint = await api.getCurrentPoint(); - state.sumPoint = sumPoint; - } - - try { - const luckyusersResult = await api.getLotteriesLuckyUsers(); - if (luckyusersResult.count > 0) { - const no1LuckyUser = luckyusersResult.lotteries[0]; - const dipLuckyResult = await api.dipLucky(no1LuckyUser.history_id); - if (dipLuckyResult.has_dip) { - console.log(`今天你已经沾过喜气,明天再来吧!`); - } else { - console.log(`沾喜气 +${dipLuckyResult.dip_value} 幸运值`); - } - } - } catch {} - - console.log(`当前余额:${state.sumPoint} 矿石`); - - const luckyResult = await api.getMyLucky(); - state.luckyValue = luckyResult.total_value; - console.log(`当前幸运值:${state.luckyValue}/6000`); - - const lotteryConfig = await api.getLotteryConfig(); - state.lottery = lotteryConfig.lottery; - state.pointCost = lotteryConfig.point_cost; - state.freeCount = lotteryConfig.free_count; - state.sumPoint += state.freeCount * state.pointCost; - console.log(`免费抽奖次数: ${state.freeCount}`); - - console.log(`准备梭哈!`); - - console.logGroupStart("奖品实况"); - - const getSupplyPoint = draw => { - const maybe = [ - ["lottery_id", "6981716980386496552"], - ["lottery_name", "随机矿石"], - ["lottery_type", 1] - ]; - if (maybe.findIndex(([prop, value]) => draw[prop] === value) !== -1) { - const supplyPoint = Number.parseInt(draw.lottery_name); - if (!isNaN(supplyPoint)) { - return supplyPoint; - } - } - return 0; - }; - - const lottery = async () => { - const result = await api.drawLottery(); - state.sumPoint -= state.pointCost; - state.sumPoint += getSupplyPoint(result); - state.luckyValue += result.draw_lucky_value; - state.counter++; - state.prize[result.lottery_name] = (state.prize[result.lottery_name] || 0) + 1; - console.log(`[第${state.counter}抽]:${result.lottery_name}`); - }; - - while (state.freeCount > 0) { - await lottery(); - state.freeCount--; - await utils.wait(state.simulateSpeed); - } - - while (state.sumPoint >= state.pointCost) { - await lottery(); - await utils.wait(state.simulateSpeed); - } - - console.logGroupEnd("奖品实况"); - - console.log(`弹药不足,当前余额:${state.sumPoint} 矿石`); - console.log(`养精蓄锐来日再战!`); - - const recordInfo = []; - recordInfo.push("=====[战绩详情]====="); - if (state.counter > 0) { - const prizeList = []; - for (const key in state.prize) { - prizeList.push(`${key}: ${state.prize[key]}`); - } - recordInfo.push(...prizeList); - recordInfo.push("-------------------"); - recordInfo.push(`共计: ${state.counter}`); - } else { - recordInfo.push("暂无奖品"); - } - recordInfo.push("+++++++++++++++++++"); - recordInfo.push(`幸运值: ${state.luckyValue}/6000`); - recordInfo.push("==================="); - console.log(recordInfo.join("\n")); - - email({ - subject: "掘金每日签到", - text: console.toString() - }); -} - -run(process.argv.splice(2)).catch(error => { - email({ - subject: "掘金每日签到", - html: `Error
${error.message}
` - }); -}); diff --git a/scripts/seaGold.js b/scripts/seaGold.js index 845522eb..6d4db946 100644 --- a/scripts/seaGold.js +++ b/scripts/seaGold.js @@ -1,9 +1,68 @@ const api = require("./api/juejin-api"); const juejinGameApi = require("./api/juejin-game-api"); const utils = require("./utils/utils"); +<<<<<<< Updated upstream const { Grid, Astar } = require("fast-astar"); const console = require("./utils/logger"); const email = require("./utils/email"); +======= +const {Grid, Astar} = require("fast-astar"); +const pushMessage = require("./utils/pushMessage"); +const env = require("./utils/env"); + +class SeaGold { + gameApi = null; + cookie = ""; + + constructor(cookie) { + this.cookie = cookie; + } + + nodeRules = [ + {code: 0, hasBounty: false, isWall: false, name: "空地"}, + {code: 2, hasBounty: true, isWall: false, name: "矿石", isBest: true}, + {code: 3, hasBounty: false, isWall: false, name: "星星"}, + {code: 4, hasBounty: false, isWall: true, name: "贝壳"}, + {code: 5, hasBounty: false, isWall: true, name: "水母"}, + {code: 6, hasBounty: false, isWall: true, name: "石头"}, + {code: 10, hasBounty: true, isWall: false, name: "上指令"}, + {code: 11, hasBounty: true, isWall: false, name: "下指令"}, + {code: 12, hasBounty: true, isWall: false, name: "左指令"}, + {code: 13, hasBounty: true, isWall: false, name: "右指令"}, + {code: 14, hasBounty: true, isWall: false, name: "跳跃指令"}, + {code: 15, hasBounty: true, isWall: false, name: "循环指令"} + ]; + + debug = false; + userInfo = { + uid: "", + name: "", + todayDiamond: 0, // 今日获取矿石数 + todayLimitDiamond: 1500, // 今日限制获取矿石数 + maxTodayDiamond: 0 // 今日最大矿石数 + }; + + gameInfo = { + gameId: "", + mapData: [], + curPos: {x: 0, y: 0}, + blockData: { + moveUp: 0, + moveDown: 0, + moveLeft: 0, + moveRight: 0, + jump: 0, + loop: 0 + }, + gameDiamond: 0 + }; + + history = []; + + get isGaming() { + return this.gameInfo && this.gameInfo.gameId !== ""; + } +>>>>>>> Stashed changes async function run(args) { console.clear(); @@ -46,7 +105,7 @@ async function run(args) { gameInfo = { gameId: "", mapData: [], - curPos: { x: 0, y: 0 }, + curPos: {x: 0, y: 0}, blockData: { moveUp: 0, moveDown: 0, @@ -58,6 +117,7 @@ async function run(args) { gameDiamond: 0 }; +<<<<<<< Updated upstream get isGaming() { return this.gameInfo && this.gameInfo.gameId !== ""; } @@ -82,6 +142,32 @@ async function run(args) { this.resetGame(); } } +======= + restoreGame(gameInfo) { + this.gameInfo = { + gameId: gameInfo.gameId, + mapData: this.makeMap(gameInfo.mapData, 6), + curPos: gameInfo.curPos, + blockData: gameInfo.blockData, + gameDiamond: gameInfo.gameDiamond + }; + } + + async gameStart() { + if (this.isGaming) return; + const roleId = Math.ceil(Math.random() * 3); + const gameInfo = await this.gameApi.gameStart({roleId}); + + this.gameInfo = { + roleId, + gameId: gameInfo.gameId, + mapData: this.makeMap(gameInfo.mapData, 6), + curPos: gameInfo.curPos, + blockData: gameInfo.blockData, + gameDiamond: 0 + }; + } +>>>>>>> Stashed changes resetGame() { this.gameInfo = { @@ -140,6 +226,7 @@ async function run(args) { return gameDiamond; } +<<<<<<< Updated upstream async executeGameCommand() { const bmmap = this.getBMMap(); const curNode = this.getNode(this.gameInfo.curPos); @@ -156,6 +243,21 @@ async function run(args) { this.gameInfo.gameDiamond = gameCommandInfo.gameDiamond; console.log(`curPos(${this.gameInfo.curPos.x},${this.gameInfo.curPos.y}): ${this.gameInfo.gameDiamond} 矿石`); return true; +======= + async executeGameCommand() { + const bmmap = this.getBMMap(); + const curNode = this.getNode(this.gameInfo.curPos); + const bestNode = this.getBestNode(bmmap); + const path = this.getRoutePath(bmmap, curNode, bestNode); + if (!Array.isArray(path)) { + throw new Error( + `路径 ${JSON.stringify(path)} 无法在地图 ${JSON.stringify(this.getMaze(bmmap))} 行进.` + ); + } + const commands = this.getCommands(path); + if (commands.length <= 0) { + return false; +>>>>>>> Stashed changes } getCommand(start, end) { @@ -173,6 +275,7 @@ async function run(args) { return null; } +<<<<<<< Updated upstream getCommands(path) { const commands = []; for(let i=0; i${i+1}`); } commands.push(cmd); +======= + return null; + } + + getCommands(path) { + const commands = []; + for (let i = 0; i < path.length - 1; i++) { + const cmd = this.getCommand(path[i], path[i + 1]); + if (!cmd) { + throw new Error(`路径错误: ${i}->${i + 1}`); +>>>>>>> Stashed changes } return commands; } +<<<<<<< Updated upstream getNodePosition(map, node) { for (let y = 0; y < map.length; y++) { const list = map[y]; @@ -193,21 +308,48 @@ async function run(args) { if (cNode === node) { return { x, y }; } +======= + getNodePosition(map, node) { + for (let y = 0; y < map.length; y++) { + const list = map[y]; + for (let x = 0; x < list.length; x++) { + const cNode = list[x]; + if (cNode === node) { + return {x, y}; +>>>>>>> Stashed changes } } return { x: 0, y: 0 }; } +<<<<<<< Updated upstream +======= + return {x: 0, y: 0}; + } + + getRoutePath(map, startNode, endNode) { + const maze = this.generateMapMaze(map); + const startPos = this.getNodePosition(map, startNode); + const endPos = this.getNodePosition(map, endNode); +>>>>>>> Stashed changes getRoutePath(map, startNode, endNode) { const maze = this.generateMapMaze(map); const startPos = this.getNodePosition(map, startNode); const endPos = this.getNodePosition(map, endNode); +<<<<<<< Updated upstream if (this.debug) { console.log("地图", this.getMaze(map)); console.log("开始位置", startPos); console.log("结束位置", endPos); } +======= + const astar = new Astar(maze); + const path = astar.search([startPos.x, startPos.y], [endPos.x, endPos.y], { + rightAngle: true, + optimalResult: true + }); +>>>>>>> Stashed changes const astar = new Astar(maze); const path = astar.search( @@ -219,9 +361,22 @@ async function run(args) { } ); +<<<<<<< Updated upstream return path; +======= + makeMap(mapData, grid = 6) { + const map = []; + for (let i = 0, y = 0; i < mapData.length; i += grid, y++) { + const row = []; + map.push(row); + for (let x = 0; x < grid; x++) { + const cell = mapData[i + x]; + row.push(this.createMapNode(x, y, cell)); + } +>>>>>>> Stashed changes } +<<<<<<< Updated upstream makeMap(mapData, grid = 6) { const map = []; for (let i = 0, y = 0; i < mapData.length; i+=grid, y++) { @@ -244,6 +399,34 @@ async function run(args) { y, isWall: rule.isWall, isBest: !!rule.isBest +======= + createMapNode(x, y, secret) { + const rule = this.getNodeRule(secret); + return { + code: rule.code, + bounty: rule.hasBounty ? this.getBounty(secret, rule.code) : 0, + x, + y, + isWall: rule.isWall, + isBest: !!rule.isBest + }; + } + + // 获取范围地图 + getBMMap() { + const {mapData, blockData, curPos} = this.gameInfo; + const minX = Math.max(curPos.x - blockData.moveLeft, 0); + const maxX = Math.min(curPos.x + blockData.moveRight, mapData[0].length - 1); + const minY = Math.max(curPos.y - blockData.moveUp, 0); + const maxY = Math.min(curPos.y + blockData.moveDown, mapData.length - 1); + + const map = []; + for (let y = minY; y <= maxY; y++) { + const row = []; + map.push(row); + for (let x = minX; x <= maxX; x++) { + row.push(mapData[y][x]); +>>>>>>> Stashed changes } } @@ -266,9 +449,25 @@ async function run(args) { return map; } +<<<<<<< Updated upstream getNode(pos) { return this.gameInfo.mapData[pos.y][pos.x]; } +======= + getBestNode(map) { + let bestNode = null; + map.forEach((row) => { + row.forEach((node) => { + if (node.isBest && bestNode === null) { + bestNode = node; + } else if (node.isBest && node.bounty > bestNode.bounty) { + bestNode = node; + } + }); + }); + return bestNode; + } +>>>>>>> Stashed changes getBestNode(map) { let bestNode = null; @@ -284,6 +483,7 @@ async function run(args) { return bestNode; } +<<<<<<< Updated upstream getMaze(map) { return map.map((row, y) => { return row.map((node, x) => { @@ -293,6 +493,20 @@ async function run(args) { return 0; } }); +======= + // 生成迷宫 + generateMapMaze(map) { + const grid = new Grid({ + col: map[0].length, + row: map.length + }); + + map.forEach((row, y) => { + row.forEach((node, x) => { + if (node.isWall) { + grid.set([x, y], "value", 1); + } +>>>>>>> Stashed changes }); } @@ -303,6 +517,7 @@ async function run(args) { row: map.length }); +<<<<<<< Updated upstream map.forEach((row, y) => { row.forEach((node, x) => { if (node.isWall) { @@ -310,15 +525,34 @@ async function run(args) { } }); }); +======= + getNodeRule(secret) { + return this.nodeRules.find((rule) => { + const reg = new RegExp(`^${rule.code}`); + return reg.test(secret); + }); + } +>>>>>>> Stashed changes return grid; } +<<<<<<< Updated upstream getNodeRule(secret) { return this.nodeRules.find(rule => { const reg = new RegExp(`^${rule.code}`); return reg.test(secret); }); +======= + async run() { + const juejin = new JuejinHelper(); + await juejin.login(this.cookie); + this.gameApi = juejin.seagold(); + + const loginInfo = await this.gameApi.gameLogin(); + if (!loginInfo.isAuth) { + throw Error(`掘友 ${loginInfo.name} 未授权, 请前往掘金授权!`); +>>>>>>> Stashed changes } getBounty(secret, key) { @@ -345,6 +579,7 @@ async function run(args) { await utils.wait(utils.randomRangeNumber(1000, 1500)); run = await seaGold.executeGameCommand(); } +<<<<<<< Updated upstream return await seaGold.gameOver(); } catch (e) { await seaGold.gameOver(); @@ -355,6 +590,12 @@ async function run(args) { if (seaGold.userInfo.todayDiamond >= seaGold.userInfo.todayLimitDiamond) { console.log(`今日开采已达上限!`); } else { +======= + + return await this.gameOver(); + }; + +>>>>>>> Stashed changes const maxZeroCount = 5; let zeroCount = 0; const runEndTime = new Date(); @@ -380,6 +621,7 @@ async function run(args) { runTime = new Date(); } +<<<<<<< Updated upstream if (seaGold.userInfo.todayDiamond >= seaGold.userInfo.todayLimitDiamond) { console.log(`今日开采已达上限!`); } @@ -394,6 +636,50 @@ async function run(args) { run(process.argv.splice(2)).catch(error => { console.log(error); email({ +======= + await juejin.logout(); + } + + toString() { + const userInfo = this.userInfo; + const gameLives = this.history + .map((game) => `${game.gameId}\n 挖取 ${game.gameDiamond}\n 获得 ${game.realDiamond}`) + .join("\n"); + + return ` +掘友: ${userInfo.name} +今日限制矿石数 ${userInfo.todayLimitDiamond} +${ + userInfo.todayDiamond < userInfo.todayLimitDiamond + ? `今日获取矿石数 ${userInfo.todayDiamond}` + : "今日获取已达上限" +} +${this.history.length ? `\n游戏记录\n${gameLives}` : ""} +`.trim(); + } +} + +async function run(args) { + const cookies = utils.getUsersCookie(env); + for (let cookie of cookies) { + const seaGold = new SeaGold(cookie); + + await utils.wait(utils.randomRangeNumber(1000, 5000)); // 初始等待1-5s + await seaGold.run(); + + const content = seaGold.toString(); + console.log(content); + + pushMessage({ + subject: "海底掘金游戏", + text: content + }); + } +} + +run(process.argv.splice(2)).catch((error) => { + pushMessage({ +>>>>>>> Stashed changes subject: "海底掘金游戏", html: `Error
${error.message}
` }); diff --git a/scripts/utils/dingding.js b/scripts/utils/dingding.js new file mode 100644 index 00000000..2bfe864f --- /dev/null +++ b/scripts/utils/dingding.js @@ -0,0 +1,20 @@ +const fetch = require("node-fetch"); + +const env = require("./env"); +async function dingding({ subject, text, html }) { + return fetch(env.DINGDING_WEBHOOK, { + headers: { + "Content-Type": "application/json", + Charset: "UTF-8" + }, + method: "POST", + body: JSON.stringify({ + msgtype: "text", + text: { + content: `${subject}\n${text || html}` + } + }) + }).then((res) => console.log(JSON.stringify(res))); +} + +module.exports = dingding; diff --git a/scripts/utils/email.js b/scripts/utils/email.js index b24ed3d1..ba4a6676 100644 --- a/scripts/utils/email.js +++ b/scripts/utils/email.js @@ -6,7 +6,7 @@ async function main({ subject, text, html }) { const auth = { user: env.EMAIL_USER, // generated ethereal user - pass: env.EMAIL_PASS, // generated ethereal password + pass: env.EMAIL_PASS // generated ethereal password }; const transporter = nodemailer.createTransport({ @@ -25,7 +25,7 @@ async function main({ subject, text, html }) {
稀土掘金助手 | - Copyright © 2022 Derek Li. + Copyright © ${new Date().getFullYear()} Derek Li.
`.trim(); @@ -36,11 +36,13 @@ async function main({ subject, text, html }) { subject, // Subject line // text, // plain text body html: template, // html body - attachments: [{ - filename: "logo.svg", - path: path.resolve(__dirname, "../../resources/logo.svg"), - cid: 'logo.svg' //same cid value as in the html img src - }] + attachments: [ + { + filename: "logo.svg", + path: path.resolve(__dirname, "../../resources/logo.svg"), + cid: "logo.svg" //same cid value as in the html img src + } + ] }); console.log("已通知订阅人!"); diff --git a/scripts/utils/env.js b/scripts/utils/env.js index 2e98bcb7..e49ba69b 100644 --- a/scripts/utils/env.js +++ b/scripts/utils/env.js @@ -1,8 +1,28 @@ const env = process.env || {}; module.exports = { + /* 掘金Cookie */ + COOKIE: env.COOKIE, + /* 多用户掘金Cookie, 当有1名以上用户时填写, 支持同时最多可配置5名用户 */ + COOKIE_2: env.COOKIE_2, + COOKIE_3: env.COOKIE_3, + COOKIE_4: env.COOKIE_4, + COOKIE_5: env.COOKIE_5, + /** + * 邮箱配置 + * user 发件人邮箱, pass, 发件人密码, to收件人 + */ EMAIL_USER: env.EMAIL_USER, EMAIL_PASS: env.EMAIL_PASS, EMAIL_TO: env.EMAIL_TO, - COOKIE: env.COOKIE + /** + * 钉钉配置 + * https://open.dingtalk.com/document/robots/custom-robot-access + */ + DINGDING_WEBHOOK: env.DINGDING_WEBHOOK, + /** + * PushPlus配置 + * http://www.pushplus.plus/doc/guide/openApi.html + */ + PUSHPLUS_TOKEN: env.PUSHPLUS_TOKEN }; diff --git a/scripts/utils/logger.js b/scripts/utils/logger.js deleted file mode 100644 index 331e4be8..00000000 --- a/scripts/utils/logger.js +++ /dev/null @@ -1,84 +0,0 @@ -class LogNode { - constructor(data, parent = null, leaf = true) { - this.data = data; - this.parent = parent; - this.level = parent ? parent.level + 1 : 0; - this.leaf = leaf; - - if (!leaf) { - this.children = []; - } - } - - toString() { - const level = this.level - 1; - const isGroup = !this.leaf; - return `${' '.repeat(level * 3)}${isGroup ? '▼' : level > 0 ? '-' : ' '} ${this.data}\n`; - } -} - -class Logger { - result = this.createNode(null, null, false); - current = this.result; - - createNode(data, parent, leaf) { - return new LogNode(data, parent, leaf); - } - - clear() { - this.result = this.createNode(null, null, false); - this.current = this.result; - console.clear(); - } - - log(msg) { - const node = this.createNode(msg, this.current, true); - this.current.children.push(node); - console.log(msg); - } - - logGroupStart(name) { - const current = this.createNode(name, this.current, false); - this.result.children.push(current); - this.current = current; - console.group(name); - } - - logGroupEnd(name) { - const current = this.current.parent; - this.current = current; - console.groupEnd(name); - } - - toString() { - const each = children => { - if (!Array.isArray(children)) return ""; - let content = ""; - children.forEach(child => { - content += child.toString(); - if (!child.leaf) { - content += each(child.children); - } - }); - return content; - } - return each(this.result.children); - } -} - -const logger = new Logger(); - -module.exports = logger; -// logger.log(2) -// logger.logGroupStart("group 1") -// logger.log(3) -// logger.log(4) -// logger.log(5) -// logger.logGroupStart("group 2") -// logger.log(6) -// logger.log(7) -// logger.log(8) -// logger.logGroupEnd("group 2") -// logger.logGroupEnd("group 1") -// logger.log(9) -// logger.toString(); diff --git a/scripts/utils/pushMessage.js b/scripts/utils/pushMessage.js new file mode 100644 index 00000000..68c4ca2b --- /dev/null +++ b/scripts/utils/pushMessage.js @@ -0,0 +1,12 @@ +const env = require("./env"); +const email = require("./email"); +const pushplus = require("./pushplus"); +const dingding = require("./dingding"); + +async function pushMessage({ subject, text, html }) { + env.EMAIL_USER && (await email({ subject, text, html })); + env.DINGDING_WEBHOOK && (await dingding({ subject, text, html })); + env.PUSHPLUS_TOKEN && (await pushplus({ subject, text, html })); +} + +module.exports = pushMessage; diff --git a/scripts/utils/pushplus.js b/scripts/utils/pushplus.js new file mode 100644 index 00000000..5962b75b --- /dev/null +++ b/scripts/utils/pushplus.js @@ -0,0 +1,41 @@ +const fetch = require("node-fetch"); +const env = require("./env"); +const userConfig = { + url: "http://www.pushplus.plus/send", + token: env.PUSHPLUS_TOKEN +}; + +async function main({ subject, text, html }) { + if (!userConfig.token) { + console.warn("未配置PushPlus之Token, 请先配置PushPlus"); + return; + } + return await postMessage({ + token: userConfig.token, + title: subject, + content: text ?? html, + topic: "", + template: "html", + channel: "wechat", + webhook: "", + callbackUrl: "", + timestamp: "" + }) + .then((res) => res.json()) + .then((json) => { + console.log(`PushPlus推送结果: ` + json.msg); + return json; + }); +} + +async function postMessage(message) { + return await fetch(userConfig.url, { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(message) + }).catch((err) => console.log(err)); +} + +module.exports = main; diff --git a/scripts/utils/utils.js b/scripts/utils/utils.js index 2fafe4b2..62b8d950 100644 --- a/scripts/utils/utils.js +++ b/scripts/utils/utils.js @@ -1,8 +1,16 @@ module.exports = { async wait(time = 0) { - return new Promise(resolve => setTimeout(resolve, time)); + return new Promise((resolve) => setTimeout(resolve, time)); }, randomRangeNumber(start = 500, end = 1000) { return (Math.random() * (end - start) + start) >> 0; + }, + getUsersCookie(env) { + const users = [env.COOKIE]; + + const keys = Object.keys(env).filter(key => key.match(/^COOKIE_([0-9])+$/)); + keys.forEach(key => users.push(env[key])); + + return users.filter(cookie => !!cookie); } -} +}; diff --git a/yarn.lock b/yarn.lock index 6e3974e8..692cd85a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -35,6 +35,18 @@ jsonwebtoken@^8.5.1: ms "^2.1.1" semver "^5.6.0" +<<<<<<< Updated upstream +======= +juejin-helper@^1.5.1: + version "1.5.1" + resolved "https://registry.npmmirror.com/juejin-helper/-/juejin-helper-1.5.1.tgz#416dd622e18daa03fd5ab68f2fb74ec522ce4e8f" + integrity sha512-CoC4D0hph59eodM2aO7Brj8hURvFuI8PvrSgZQzyjQ/5BqYK2+ewcMNXxhzYWvHZ4ENMFqfwzHbOU4OelfyJ6Q== + dependencies: + jsonwebtoken "^8.5.1" + node-fetch "^2.6.1" + uuid "^8.3.2" + +>>>>>>> Stashed changes jwa@^1.4.1: version "1.4.1" resolved "https://registry.npm.taobao.org/jwa/download/jwa-1.4.1.tgz#743c32985cb9e98655530d53641b66c8645b039a" From 9edbd348bbaff45f11842069c6c39f3d7a4b124c Mon Sep 17 00:00:00 2001 From: dbl520 <2239146847@qq.com> Date: Thu, 23 Jun 2022 10:49:13 +0800 Subject: [PATCH 21/27] Update README.md --- README.md | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/README.md b/README.md index c3070f64..b02aea8d 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,4 @@ -<<<<<<< HEAD - test -======= -<<<<<<< Updated upstream -======= -<<<<<<< HEAD - test -======= ->>>>>>> Stashed changes -
- - 稀土掘金 - -
- -

JuejinHelper-稀土掘金助手

-<<<<<<< Updated upstream

签到、抽奖、沾喜气、海底掘金游戏、自动化工作流。

## 使用 @@ -95,16 +78,5 @@ DevTools截图: 这个项目的存在要感谢所有做出贡献的人。 请先阅读 [[Contribute](CONTRIBUTING.md)]。 您可以将任何想法作为 [拉取请求](https://github.com/iDerekLi/juejin-helper/pulls) 或 [GitHub问题](https://github.com/iDerekLi/juejin-helper/issues) 提交。 -## 赞赏 -### ☕️微信赞赏! ->>>>>>> Stashed changes -微信赞赏 -## 许可 -[MIT](./LICENSE) -<<<<<<< Updated upstream -======= ->>>>>>> upstream/main ->>>>>>> Stashed changes ->>>>>>> dev From f8432318b520f48ef51281fdccd1f8507cc01d2a Mon Sep 17 00:00:00 2001 From: dbl520 <2239146847@qq.com> Date: Thu, 18 Jul 2024 18:55:04 +0800 Subject: [PATCH 22/27] Update package.json --- package.json | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/package.json b/package.json index 4cfe3ba5..502710cf 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,7 @@ { "name": "juejin-helper", -<<<<<<< HEAD - "version": "1.4.0", -======= -<<<<<<< Updated upstream - "version": "1.0.0", ->>>>>>> dev - "description": "稀土掘金助手:签到、抽奖、沾喜气、海底淘金、自动化工作流。", -======= "version": "1.5.1", "description": "稀土掘金助手:签到、抽奖、沾喜气、消除Bug、海底掘金游戏、自动化工作流。", ->>>>>>> Stashed changes "author": "Derek Li", "license": "MIT", "scripts": { @@ -20,16 +11,10 @@ }, "dependencies": { "fast-astar": "^1.0.6", -<<<<<<< HEAD "juejin-helper": "^0.1.4", -======= -<<<<<<< Updated upstream "jsonwebtoken": "^8.5.1", "node-fetch": "^2.6.1", -======= "juejin-helper": "^1.5.1", ->>>>>>> Stashed changes ->>>>>>> dev "nodemailer": "^6.7.0" }, "repository": { From 637b5a9959f79591c41a64c2553ebfe18ae55e46 Mon Sep 17 00:00:00 2001 From: dbl520 <2239146847@qq.com> Date: Thu, 18 Jul 2024 20:50:15 +0800 Subject: [PATCH 23/27] merge code --- scripts/checkin.js | 271 +---------------------------- scripts/seaGold.js | 412 +-------------------------------------------- 2 files changed, 5 insertions(+), 678 deletions(-) diff --git a/scripts/checkin.js b/scripts/checkin.js index 7b31132b..52e21ff7 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -1,6 +1,5 @@ const JuejinHelper = require("juejin-helper"); const utils = require("./utils/utils"); -<<<<<<< Updated upstream const email = require("./utils/email"); const env = require("./utils/env"); @@ -34,80 +33,6 @@ class CheckIn { throw new Error("登录失败, 请尝试更新Cookies!"); } -<<<<<<< HEAD -======= -async function run(args) { - const state = { - simulateSpeed: 100, // ms/进行一次抽奖 - sumPoint: 0, - pointCost: 0, - supplyPoint: 0, - freeCount: 0, - luckyValue: 0, - lottery: [], - counter: 0, - prize: {} - }; - - await utils.wait(100); - console.clear(); - - try { - const checkInResult = await api.checkIn(); - const incrPoint = checkInResult.incr_point; - console.log(`签到成功 +${incrPoint} 矿石`); - - const sumPoint = checkInResult.sum_point; - state.sumPoint = sumPoint; - } catch (e) { - console.log(e.message); - - const sumPoint = await api.getCurrentPoint(); - state.sumPoint = sumPoint; - } -======= -const pushMessage = require("./utils/pushMessage"); -const env = require("./utils/env"); - -class CheckIn { - username = ""; - cookie = ""; - todayStatus = 0; // 未签到 - incrPoint = 0; - sumPoint = 0; // 当前矿石数 - contCount = 0; // 连续签到天数 - sumCount = 0; // 累计签到天数 - dipStatus = 0; - dipValue = 0; // 沾喜气 - luckyValue = 0; - lottery = []; // 奖池 - pointCost = 0; // 一次抽奖消耗 - freeCount = 0; // 免费抽奖次数 - drawLotteryHistory = {}; - lotteryCount = 0; - luckyValueProbability = 0; - bugStatus = 0; - collectBugCount = 0; - userOwnBug = 0; - - calledSdkSetting = false; - calledTrackGrowthEvent = false; - calledTrackOnloadEvent = false; - - constructor(cookie) { - this.cookie = cookie; - } - - async run() { - const juejin = new JuejinHelper(); - try { - await juejin.login(this.cookie); - } catch (e) { - console.error(e); - throw new Error("登录失败, 请尝试更新Cookies!"); - } - ->>>>>>> dev this.username = juejin.getUser().user_name; const growth = juejin.growth(); @@ -117,11 +42,7 @@ class CheckIn { const checkInResult = await growth.checkIn(); this.incrPoint = checkInResult.incr_point; -<<<<<<< HEAD this.sumPoint = checkInResult.sum_point; -======= - this.sumPoint = checkInResult.sum_point; ->>>>>>> dev this.todayStatus = 1; // 本次签到 } else { this.todayStatus = 2; // 已签到 @@ -130,10 +51,6 @@ class CheckIn { const counts = await growth.getCounts(); this.contCount = counts.cont_count; this.sumCount = counts.sum_count; -<<<<<<< HEAD -======= ->>>>>>> Stashed changes ->>>>>>> dev const luckyusersResult = await growth.getLotteriesLuckyUsers(); if (luckyusersResult.count > 0) { @@ -146,7 +63,6 @@ class CheckIn { this.dipValue = dipLuckyResult.dip_value; } } -<<<<<<< HEAD const luckyResult = await growth.getMyLucky(); this.luckyValue = luckyResult.total_value; @@ -165,30 +81,6 @@ class CheckIn { freeCount--; this.lotteryCount++; await utils.wait(utils.randomRangeNumber(300, 1000)); -======= -<<<<<<< Updated upstream - } catch {} - - console.log(`当前余额:${state.sumPoint} 矿石`); - - const luckyResult = await api.getMyLucky(); - state.luckyValue = luckyResult.total_value; - console.log(`当前幸运值:${state.luckyValue}/6000`); - - const lotteryConfig = await api.getLotteryConfig(); - state.lottery = lotteryConfig.lottery; - state.pointCost = lotteryConfig.point_cost; - state.freeCount = lotteryConfig.free_count; - state.sumPoint += state.freeCount * state.pointCost; - - const getProbabilityOfWinning = sumPoint => { - const pointCost = state.pointCost; - const luckyValueCost = 10; - const totalDrawsNumber = sumPoint / pointCost; - let supplyPoint = 0; - for(let i = 0, length = Math.floor(totalDrawsNumber * 0.65); i < length; i++) { - supplyPoint += Math.ceil(Math.random() * 100) ->>>>>>> dev } this.sumPoint = await growth.getCurrentPoint(); @@ -204,94 +96,11 @@ class CheckIn { const luckyValue = (sumPoint + supplyPoint) / pointCost * luckyValueCost + this.luckyValue; return luckyValue / 6000; } -<<<<<<< HEAD -======= - return 0; - }; - - const lottery = async () => { - const result = await api.drawLottery(); - state.sumPoint -= state.pointCost; - state.sumPoint += getSupplyPoint(result); - state.luckyValue += result.draw_lucky_value; - state.counter++; - state.prize[result.lottery_name] = (state.prize[result.lottery_name] || 0) + 1; - console.log(`[第${state.counter}抽]:${result.lottery_name}`); - }; - - while (state.freeCount > 0) { - await lottery(); - state.freeCount--; - await utils.wait(state.simulateSpeed); - } -======= - - const luckyResult = await growth.getMyLucky(); - this.luckyValue = luckyResult.total_value; - - const lotteryConfig = await growth.getLotteryConfig(); - this.lottery = lotteryConfig.lottery; - this.pointCost = lotteryConfig.point_cost; - this.freeCount = lotteryConfig.free_count; - this.lotteryCount = 0; - - let freeCount = this.freeCount; - while (freeCount > 0) { - const result = await growth.drawLottery(); - this.drawLotteryHistory[result.lottery_id] = - (this.drawLotteryHistory[result.lottery_id] || 0) + 1; - this.luckyValue = result.total_lucky_value; - freeCount--; - this.lotteryCount++; - await utils.wait(utils.randomRangeNumber(300, 1000)); - } - - this.sumPoint = await growth.getCurrentPoint(); - - const getProbabilityOfWinning = (sumPoint) => { - const pointCost = this.pointCost; - const luckyValueCost = 10; - const totalDrawsNumber = sumPoint / pointCost; - let supplyPoint = 0; - for (let i = 0, length = Math.floor(totalDrawsNumber * 0.65); i < length; i++) { - supplyPoint += Math.ceil(Math.random() * 100); - } - const luckyValue = ((sumPoint + supplyPoint) / pointCost) * luckyValueCost + this.luckyValue; - return luckyValue / 6000; - }; ->>>>>>> Stashed changes ->>>>>>> dev this.luckyValueProbability = getProbabilityOfWinning(this.sumPoint); -<<<<<<< HEAD - // 调用埋点 - const sdk = juejin.sdk(); -======= -<<<<<<< Updated upstream - console.log(`当前余额:${state.sumPoint} 矿石`); -======= - // 收集bug - const bugfix = juejin.bugfix(); - - const competition = await bugfix.getCompetition(); - const bugfixInfo = await bugfix.getUser(competition); - this.userOwnBug = bugfixInfo.user_own_bug; - - try { - const notCollectBugList = await bugfix.getNotCollectBugList(); - await bugfix.collectBugBatch(notCollectBugList); - this.bugStatus = 1; - this.collectBugCount = notCollectBugList.length; - this.userOwnBug += this.collectBugCount; - } catch (e) { - this.bugStatus = 2; - } - // 调用埋点 const sdk = juejin.sdk(); ->>>>>>> Stashed changes ->>>>>>> dev try { await sdk.slardarSDKSetting(); @@ -330,7 +139,6 @@ class CheckIn { await juejin.logout(); } -<<<<<<< HEAD toString() { const drawLotteryHistory = Object.entries(this.drawLotteryHistory).map(([lottery_id, count]) => { @@ -366,91 +174,18 @@ async function run(args) { const content = checkin.toString(); console.log(content); // 打印结果 -======= -<<<<<<< Updated upstream - recordInfo.push("+++++++++++++++++++"); - recordInfo.push(`幸运值: ${state.luckyValue}/6000`); - recordInfo.push("==================="); - console.log(recordInfo.join("\n ")); ->>>>>>> dev email({ subject: "掘金每日签到", text: content }); -======= - - toString() { - const drawLotteryHistory = Object.entries(this.drawLotteryHistory) - .map(([lottery_id, count]) => { - const lotteryItem = this.lottery.find((item) => item.lottery_id === lottery_id); - if (lotteryItem) { - return `${lotteryItem.lottery_name}: ${count}`; - } - return `${lottery_id}: ${count}`; - }) - .join("\n"); - - return ` -掘友: ${this.username} -${ - this.todayStatus === 1 - ? `签到成功 +${this.incrPoint} 矿石` - : this.todayStatus === 2 - ? "今日已完成签到" - : "签到失败" -} -${ - this.dipStatus === 1 - ? `沾喜气 +${this.dipValue} 幸运值` - : this.dipStatus === 2 - ? "今日已经沾过喜气" - : "沾喜气失败" -} -${ - this.bugStatus === 1 - ? this.collectBugCount > 0 - ? `收集Bug +${this.collectBugCount}` - : "没有可收集Bug" - : "收集Bug失败" -} -连续签到天数 ${this.contCount} -累计签到天数 ${this.sumCount} -当前矿石数 ${this.sumPoint} -当前未消除Bug数量 ${this.userOwnBug} -当前幸运值 ${this.luckyValue}/6000 -预测All In矿石累计幸运值比率 ${(this.luckyValueProbability * 100).toFixed(2) + "%"} -抽奖总次数 ${this.lotteryCount} -免费抽奖次数 ${this.freeCount} -${this.lotteryCount > 0 ? "==============\n" + drawLotteryHistory + "\n==============" : ""} -`.trim(); - } } -async function run(args) { - const cookies = utils.getUsersCookie(env); - for (let cookie of cookies) { - const checkin = new CheckIn(cookie); - - await utils.wait(utils.randomRangeNumber(1000, 5000)); // 初始等待1-5s - await checkin.run(); // 执行 - - const content = checkin.toString(); - console.log(content); // 打印结果 - - pushMessage({ - subject: "掘金每日签到", - text: content - }); - } ->>>>>>> Stashed changes -} - -run(process.argv.splice(2)).catch((error) => { - pushMessage({ +run(process.argv.splice(2)).catch(error => { + email({ subject: "掘金每日签到", html: `Error
${error.message}
` }); throw error; -}); +}); \ No newline at end of file diff --git a/scripts/seaGold.js b/scripts/seaGold.js index cdbe936d..bbfb696a 100644 --- a/scripts/seaGold.js +++ b/scripts/seaGold.js @@ -1,19 +1,11 @@ const JuejinHelper = require("juejin-helper"); const utils = require("./utils/utils"); -<<<<<<< Updated upstream const { Grid, Astar } = require("fast-astar"); const email = require("./utils/email"); -<<<<<<< HEAD -======= -======= -const {Grid, Astar} = require("fast-astar"); -const pushMessage = require("./utils/pushMessage"); ->>>>>>> dev const env = require("./utils/env"); class SeaGold { gameApi = null; -<<<<<<< HEAD nodeRules = [ { code: 0, hasBounty: false, isWall: false, name: "空地" }, @@ -28,27 +20,6 @@ class SeaGold { { code: 13, hasBounty: true, isWall: false, name: "右指令" }, { code: 14, hasBounty: true, isWall: false, name: "跳跃指令" }, { code: 15, hasBounty: true, isWall: false, name: "循环指令" } -======= - cookie = ""; - - constructor(cookie) { - this.cookie = cookie; - } - - nodeRules = [ - {code: 0, hasBounty: false, isWall: false, name: "空地"}, - {code: 2, hasBounty: true, isWall: false, name: "矿石", isBest: true}, - {code: 3, hasBounty: false, isWall: false, name: "星星"}, - {code: 4, hasBounty: false, isWall: true, name: "贝壳"}, - {code: 5, hasBounty: false, isWall: true, name: "水母"}, - {code: 6, hasBounty: false, isWall: true, name: "石头"}, - {code: 10, hasBounty: true, isWall: false, name: "上指令"}, - {code: 11, hasBounty: true, isWall: false, name: "下指令"}, - {code: 12, hasBounty: true, isWall: false, name: "左指令"}, - {code: 13, hasBounty: true, isWall: false, name: "右指令"}, - {code: 14, hasBounty: true, isWall: false, name: "跳跃指令"}, - {code: 15, hasBounty: true, isWall: false, name: "循环指令"} ->>>>>>> dev ]; debug = false; @@ -63,11 +34,7 @@ class SeaGold { gameInfo = { gameId: "", mapData: [], -<<<<<<< HEAD curPos: { x: 0, y: 0 }, -======= - curPos: {x: 0, y: 0}, ->>>>>>> dev blockData: { moveUp: 0, moveDown: 0, @@ -84,16 +51,12 @@ class SeaGold { get isGaming() { return this.gameInfo && this.gameInfo.gameId !== ""; } -<<<<<<< HEAD -======= ->>>>>>> Stashed changes ->>>>>>> dev resetGame() { this.gameInfo = { gameId: "", mapData: [], - curPos: {x: 0, y: 0}, + curPos: { x: 0, y: 0 }, blockData: { moveUp: 0, moveDown: 0, @@ -106,7 +69,6 @@ class SeaGold { }; } -<<<<<<< HEAD restoreGame(gameInfo) { this.gameInfo = { gameId: gameInfo.gameId, @@ -114,56 +76,13 @@ class SeaGold { curPos: gameInfo.curPos, blockData: gameInfo.blockData, gameDiamond: gameInfo.gameDiamond -======= -<<<<<<< Updated upstream - get isGaming() { - return this.gameInfo && this.gameInfo.gameId !== ""; ->>>>>>> dev } } -<<<<<<< HEAD async gameStart() { if (this.isGaming) return; const roleId = Math.ceil(Math.random() * 3); const gameInfo = await this.gameApi.gameStart({ roleId }); -======= - async init() { - const loginInfo = await juejinGameApi.gameLogin(); - if (!loginInfo.isAuth) { - throw Error("玩家未授权, 请前往掘金授权!"); - } - console.log(`玩家: ${loginInfo.name}`); - const info = await juejinGameApi.gameInfo(); - this.userInfo = { - uid: info.userInfo.uid, - name: info.userInfo.name, - todayDiamond: info.userInfo.todayDiamond, - todayLimitDiamond: info.userInfo.todayLimitDiamond, - maxTodayDiamond: info.userInfo.maxTodayDiamond - }; - if (info.gameStatus === 1) { - this.restoreGame(info.gameInfo); - } else { - this.resetGame(); - } - } -======= - restoreGame(gameInfo) { - this.gameInfo = { - gameId: gameInfo.gameId, - mapData: this.makeMap(gameInfo.mapData, 6), - curPos: gameInfo.curPos, - blockData: gameInfo.blockData, - gameDiamond: gameInfo.gameDiamond - }; - } - - async gameStart() { - if (this.isGaming) return; - const roleId = Math.ceil(Math.random() * 3); - const gameInfo = await this.gameApi.gameStart({roleId}); ->>>>>>> dev this.gameInfo = { roleId, @@ -174,10 +93,6 @@ class SeaGold { gameDiamond: 0 }; } -<<<<<<< HEAD -======= ->>>>>>> Stashed changes ->>>>>>> dev async gameOver() { if (!this.isGaming) return; @@ -198,47 +113,14 @@ class SeaGold { return gameOverInfo; } -<<<<<<< HEAD -======= -<<<<<<< Updated upstream - async executeGameCommand() { - const bmmap = this.getBMMap(); - const curNode = this.getNode(this.gameInfo.curPos); - const bestNode = this.getBestNode(bmmap); - const path = this.getRoutePath(bmmap, curNode, bestNode); - const commands = this.getCommands(path); - if (commands.length <= 0) { - console.log("当局游戏资源耗尽"); - return false; - } - const gameCommandInfo = await juejinGameApi.gameCommand(this.gameInfo.gameId, commands); - this.gameInfo.curPos = gameCommandInfo.curPos; - this.gameInfo.blockData = gameCommandInfo.blockData; - this.gameInfo.gameDiamond = gameCommandInfo.gameDiamond; - console.log(`curPos(${this.gameInfo.curPos.x},${this.gameInfo.curPos.y}): ${this.gameInfo.gameDiamond} 矿石`); - return true; -======= ->>>>>>> dev async executeGameCommand() { const bmmap = this.getBMMap(); const curNode = this.getNode(this.gameInfo.curPos); const bestNode = this.getBestNode(bmmap); const path = this.getRoutePath(bmmap, curNode, bestNode); -<<<<<<< HEAD - const commands = this.getCommands(path); - if (commands.length <= 0) { - return false; -======= - if (!Array.isArray(path)) { - throw new Error( - `路径 ${JSON.stringify(path)} 无法在地图 ${JSON.stringify(this.getMaze(bmmap))} 行进.` - ); - } const commands = this.getCommands(path); if (commands.length <= 0) { return false; ->>>>>>> Stashed changes ->>>>>>> dev } const gameCommandInfo = await this.gameApi.gameCommand(this.gameInfo.gameId, commands); this.gameInfo.curPos = gameCommandInfo.curPos; @@ -260,112 +142,44 @@ class SeaGold { return sx > ex ? "L" : "R"; } -<<<<<<< HEAD -======= -<<<<<<< Updated upstream - getCommands(path) { - const commands = []; - for(let i=0; i${i+1}`); - } - commands.push(cmd); -======= ->>>>>>> dev return null; } getCommands(path) { const commands = []; -<<<<<<< HEAD for(let i=0; i${i+1}`); -======= - for (let i = 0; i < path.length - 1; i++) { - const cmd = this.getCommand(path[i], path[i + 1]); - if (!cmd) { - throw new Error(`路径错误: ${i}->${i + 1}`); ->>>>>>> Stashed changes ->>>>>>> dev } commands.push(cmd); } return commands; } -<<<<<<< HEAD -======= -<<<<<<< Updated upstream - getNodePosition(map, node) { - for (let y = 0; y < map.length; y++) { - const list = map[y]; - for (let x = 0; x < list.length; x++) { - const cNode = list[x]; - if (cNode === node) { - return { x, y }; - } -======= ->>>>>>> dev getNodePosition(map, node) { for (let y = 0; y < map.length; y++) { const list = map[y]; for (let x = 0; x < list.length; x++) { const cNode = list[x]; if (cNode === node) { -<<<<<<< HEAD return { x, y }; -======= - return {x, y}; ->>>>>>> Stashed changes ->>>>>>> dev } } } -<<<<<<< HEAD return { x: 0, y: 0 }; } -======= -<<<<<<< Updated upstream -======= - return {x: 0, y: 0}; - } - - getRoutePath(map, startNode, endNode) { - const maze = this.generateMapMaze(map); - const startPos = this.getNodePosition(map, startNode); - const endPos = this.getNodePosition(map, endNode); ->>>>>>> Stashed changes ->>>>>>> dev getRoutePath(map, startNode, endNode) { const maze = this.generateMapMaze(map); const startPos = this.getNodePosition(map, startNode); const endPos = this.getNodePosition(map, endNode); -<<<<<<< HEAD if (this.debug) { console.log("地图", this.getMaze(map)); console.log("开始位置", startPos); console.log("结束位置", endPos); } -======= -<<<<<<< Updated upstream - if (this.debug) { - console.log("地图", this.getMaze(map)); - console.log("开始位置", startPos); - console.log("结束位置", endPos); - } -======= - const astar = new Astar(maze); - const path = astar.search([startPos.x, startPos.y], [endPos.x, endPos.y], { - rightAngle: true, - optimalResult: true - }); ->>>>>>> Stashed changes ->>>>>>> dev const astar = new Astar(maze); const path = astar.search( @@ -377,7 +191,6 @@ class SeaGold { } ); -<<<<<<< HEAD return path; } @@ -389,51 +202,11 @@ class SeaGold { for (let x = 0; x < grid; x++) { const cell = mapData[i + x]; row.push(this.createMapNode(x, y, cell)); -======= -<<<<<<< Updated upstream - return path; -======= - makeMap(mapData, grid = 6) { - const map = []; - for (let i = 0, y = 0; i < mapData.length; i += grid, y++) { - const row = []; - map.push(row); - for (let x = 0; x < grid; x++) { - const cell = mapData[i + x]; - row.push(this.createMapNode(x, y, cell)); - } ->>>>>>> Stashed changes - } - -<<<<<<< Updated upstream - makeMap(mapData, grid = 6) { - const map = []; - for (let i = 0, y = 0; i < mapData.length; i+=grid, y++) { - const row = []; - map.push(row); - for (let x = 0; x < grid; x++) { - const cell = mapData[i + x]; - row.push(this.createMapNode(x, y, cell)); - } ->>>>>>> dev } } return map; } -<<<<<<< HEAD -======= - createMapNode(x, y, secret) { - const rule = this.getNodeRule(secret); - return { - code: rule.code, - bounty: rule.hasBounty ? this.getBounty(secret, rule.code) : 0, - x, - y, - isWall: rule.isWall, - isBest: !!rule.isBest -======= ->>>>>>> dev createMapNode(x, y, secret) { const rule = this.getNodeRule(secret); return { @@ -443,28 +216,6 @@ class SeaGold { y, isWall: rule.isWall, isBest: !!rule.isBest -<<<<<<< HEAD -======= - }; - } - - // 获取范围地图 - getBMMap() { - const {mapData, blockData, curPos} = this.gameInfo; - const minX = Math.max(curPos.x - blockData.moveLeft, 0); - const maxX = Math.min(curPos.x + blockData.moveRight, mapData[0].length - 1); - const minY = Math.max(curPos.y - blockData.moveUp, 0); - const maxY = Math.min(curPos.y + blockData.moveDown, mapData.length - 1); - - const map = []; - for (let y = minY; y <= maxY; y++) { - const row = []; - map.push(row); - for (let x = minX; x <= maxX; x++) { - row.push(mapData[y][x]); ->>>>>>> Stashed changes - } ->>>>>>> dev } } @@ -484,36 +235,13 @@ class SeaGold { } } -<<<<<<< HEAD return map; } -======= -<<<<<<< Updated upstream - getNode(pos) { - return this.gameInfo.mapData[pos.y][pos.x]; - } -======= - getBestNode(map) { - let bestNode = null; - map.forEach((row) => { - row.forEach((node) => { - if (node.isBest && bestNode === null) { - bestNode = node; - } else if (node.isBest && node.bounty > bestNode.bounty) { - bestNode = node; - } - }); - }); - return bestNode; - } ->>>>>>> Stashed changes ->>>>>>> dev getNode(pos) { return this.gameInfo.mapData[pos.y][pos.x]; } -<<<<<<< HEAD getBestNode(map) { let bestNode = null; map.forEach(row => { @@ -523,32 +251,6 @@ class SeaGold { } else if (node.isBest && node.bounty > bestNode.bounty) { bestNode = node; } -======= -<<<<<<< Updated upstream - getMaze(map) { - return map.map((row, y) => { - return row.map((node, x) => { - if (node.isWall) { - return 1; - } else { - return 0; - } - }); -======= - // 生成迷宫 - generateMapMaze(map) { - const grid = new Grid({ - col: map[0].length, - row: map.length - }); - - map.forEach((row, y) => { - row.forEach((node, x) => { - if (node.isWall) { - grid.set([x, y], "value", 1); - } ->>>>>>> Stashed changes ->>>>>>> dev }); }); return bestNode; @@ -566,7 +268,6 @@ class SeaGold { }); } -<<<<<<< HEAD // 生成迷宫 generateMapMaze(map) { const grid = new Grid({ @@ -581,54 +282,16 @@ class SeaGold { } }); }); -======= -<<<<<<< Updated upstream - map.forEach((row, y) => { - row.forEach((node, x) => { - if (node.isWall) { - grid.set([x, y], 'value', 1); - } - }); - }); -======= - getNodeRule(secret) { - return this.nodeRules.find((rule) => { - const reg = new RegExp(`^${rule.code}`); - return reg.test(secret); - }); - } ->>>>>>> Stashed changes ->>>>>>> dev return grid; } -<<<<<<< HEAD getNodeRule(secret) { return this.nodeRules.find(rule => { const reg = new RegExp(`^${rule.code}`); return reg.test(secret); }); } -======= -<<<<<<< Updated upstream - getNodeRule(secret) { - return this.nodeRules.find(rule => { - const reg = new RegExp(`^${rule.code}`); - return reg.test(secret); - }); -======= - async run() { - const juejin = new JuejinHelper(); - await juejin.login(this.cookie); - this.gameApi = juejin.seagold(); - - const loginInfo = await this.gameApi.gameLogin(); - if (!loginInfo.isAuth) { - throw Error(`掘友 ${loginInfo.name} 未授权, 请前往掘金授权!`); ->>>>>>> Stashed changes - } ->>>>>>> dev getBounty(secret, key) { const reg = new RegExp(`^${key}([0-9]*)`); @@ -679,30 +342,10 @@ class SeaGold { runTime = new Date(); } -<<<<<<< HEAD return await this.gameOver(); } -======= -<<<<<<< Updated upstream - return await seaGold.gameOver(); - } catch (e) { - await seaGold.gameOver(); - throw e; - } - } - console.log(`今日开采限制: ${seaGold.userInfo.todayLimitDiamond} 矿石`); - if (seaGold.userInfo.todayDiamond >= seaGold.userInfo.todayLimitDiamond) { - console.log(`今日开采已达上限!`); - } else { -======= - - return await this.gameOver(); - }; - ->>>>>>> Stashed changes ->>>>>>> dev const maxZeroCount = 5; let zeroCount = 0; @@ -732,7 +375,6 @@ class SeaGold { runTime = new Date(); } -<<<<<<< HEAD await juejin.logout(); } @@ -746,12 +388,6 @@ class SeaGold { ${userInfo.todayDiamond < userInfo.todayLimitDiamond ? `今日获取矿石数 ${userInfo.todayDiamond}` : "今日获取已达上限"} ${this.history.length ? `\n游戏记录\n${gameLives}` : ""} `.trim(); -======= -<<<<<<< Updated upstream - if (seaGold.userInfo.todayDiamond >= seaGold.userInfo.todayLimitDiamond) { - console.log(`今日开采已达上限!`); - } ->>>>>>> dev } } @@ -774,50 +410,6 @@ async function run(args) { run(process.argv.splice(2)).catch(error => { email({ -======= - await juejin.logout(); - } - - toString() { - const userInfo = this.userInfo; - const gameLives = this.history - .map((game) => `${game.gameId}\n 挖取 ${game.gameDiamond}\n 获得 ${game.realDiamond}`) - .join("\n"); - - return ` -掘友: ${userInfo.name} -今日限制矿石数 ${userInfo.todayLimitDiamond} -${ - userInfo.todayDiamond < userInfo.todayLimitDiamond - ? `今日获取矿石数 ${userInfo.todayDiamond}` - : "今日获取已达上限" -} -${this.history.length ? `\n游戏记录\n${gameLives}` : ""} -`.trim(); - } -} - -async function run(args) { - const cookies = utils.getUsersCookie(env); - for (let cookie of cookies) { - const seaGold = new SeaGold(cookie); - - await utils.wait(utils.randomRangeNumber(1000, 5000)); // 初始等待1-5s - await seaGold.run(); - - const content = seaGold.toString(); - console.log(content); - - pushMessage({ - subject: "海底掘金游戏", - text: content - }); - } -} - -run(process.argv.splice(2)).catch((error) => { - pushMessage({ ->>>>>>> Stashed changes subject: "海底掘金游戏", html: ` Error @@ -827,4 +419,4 @@ run(process.argv.splice(2)).catch((error) => { }); throw error; -}); +}); \ No newline at end of file From be76c828b88bcd0ddd7579b08cadbacaf2ac7c66 Mon Sep 17 00:00:00 2001 From: dbl520 <2239146847@qq.com> Date: Thu, 18 Jul 2024 21:32:11 +0800 Subject: [PATCH 24/27] feat --- yarn.lock | 160 ------------------------------------------------------ 1 file changed, 160 deletions(-) delete mode 100644 yarn.lock diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index 9dadb510..00000000 --- a/yarn.lock +++ /dev/null @@ -1,160 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -buffer-equal-constant-time@1.0.1: - version "1.0.1" - resolved "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819" - integrity sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk= - -ecdsa-sig-formatter@1.0.11: - version "1.0.11" - resolved "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz#ae0f0fa2d85045ef14a817daa3ce9acd0489e5bf" - integrity sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ== - dependencies: - safe-buffer "^5.0.1" - -fast-astar@^1.0.6: - version "1.0.6" - resolved "https://registry.npmjs.org/fast-astar/-/fast-astar-1.0.6.tgz#e4cae258839bc6406c49df1eaa80077eda74723c" - integrity sha512-r23aD+DIl2Y/XdhP/Z3kDyi9dJ4BID6z49gjc+lQo1fLBqi9uEkaevcX4v0bqHGxjwc7GKbt/OPRM/UwTCfiEw== - -jsonwebtoken@^8.5.1: - version "8.5.1" - resolved "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d" - integrity sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w== - dependencies: - 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" - -<<<<<<< HEAD -juejin-helper@^0.1.4: - version "0.1.4" - resolved "https://registry.npmmirror.com/juejin-helper/-/juejin-helper-0.1.4.tgz#921933b63cd21276dfd928f953a80fe87b454d45" - integrity sha512-14xMEhYgT+RhtmU13IJfMAeZwGwKwSzr+VjO5tCLtxP/MfrpEzSvmEOCKVRwITfJ3e2+NQyU//i+6jFVL9+9/Q== -======= -<<<<<<< Updated upstream -======= -juejin-helper@^1.5.1: - version "1.5.1" - resolved "https://registry.npmmirror.com/juejin-helper/-/juejin-helper-1.5.1.tgz#416dd622e18daa03fd5ab68f2fb74ec522ce4e8f" - integrity sha512-CoC4D0hph59eodM2aO7Brj8hURvFuI8PvrSgZQzyjQ/5BqYK2+ewcMNXxhzYWvHZ4ENMFqfwzHbOU4OelfyJ6Q== ->>>>>>> dev - dependencies: - jsonwebtoken "^8.5.1" - node-fetch "^2.6.1" - uuid "^8.3.2" - -<<<<<<< HEAD -======= ->>>>>>> Stashed changes ->>>>>>> dev -jwa@^1.4.1: - version "1.4.1" - resolved "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz#743c32985cb9e98655530d53641b66c8645b039a" - integrity sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA== - dependencies: - buffer-equal-constant-time "1.0.1" - ecdsa-sig-formatter "1.0.11" - safe-buffer "^5.0.1" - -jws@^3.2.2: - version "3.2.2" - resolved "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz#001099f3639468c9414000e99995fa52fb478304" - integrity sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA== - dependencies: - jwa "^1.4.1" - safe-buffer "^5.0.1" - -lodash.includes@^4.3.0: - version "4.3.0" - resolved "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f" - integrity sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8= - -lodash.isboolean@^3.0.3: - version "3.0.3" - resolved "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6" - integrity sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY= - -lodash.isinteger@^4.0.4: - version "4.0.4" - resolved "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343" - integrity sha1-YZwK89A/iwTDH1iChAt3sRzWg0M= - -lodash.isnumber@^3.0.3: - version "3.0.3" - resolved "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc" - integrity sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w= - -lodash.isplainobject@^4.0.6: - version "4.0.6" - resolved "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" - integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs= - -lodash.isstring@^4.0.1: - version "4.0.1" - resolved "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" - integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE= - -lodash.once@^4.0.0: - version "4.1.1" - resolved "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac" - integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w= - -ms@^2.1.1: - version "2.1.3" - resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" - integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== - -node-fetch@^2.6.1: - version "2.6.7" - resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" - integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== - dependencies: - whatwg-url "^5.0.0" - -nodemailer@^6.7.0: - version "6.7.2" - resolved "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.2.tgz#44b2ad5f7ed71b7067f7a21c4fedabaec62b85e0" - integrity sha512-Dz7zVwlef4k5R71fdmxwR8Q39fiboGbu3xgswkzGwczUfjp873rVxt1O46+Fh0j1ORnAC6L9+heI8uUpO6DT7Q== - -safe-buffer@^5.0.1: - version "5.2.1" - resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" - integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== - -semver@^5.6.0: - version "5.7.1" - resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" - integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== - -tr46@~0.0.3: - version "0.0.3" - resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" - integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= - -uuid@^8.3.2: - version "8.3.2" - resolved "https://registry.npmmirror.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" - integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== - -webidl-conversions@^3.0.0: - version "3.0.1" - resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" - integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= - -whatwg-url@^5.0.0: - version "5.0.0" - resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" - integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0= - dependencies: - tr46 "~0.0.3" - webidl-conversions "^3.0.0" From dd295cb60a65eb86f4aef5f776961ee2f4c7e038 Mon Sep 17 00:00:00 2001 From: dbl520 <2239146847@qq.com> Date: Fri, 19 Jul 2024 09:33:03 +0800 Subject: [PATCH 25/27] Update checkin.js --- scripts/checkin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/checkin.js b/scripts/checkin.js index 52e21ff7..6f288307 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -30,6 +30,8 @@ class CheckIn { await juejin.login(env.COOKIE); } catch (e) { console.error(e); + console.error(env.COOKIE); + throw new Error("登录失败, 请尝试更新Cookies!"); } @@ -188,4 +190,4 @@ run(process.argv.splice(2)).catch(error => { }); throw error; -}); \ No newline at end of file +}); From 7dd7a9d817923e0a368b23a90414a2f831f85c45 Mon Sep 17 00:00:00 2001 From: dbl520 <2239146847@qq.com> Date: Fri, 19 Jul 2024 09:35:09 +0800 Subject: [PATCH 26/27] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 502710cf..5158a417 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "fast-astar": "^1.0.6", - "juejin-helper": "^0.1.4", + "juejin-helper": "^1.7.2", "jsonwebtoken": "^8.5.1", "node-fetch": "^2.6.1", "juejin-helper": "^1.5.1", From 5c51f154c8f308020ecd5c38f5a37c31c9f2cc39 Mon Sep 17 00:00:00 2001 From: dbl520 <2239146847@qq.com> Date: Fri, 19 Jul 2024 09:38:42 +0800 Subject: [PATCH 27/27] Update checkin.js --- scripts/checkin.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/checkin.js b/scripts/checkin.js index 6f288307..c751947a 100644 --- a/scripts/checkin.js +++ b/scripts/checkin.js @@ -28,9 +28,10 @@ class CheckIn { const juejin = new JuejinHelper(); try { await juejin.login(env.COOKIE); + console.log(env.COOKIE); } catch (e) { console.error(e); - console.error(env.COOKIE); + throw new Error("登录失败, 请尝试更新Cookies!"); }