From d676a10e563c095966cc360114117a0ef585e07e Mon Sep 17 00:00:00 2001 From: shanmiteko Date: Tue, 5 Oct 2021 18:13:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=AF=E9=97=B4=E9=9A=94=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E9=9A=8F=E6=9C=BA=E5=8A=A8=E6=80=81(#33)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/monitor.js | 19 ++++++++++++++++--- my_config.example.js | 10 +++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/core/monitor.js b/lib/core/monitor.js index 812bd19f0..638b3b2da 100644 --- a/lib/core/monitor.js +++ b/lib/core/monitor.js @@ -81,14 +81,16 @@ class Monitor extends Searcher { */ async startLottery() { const allLottery = await this.filterLotteryInfo() - , len = allLottery.length; + , len = allLottery.length + , { dy_contents, create_dy, create_dy_mode, wait } = config; log.info('筛选动态', `筛选完毕(${len})`); if (len) { let is_exception = false; - for (const Lottery of utils.shuffle(allLottery)) { + for (const [index, Lottery] of utils.shuffle(allLottery).entries()) { let status = 0; + if (Lottery.isOfficialLottery) { let { ts } = await bili.getLotteryNotice(Lottery.dyid); const ts_10 = Date.now() / 1000; @@ -113,6 +115,17 @@ class Monitor extends Searcher { continue } } + + if (create_dy + && create_dy_mode instanceof Array + && index > 0 + && index % create_dy_mode[0] === 0) { + for (let i = 0; i < create_dy_mode[1]; i++) { + await bili.createDynamic(utils.getRandomOne(dy_contents)); + await utils.delay(2000); + } + } + status = await this.go(Lottery) switch (status) { case 0: @@ -124,7 +137,7 @@ class Monitor extends Searcher { return status } - await utils.delay(config.wait * (Math.random() + 0.5)); + await utils.delay(wait * (Math.random() + 0.5)); } log.info('抽奖', '开始转发下一组动态'); if (is_exception) { diff --git a/my_config.example.js b/my_config.example.js index 25b39123f..c20fbbf34 100644 --- a/my_config.example.js +++ b/my_config.example.js @@ -123,15 +123,19 @@ module.exports = Object.freeze({ create_dy: false, /** - * - 发送随机动态的数量 + * - 结束运行时发送随机动态的数量 */ create_dy_num: 1, /** - * - 随机动态内容 - * - 类型 `content[]` + * - 每转发x条抽奖动态就发送x条随机动态 + * - @example [6,1] 每转发6条抽奖动态就发送1条随机动态 */ + create_dy_mode: [0, 0], + /** + * - 随机动态内容 + * - 类型 `content[]` * @typedef Picture * @property {string} img_src 站内源 * @property {number} img_width