diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..05df379 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules/ +package-lock.json +lib/dyid*.txt +dyid.zip +env.js +my_config.json \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e27d889 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Latest Nodejs + Alpine Linux +FROM node:lts-alpine + +MAINTAINER shanmite@github.com + +LABEL version="0.1" description="自动参与B站动态抽奖" + +WORKDIR /lottery + +COPY ["package.json", "./"] + +RUN npm install + +CMD echo "Hello" \ No newline at end of file diff --git a/env.example.js b/env.example.js index 7e89cd9..58f1006 100644 --- a/env.example.js +++ b/env.example.js @@ -4,15 +4,16 @@ */ /** - * # 账号相关参数 + * ## 账号相关参数 * `COOKIE` 是必填项 * `NUMBER` 表示是第几个账号 * `PAT` 与 `GITHUB_REPOSITORY` 如果之前在Github Action上运行过脚本, 可填写已下载转发过的动态dyid, 之后可移除 * - * # 多账号 + * ## 多账号 * 将 ENABLE_MULTIPLE_ACCOUNT 的值改为true * 将账号信息依次填写于 MULTIPLE_ACCOUNT 中, 参考例子类推 * `WAIT` 表示下一个账号运行等待时间(毫秒) + * **按顺序依次执行, 防止访问频繁封禁IP** */ const account_parm = { COOKIE: "", @@ -22,6 +23,7 @@ const account_parm = { PAT: "", GITHUB_REPOSITORY: "用户名/仓库名", ENABLE_MULTIPLE_ACCOUNT: false, + /* 不推荐 */ MULTIPLE_ACCOUNT: JSON.stringify([ { COOKIE: "", @@ -38,6 +40,24 @@ const account_parm = { ]) } +/** + * 为防止环境变量过长, 请将多账号填在此处 + */ +const multiple_account_parm = [ + { + COOKIE: "", + NUMBER: 1, + CLEAR: true, + WAIT: 60 * 1000, + }, + // { + // COOKIE: "", + // NUMBER: 2, + // CLEAR: true, + // WAIT: 60 * 1000, + // }, +] + /** * 推送相关参数 */ @@ -77,4 +97,4 @@ function initEnv() { } -module.exports = { initEnv }; \ No newline at end of file +module.exports = { initEnv, multiple_account_parm }; \ No newline at end of file diff --git a/main.js b/main.js index 3372172..6c519bb 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,10 @@ const { tooltip, delay } = require("./lib/Base"); +let multiple_account = []; + if (!process.env.CI) { - const { initEnv } = require("./env"); + const { initEnv, multiple_account_parm } = require("./env"); + multiple_account = multiple_account_parm; initEnv() } @@ -9,8 +12,12 @@ async function main() { const { COOKIE, NUMBER, CLEAR, PAT, LOCALLAUNCH, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT } = process.env; if (LOCALLAUNCH || PAT) { if (ENABLE_MULTIPLE_ACCOUNT) { - let muti_acco = JSON.parse(MULTIPLE_ACCOUNT); + let muti_acco = multiple_account.length + ? multiple_account + : JSON.parse(MULTIPLE_ACCOUNT); + process.env.ENABLE_MULTIPLE_ACCOUNT = ''; + for (const acco of muti_acco) { process.env.COOKIE = acco.COOKIE; process.env.NUMBER = acco.NUMBER; @@ -22,9 +29,12 @@ async function main() { if (COOKIE) { const { setVariable } = require("./lib/setVariable"); await setVariable(COOKIE, Number(NUMBER)); + const { start, isMe, checkCookie } = require("./lib/lottery-in-nodejs"); const { clear } = require("./lib/clear"); + tooltip.log('[LotteryAutoScript] 账号' + NUMBER); + if (await checkCookie(NUMBER)) { switch (process.argv.slice(2)[0]) { case 'start':