From 16eb585bc355e6726e12b04861e273e01fc3233f Mon Sep 17 00:00:00 2001 From: shanmite <1971513084@qq.com> Date: Wed, 7 Apr 2021 10:48:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0UIDs=E5=92=8CTAGs?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Monitor.js | 1 - lib/Script.js | 35 ++++++++++++++++++++++++++++++++++- lib/config.js | 3 ++- lib/lottery-in-nodejs.js | 9 +++++++-- main.js | 2 +- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/lib/Monitor.js b/lib/Monitor.js index 7c60f16..908a570 100644 --- a/lib/Monitor.js +++ b/lib/Monitor.js @@ -26,7 +26,6 @@ class Monitor extends Public { */ async init() { if (config.model === '00') { Base.tooltip.log('已关闭所有转发行为'); return; } - if (GlobalVar.Lottery.length === 0) { Base.tooltip.log('抽奖信息为空'); return; } this.tagid = await BiliAPI.checkMyPartition(); /* 检查关注分区 */ this.attentionList = await BiliAPI.getAttentionList(GlobalVar.myUID); /* 获取关注列表 */ await this.startLottery(); diff --git a/lib/Script.js b/lib/Script.js index ecded27..f72a83a 100644 --- a/lib/Script.js +++ b/lib/Script.js @@ -1,4 +1,4 @@ -module.exports = { +const default_script = { version: '|version: 3.8.2|in nodejs', author: '@shanmite', UIDs: [ @@ -16,3 +16,36 @@ module.exports = { '动态抽奖', ] }; + +/** + * 自己修改过的设置 + */ +const my_config = (() => { + let _my_config = {} + if (process.env.LOCALLAUNCH) { + try { + const { UIDs, TAGs } = require('../my_config.json'); + if (UIDs) _my_config.UIDs = UIDs; + if (TAGs) _my_config.TAGs = TAGs; + } catch (_) { + console.log("无自定义设置"); + } + } else { + try { + const { UIDs, TAGs } = JSON.parse(process.env.MY_CONFIG); + if (UIDs) _my_config.UIDs = UIDs; + if (TAGs) _my_config.TAGs = TAGs; + } catch (_) { + console.log("MY_CONFIG语法错误"); + } + } + return _my_config; +})(); + +const script = { + ...default_script, + ...my_config +} + + +module.exports = script; diff --git a/lib/config.js b/lib/config.js index c6d74be..78eb5e1 100644 --- a/lib/config.js +++ b/lib/config.js @@ -51,4 +51,5 @@ const config = { ...my_config }; -module.exports = config; + +module.exports = config; \ No newline at end of file diff --git a/lib/lottery-in-nodejs.js b/lib/lottery-in-nodejs.js index f481db2..4550f73 100644 --- a/lib/lottery-in-nodejs.js +++ b/lib/lottery-in-nodejs.js @@ -17,11 +17,11 @@ const MAX_TIME = 6 * 60 * 60 * 1000 - 6 * 60 * 1000; function start() { return new Promise(resolve => { function createRandomDynamic() { - return new Promise((resolve) => { + return new Promise((_resolve) => { if (config.create_dy === '1') { Public.prototype.checkAllDynamic(GlobalVar.myUID, 1).then(Dynamic => { if (Dynamic.allModifyDynamicResArray[0].type === 1) { - BiliAPI.createDynamic(Base.getRandomStr(config.dy_contents)).then(() => resolve()) + BiliAPI.createDynamic(Base.getRandomStr(config.dy_contents)).then(() => _resolve()) } }) } @@ -30,6 +30,11 @@ function start() { let times = Base.counter(); /* 注册事件 */ eventBus.on('Turn_on_the_Monitor', async () => { + if (GlobalVar.Lottery.length) { + Base.tooltip.log('抽奖信息为空'); + resolve(); + return; + } if (times.value() === GlobalVar.Lottery.length) { await createRandomDynamic(); Base.tooltip.log('所有动态转发完毕'); diff --git a/main.js b/main.js index 9f1ec6c..1f17a9d 100644 --- a/main.js +++ b/main.js @@ -31,6 +31,6 @@ const { NUMBER, CLEAR, COOKIE, PAT, LOCALLAUNCH } = process.env; default: break; } - process.exit(0) } + process.exit(0) }))();