diff --git a/env.example.js b/env.example.js index 483b26a..25b5beb 100644 --- a/env.example.js +++ b/env.example.js @@ -8,7 +8,9 @@ * ## 账号相关参数 * - `COOKIE` 是必填项 * - `NUMBER` 表示是第几个账号 - * - `PAT` 与 `GITHUB_REPOSITORY` 如果之前在Github Action上运行过脚本, 可填写已下载转发过的动态dyid, 之后可移除 + * - `CLEAR` 是否启用清理功能 + * - `ENABLE_MULTIPLE_ACCOUNT` 是否启用多账号 + * - `MULTIPLE_ACCOUNT_PARM` 多账号参数(JSON格式) * * ## 多账号 * 1. 将 ENABLE_MULTIPLE_ACCOUNT 的值改为true @@ -21,10 +23,8 @@ const account_parm = { COOKIE: "", NUMBER: 1, CLEAR: true, - LOCALLAUNCH: true, - PAT: "", - GITHUB_REPOSITORY: "用户名/仓库名", - ENABLE_MULTIPLE_ACCOUNT: false + ENABLE_MULTIPLE_ACCOUNT: false, + MULTIPLE_ACCOUNT_PARM: "" } /** diff --git a/lib/config.js b/lib/config.js index b483474..5b60af5 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,14 +1,5 @@ -const { config_file, tooltip } = require('./Base'); - -const my_config = (() => { - let _my_config = {} - try { - _my_config = require(config_file) - } catch (e) { - tooltip.log("[config]自定义设置异常 原因如下:\n" + e); - } - return _my_config; -})(); +const { config_file } = require('./Base'); +const my_config = require(config_file); const config = { ...my_config["default_config"], diff --git a/lib/lottery-in-nodejs.js b/lib/lottery-in-nodejs.js index f7d9628..df56339 100644 --- a/lib/lottery-in-nodejs.js +++ b/lib/lottery-in-nodejs.js @@ -27,7 +27,7 @@ async function createRandomDynamic(num) { } /** - * 主函数 + * 抽奖主函数 * @param {string} cookie * @returns {Promise} */ diff --git a/main.js b/main.js index 3b36b79..398a3af 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,7 @@ const { env_file, tooltip, delay } = require("./lib/Base"); +const { loop_wait } = require("./lib/config"); +/**多账号存储 */ let multiple_account = []; if (!process.env.CI) { @@ -10,70 +12,64 @@ if (!process.env.CI) { initEnv() } +/** + * @returns {Promise} 错误信息 + */ 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 = multiple_account.length - ? multiple_account - : JSON.parse(MULTIPLE_ACCOUNT); + const { COOKIE, NUMBER, CLEAR, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT_PARM } = process.env; + if (ENABLE_MULTIPLE_ACCOUNT) { + let muti_acco = multiple_account.length + ? multiple_account + : JSON.parse(MULTIPLE_ACCOUNT_PARM); - process.env.ENABLE_MULTIPLE_ACCOUNT = ''; + process.env.ENABLE_MULTIPLE_ACCOUNT = ''; - for (const acco of muti_acco) { - process.env.COOKIE = acco.COOKIE; - process.env.NUMBER = acco.NUMBER; - process.env.CLEAR = acco.CLEAR; - await main(); - await delay(acco.WAIT); - } - } else { - 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)) { - const mode = process.env.lottery_mode; - const help_msg = "用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tclear 清理动态和关注\n"; - switch (mode) { - case 'start': - tooltip.log('开始参与抽奖'); - await start(); - break; - case 'check': - tooltip.log('检查是否中奖'); - await isMe(); - break; - case 'clear': - if (CLEAR) { - tooltip.log('开始清理动态'); - await clear(); - tooltip.log('清理动态完毕'); - } - break; - case 'help': - console.log(help_msg); - break; - case undefined: - console.log(`错误: 未提供以下参数\n\t[OPTIONS]\n`); - console.log(help_msg); - break - default: - console.log(`错误: 提供了错误的[OPTIONS] -> ${mode}\n`) - console.log(help_msg); - } - } - } else { - tooltip.log('请查看README文件, 在env.js指定位置填入cookie') - } + for (const acco of muti_acco) { + process.env.COOKIE = acco.COOKIE; + process.env.NUMBER = acco.NUMBER; + process.env.CLEAR = acco.CLEAR; + await main(); + await delay(acco.WAIT); } } else { - tooltip.log('请查看README文件, 填入相应的PAT, 若是本地运行则设LOCALLAUNCH为true'); + if (!COOKIE) { + return '请查看README文件, 在env.js指定位置填入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)) { + const mode = process.env.lottery_mode; + const help_msg = "用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tclear 清理动态和关注\n\thelp 帮助信息\n"; + switch (mode) { + case 'start': + tooltip.log('开始参与抽奖'); + await start(); + break; + case 'check': + tooltip.log('检查是否中奖'); + await isMe(); + break; + case 'clear': + if (CLEAR) { + tooltip.log('开始清理动态'); + await clear(); + tooltip.log('清理动态完毕'); + } + break; + case 'help': + return help_msg + case undefined: + return "错误: 未提供以下参数\n\t[OPTIONS]\n\n" + help_msg + default: + return `错误: 提供了错误的[OPTIONS] -> ${mode}\n\n` + help_msg + } + } } } @@ -92,8 +88,14 @@ async function main() { console.log(metainfo); /**OPTIONS */ process.env.lottery_mode = process.argv[2] - await main(); + const err_msg = await main(); + if (err_msg) { + console.log(err_msg); + } else { + tooltip.log(`休眠${loop_wait / 1000}秒后再次启动`) + await delay(loop_wait); + } tooltip.log('5秒后自动退出'); await delay(5 * 1000); - process.exit(0) + process.exit(0); })() \ No newline at end of file diff --git a/my_config.example.js b/my_config.example.js index 516e34a..c8063c3 100644 --- a/my_config.example.js +++ b/my_config.example.js @@ -63,12 +63,18 @@ module.exports = { */ maxday: Infinity, + /** + * - 整体循环等待时间(指所有转发完毕后的休眠时间) + * - 单位毫秒 + */ + loop_wait: 60 * 60 * 1000, + /** * - 转发间隔时间 * - 单位毫秒 * - 上下浮动50% */ - wait: 100000, + wait: 100 * 1000, /** * - 检索动态间隔 @@ -151,7 +157,8 @@ module.exports = { ], /** - * 抽奖UP用户分组id(网页端点击分区后地址栏中的tagid) + * - 抽奖UP用户分组id(网页端点击分区后地址栏中的tagid) + * - 自动获取 */ partition_id: 0, @@ -161,7 +168,8 @@ module.exports = { is_exception: false, /** - * 取关分区 + * - 取关分区 + * - 默认为: 此处存放因抽奖临时关注的up */ clear_partition: '',