mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
const { getRandomOne, createDir, createFile, dyids_dir } = require("../utils");
|
|
const config = require("../data/config");
|
|
|
|
let global_var = {
|
|
inner: {},
|
|
get(key) {
|
|
return this.inner[key]
|
|
},
|
|
set(key, value) {
|
|
this.inner[key] = value
|
|
},
|
|
/**
|
|
* 全局变量初始化
|
|
* 更新config
|
|
* @param {string} cookie
|
|
* @param {string} num
|
|
*/
|
|
async init(cookie, num) {
|
|
if (cookie) {
|
|
const
|
|
key_map = new Map([
|
|
['DedeUserID', 'myUID'],
|
|
['bili_jct', 'csrf']]),
|
|
LotteryOrderMap = new Map([
|
|
[0, "UIDs"],
|
|
[1, "TAGs"],
|
|
[2, "Articles"],
|
|
[3, "APIs"],
|
|
[4, "TxT"],
|
|
]);
|
|
|
|
config.updata(num);
|
|
|
|
if (!/buvid3/.test(cookie)) {
|
|
const charset = "0123456789ABCDEF".split("");
|
|
const buvid3 = "x".repeat(8).split("").map(() => getRandomOne(charset)).join("")
|
|
+ "-"
|
|
+ "x".repeat(4).split("").map(() => getRandomOne(charset)).join("")
|
|
+ "-"
|
|
+ "x".repeat(4).split("").map(() => getRandomOne(charset)).join("")
|
|
+ "-"
|
|
+ "x".repeat(4).split("").map(() => getRandomOne(charset)).join("")
|
|
+ "-"
|
|
+ "x".repeat(17).split("").map(() => getRandomOne(charset)).join("")
|
|
+ "infoc";
|
|
this.set('cookie', cookie + ";" + buvid3);
|
|
} else {
|
|
this.set('cookie', cookie);
|
|
}
|
|
|
|
cookie.split(/\s*;\s*/).forEach(item => {
|
|
const _item = item.split('=');
|
|
if (key_map.has(_item[0]))
|
|
this.set(key_map.get(_item[0]), _item[1]);
|
|
});
|
|
|
|
const { LotteryOrder } = config;
|
|
this.set('Lottery',
|
|
LotteryOrder
|
|
.map(it => LotteryOrderMap.get(it))
|
|
.filter(it => typeof it === "string")
|
|
.map(lottery_option => config[lottery_option].map(it => [lottery_option, it]))
|
|
.flat()
|
|
);
|
|
}
|
|
await createDir('dyids');
|
|
await createFile(dyids_dir, num < 2 ? 'dyid.txt' : `dyid${num}.txt`, '', 'a')
|
|
}
|
|
};
|
|
|
|
|
|
module.exports = global_var;
|