Skip to content

Commit

Permalink
feat: 可间隔插入随机动态(#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanmiteko committed Oct 5, 2021
1 parent 88d3e97 commit d676a10
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
19 changes: 16 additions & 3 deletions lib/core/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -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) {
Expand Down
10 changes: 7 additions & 3 deletions my_config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d676a10

Please sign in to comment.