forked from Wenmoux/checkbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckbox.js
More file actions
125 lines (116 loc) · 5.24 KB
/
checkbox.js
File metadata and controls
125 lines (116 loc) · 5.24 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
cron: 28 8 * * *
new Env('签到盒');
*/
const yaml = require("js-yaml");
const fs = require('fs');
// 兼容 yargs 17.x 和 18.x 版本
const yargsModule = require('yargs/yargs');
const yargs = yargsModule.default || yargsModule;
const { hideBin } = require('yargs/helpers');
var argv = yargs(hideBin(process.argv)).argv;
const axios= require('axios');
ycurl = process.env.ycurl
let QL = process.env.QL_DIR
config = null, notify = null, sendmsg = null, signlist = [], logs = "", needPush = false, signList = []
if (fs.existsSync("./sendNotify.js")) notify = require('./sendNotify')
//自行添加任务 名字看脚本里的文件名 比如csdn.js 就填"csdn"
var cbList = []
async function go() {
if (ycurl) await getCF(ycurl)
else {
if (fs.existsSync("./config.yml")) config = yaml.load(fs.readFileSync('./config.yml', 'utf8'));
if (QL) {
console.log("当前是青龙面板,路径:" + QL)
if (fs.existsSync(`/${QL}/data/config/config.sh`)) console.log("建议更新到最新版青龙再来运行哦,或者手动修改路径叭~")
cbList = process.env.cbList ? process.env.cbList.split("&") : []
if (!fs.existsSync(`/${QL}/data/config/config.yml`)) {
console.log("您还没有填写cookies配置文件,请配置好再来运行8...\n配置文件路径/ql/data/config/config.yml\n如没有文件复制一份config.yml.temple并改名为config.yml")
return;
} else {
if (yaml.load) config = yaml.load(fs.readFileSync(`/${QL}/data/config/config.yml`, 'utf8'))
else console.log("亲,您的依赖掉啦,但是没有完全掉 请重装依赖\npnpm install axios crypto crypto-js fs iconv-lite js-yaml yargs\n或者\nnpm install axios crypto crypto-js fs iconv-lite js-yaml yargs")
}
}
}
if (config && config.Push) sendmsg = require("./sendmsg")
if (config) signlist = config.cbList.split("&")
if (config && config.needPush) needPush = true
var signList = (argv._.length) > 0 ? argv._ : (cbList.length > 0 ? cbList : signlist)
if (config && process.env.TENCENTCLOUD_RUNENV != "SCF") start(signList);
else console.log("哈哈哈")
}
function start(taskList) {
return new Promise(async (resolve) => {
try {
console.log("任务个数 " + taskList.length)
console.log("------------开始签到任务------------");
for (let i = 0; i < taskList.length; i++) {
console.log(`任务${i + 1}执行中`);
let exists = fs.existsSync(`./scripts/${taskList[i]}.js`)
if (exists) {
const task = require(`./scripts/${taskList[i]}.js`);
taskResult = await task()
if (taskResult && taskResult.match(/单独通知|cookie|失效|失败|出错|重新登录/)) await sendmsg(taskResult)
else logs += taskResult + " \n\n";
} else {
logs += `${taskList[i]} 不存在该脚本文件,请确认输入是否有误\n\n`
console.log("不存在该脚本文件,请确认输入是否有误")
}
}
console.log("------------任务执行完毕------------\n");
// 判断是否有自定义推送渠道
let hasCustomPushChannel = false;
if (config && config.Push) {
hasCustomPushChannel =
config.Push.sckey ||
(config.Push.qywx && config.Push.qywx.corpsecret) ||
(config.Push.tgpushkey && config.Push.tgpushkey.tgbotoken) ||
config.Push.qmsgkey ||
config.Push.pushplustoken ||
(config.Push.vocechat && config.Push.vocechat.key);
}
// 处理不同通知渠道
if (needPush) {
if (sendmsg) {
let fullLogs = logs + "\n\n吹水群:https://t.me/htuoypa";
await sendmsg(fullLogs);
}
// 只有在没有自定义推送渠道时,才使用 notify 发送
if (!hasCustomPushChannel && notify) {
await notify.sendNotify("签到盒", `${logs}\n\n吹水群:https://t.me/htuoypa`);
}
}
} catch (err) {
console.log(err);
}
resolve();
});
}
function getCF(ycurl) {
return new Promise(async (resolve) => {
try {
console.log("------------开始获取远程配置文件------------");
let rr = await axios.get(ycurl)
if (rr && rr.data) rconfig = rr.data
if (rconfig.match(/cbList/)) {
console.log("------------获取远程配置文件成功------------")
config = yaml.load(rconfig)
// console.log(config)
} else {
console.log("远程配置文件有误")
return;
}
} catch (err) {
console.log(err);
console.log("远程配置文件有误")
}
resolve();
});
}
go()
//云函数入口
exports.main_handler = async () => {
await start()
await start(signList);
};