mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
parent
a83c5ab91a
commit
9ab605a186
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@ node_modules/
|
||||
tests/
|
||||
dyids/
|
||||
lottery_info/
|
||||
lottery_dyids/
|
||||
dist/
|
||||
.env
|
||||
*.log
|
||||
|
||||
@ -26,7 +26,8 @@ class Monitor extends Searcher {
|
||||
['UIDs', this.getLotteryInfoByUID.bind(this)],
|
||||
['TAGs', this.getLotteryInfoByTag.bind(this)],
|
||||
['Articles', this.getLotteryInfoByArticle.bind(this)],
|
||||
['APIs', this.getLotteryInfoByAPI.bind(this)]
|
||||
['APIs', this.getLotteryInfoByAPI.bind(this)],
|
||||
['TxT', this.getLotteryInfoByTxT.bind(this)]
|
||||
]);
|
||||
}
|
||||
/**
|
||||
|
||||
@ -605,6 +605,71 @@ class Searcher {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 从本地文件中获取抽奖信息
|
||||
* @param {string} txt
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
async getLotteryInfoByTxT(txt) {
|
||||
log.info('获取动态', `开始获取${utils.lottery_dyids}`);
|
||||
const dyids = await utils.getLocalLotteryTxt(txt);
|
||||
let
|
||||
length = dyids.length,
|
||||
dyinfos = [];
|
||||
|
||||
for (const dyid of dyids) {
|
||||
if (typeof dyid === "string"
|
||||
&& dyid.length === utils.dyid_length) {
|
||||
|
||||
log.info('获取动态', `查看Txt中所提及动态(${dyid}) (${length--})`)
|
||||
const card = await bili.getOneDynamicByDyid(dyid)
|
||||
|
||||
if (card) {
|
||||
await utils.delay(get_dynamic_detail_wait)
|
||||
|
||||
const parsed_card = parseDynamicCard(card)
|
||||
, { is_liked } = parsed_card;
|
||||
|
||||
if (
|
||||
((!check_if_duplicated || check_if_duplicated >= 2)
|
||||
&& is_liked)
|
||||
|| ((check_if_duplicated >= 1)
|
||||
&& await d_storage.searchDyid(dyid))
|
||||
) {
|
||||
log.info('获取动态', `动态(${dyid})已转发过`)
|
||||
continue
|
||||
}
|
||||
|
||||
dyinfos.push(parsed_card);
|
||||
}
|
||||
} else {
|
||||
log.warn('获取动态', `动态(${dyid})无效 (${length--})`)
|
||||
}
|
||||
}
|
||||
const fomatdata = dyinfos.map(o => {
|
||||
return {
|
||||
lottery_info_type: 'txt',
|
||||
create_time: o.create_time,
|
||||
is_liked: o.is_liked,
|
||||
uids: [o.uid, o.origin_uid],
|
||||
uname: o.uname,
|
||||
ctrl: o.ctrl,
|
||||
dyid: o.dynamic_id,
|
||||
reserve_id: o.reserve_id,
|
||||
reserve_lottery_text: o.reserve_lottery_text,
|
||||
is_charge_lottery: o.is_charge_lottery,
|
||||
rid: o.rid_str,
|
||||
chat_type: o.chat_type,
|
||||
des: o.description,
|
||||
type: o.type,
|
||||
hasOfficialLottery: o.hasOfficialLottery
|
||||
};
|
||||
})
|
||||
log.info('获取动态', `成功获取txt信息`);
|
||||
|
||||
return fomatdata
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { Searcher, parseDynamicCard };
|
||||
|
||||
@ -47,12 +47,19 @@ const config = {
|
||||
*/
|
||||
APIs: [],
|
||||
|
||||
/**
|
||||
* lottery_dyids目录下抽奖动态文件名(如dyids.txt)
|
||||
* 一行一个dyids
|
||||
*/
|
||||
TxT: [],
|
||||
|
||||
/**
|
||||
* 抽奖参与顺序组合
|
||||
* * 0 - UIDs
|
||||
* * 1 - TAGs
|
||||
* * 2 - Articles
|
||||
* * 3 - APIs
|
||||
* * 4 - TxT
|
||||
* @example
|
||||
* [3,2,1,0]
|
||||
* [1,2,1,2,1]
|
||||
|
||||
@ -25,7 +25,9 @@ let global_var = {
|
||||
[0, "UIDs"],
|
||||
[1, "TAGs"],
|
||||
[2, "Articles"],
|
||||
[3, "APIs"]]);
|
||||
[3, "APIs"],
|
||||
[4, "TxT"],
|
||||
]);
|
||||
|
||||
config.updata(num);
|
||||
|
||||
|
||||
18
lib/utils.js
18
lib/utils.js
@ -17,6 +17,8 @@ const utils = {
|
||||
dyids_dir: path.join(process.cwd(), "dyids"),
|
||||
/**lottery_info存放目录 */
|
||||
lottery_info_dir: path.join(process.cwd(), "lottery_info"),
|
||||
/**本地抽奖信息存放目录 */
|
||||
lottery_dyids: path.join(process.cwd(), "lottery_dyids"),
|
||||
/**dyid长度 */
|
||||
dyid_length: 18,
|
||||
/**
|
||||
@ -482,6 +484,22 @@ const utils = {
|
||||
async clearLotteryInfo() {
|
||||
await utils.createDir(utils.lottery_info_dir);
|
||||
await utils.createFile(utils.lottery_info_dir, `lottery_info_${Number(process.env.NUMBER)}.json`, "{}", "w")
|
||||
},
|
||||
/**
|
||||
* 获取含抽奖dyids
|
||||
* @param {string} filename
|
||||
* @returns {Promise<Array<String>>}
|
||||
*/
|
||||
getLocalLotteryTxt(filename) {
|
||||
return new Promise((resolve) => {
|
||||
fs.readFile(path.join(utils.lottery_dyids, filename), (err, data) => {
|
||||
if (err) {
|
||||
resolve([])
|
||||
} else {
|
||||
resolve(data.toString("utf8").split(/[^0123456789]+/))
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -51,12 +51,19 @@ module.exports = Object.freeze({
|
||||
*/
|
||||
APIs: ["file://lottery_info_1.json"],
|
||||
|
||||
/**
|
||||
* lottery_dyids目录下抽奖动态文件名(如dyids.txt)
|
||||
* 一行一个dyids(非数字字符分割即可)
|
||||
*/
|
||||
TxT: ["dyids.txt"],
|
||||
|
||||
/**
|
||||
* 抽奖参与顺序组合
|
||||
* * 0 - UIDs
|
||||
* * 1 - TAGs
|
||||
* * 2 - Articles
|
||||
* * 3 - APIs
|
||||
* * 4 - TxT
|
||||
* @example
|
||||
* [3,2,1,0]
|
||||
* [1,2,1,2,1]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user