forked from 354197863/jd_sign_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
76 lines (65 loc) · 2.1 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// version v0.0.2
// create by ruicky
// detail url: https://github.com/ruicky/jd_sign_bot
const exec = require('child_process').execSync;
const fs = require('fs');
const rp = require('request-promise');
const download = require('download');
// 公共变量
const KEY = process.env.JD_COOKIE;
const serverJ = process.env.PUSH_KEY;
const DualKey = process.env.JD_COOKIE_2;
async function downFile () {
// const url = 'https://cdn.jsdelivr.net/gh/NobyDa/Script@master/JD-DailyBonus/JD_DailyBonus.js'
const url = 'https://raw.githubusercontent.com/NobyDa/Script/master/JD-DailyBonus/JD_DailyBonus.js';
await download(url, './');
}
async function changeFile () {
let content = await fs.readFileSync('./JD_DailyBonus.js', 'utf8')
content = content.replace(/var Key = ''/, `var Key = '${KEY}'`);
if (DualKey) {
content = content.replace(/var DualKey = ''/, `var DualKey = '${DualKey}'`);
}
await fs.writeFileSync( './JD_DailyBonus.js', content, 'utf8')
}
async function sendNotify (text,desp) {
const options ={
uri: `https://sc.ftqq.com/${serverJ}.send`,
form: { text, desp },
json: true,
method: 'POST'
}
await rp.post(options).then(res=>{
console.log(res)
}).catch((err)=>{
console.log(err)
})
}
async function start() {
if (!KEY) {
console.log('请填写 key 后在继续')
return
}
// 下载最新代码
await downFile();
console.log('下载代码完毕')
// 替换变量
await changeFile();
console.log('替换变量完毕')
// 执行
await exec("node JD_DailyBonus.js >> result.txt");
console.log('执行完毕')
if (serverJ) {
const path = "./result.txt";
let content = "";
if (fs.existsSync(path)) {
content = fs.readFileSync(path, "utf8");
}
let t = content.match(/【签到概览】:((.|\n)*)【签到总计】/)
let res = t ? t[1].replace(/\n/,'') : '失败'
let t2 = content.match(/【签到总计】:((.|\n)*)【账号总计】/)
let res2 = t2 ? t2[1].replace(/\n/,'') : '总计0'
await sendNotify("" + ` ${res2} ` + ` ${res} ` + new Date().toLocaleDateString(), content);
}
}
start()