mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
const utils = require('./utils');
|
|
const event_bus = require('./helper/event_bus');
|
|
const global_var = require('./data/global_var');
|
|
const { Searcher } = require('./core/searcher');
|
|
const { Monitor } = require('./core/monitor');
|
|
const config = require('./data/config');
|
|
const { randomDynamic } = require('./helper/randomDynamic');
|
|
const { log } = utils;
|
|
|
|
async function createRandomDynamic(num) {
|
|
if (config.create_dy) {
|
|
log.info('随机动态', `准备创建${num}条随机动态`);
|
|
const
|
|
{ allModifyDynamicResArray } = await Searcher.checkAllDynamic(global_var.get("myUID"), 1),
|
|
{ type, orig_type } = allModifyDynamicResArray[0] || {};
|
|
if (type === 1 && orig_type !== 8) {
|
|
await randomDynamic(num)
|
|
} else {
|
|
log.info('随机动态', '已有非抽奖动态故无需创建');
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 抽奖主函数
|
|
* @param {string} cookie
|
|
* @returns {Promise<void>}
|
|
*/
|
|
function start() {
|
|
return new Promise(resolve => {
|
|
let times = utils.counter();
|
|
/* 注册事件 */
|
|
event_bus.on('Turn_on_the_Monitor', async () => {
|
|
const lotterys = global_var.get("Lottery");
|
|
if (lotterys.length === 0) {
|
|
log.info('抽奖', '抽奖信息为空');
|
|
resolve();
|
|
return;
|
|
}
|
|
if (times.value() === lotterys.length) {
|
|
log.info('抽奖', '所有动态转发完毕');
|
|
times.clear();
|
|
event_bus.emit('Turn_off_the_Monitor', '目前无抽奖信息,过一会儿再来看看吧')
|
|
return;
|
|
}
|
|
const lottery = lotterys[times.next()];
|
|
|
|
await (new Monitor(lottery)).init();
|
|
});
|
|
event_bus.on('Turn_off_the_Monitor', async (msg) => {
|
|
await createRandomDynamic(config.create_dy_num);
|
|
log.info('结束抽奖', '原因: ' + msg);
|
|
event_bus.flush();
|
|
resolve();
|
|
})
|
|
event_bus.emit('Turn_on_the_Monitor');
|
|
});
|
|
}
|
|
|
|
|
|
module.exports = { start } |