forked from HuanLinOTO/GenshinCloudGameHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (77 loc) · 2.93 KB
/
index.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
77
78
79
80
81
82
83
84
85
86
87
const request = require("sync-request")
const fs = require("fs")
const log4js = require("log4js")
const { getConfigs, checkConfigs, makeHeader, Notification, Wallet, SendLog, AppVersion, getGlobalConfig } = require("./config")
const urlconfig = require("./config")
const nodemailer = require('nodemailer')
var baseLogger = log4js.getLogger()
baseLogger.level = "info"
var logContent = ``
global.log = {
info(content){
logContent += `<strong style="color: green">[info]</strong> ${content}<br>`
baseLogger.info(content)
},
error(content){
logContent += `<strong style="color: red">[error]</strong> ${content}<br>`
baseLogger.error(content)
}
}
log.info("开始获取全局配置")
var globalConfig = getGlobalConfig();
log.info("获取成功")
if (globalConfig.sendMail == true) {
log.info("组装邮件发射器")
var transporter = nodemailer.createTransport({
host: 'smtp.163.com',
port: 465,
secure: true,
auth: {
user: globalConfig.mailConfig.user,
pass: globalConfig.mailConfig.pass
}
});
}
var configs = getConfigs();
// console.log(configs);
log.info(`正在检测配置有效性`)
checkConfigs(configs)
log.info("检测完毕!")
log.info("正在获取版本号")
var appversion = AppVersion();
appversion = appversion.data.config["cg.key_function_controller"].versions[appversion.data.config["cg.key_function_controller"].versions.length-1]
log.info(`获取成功!当前版本号:${appversion}`)
var successNum = 0,totalNum = 0;
for(key in configs) {
totalNum ++;
log.info(`正在执行配置 ${key}`)
log.info("尝试签到……")
var WalletRespond = Wallet(makeHeader(configs[key]),appversion);
logContent += `<span style="color: orange">${key} Wallet返回体 <br> ${JSON.stringify(WalletRespond)}</span><br>`;
var NotificationRespond = Notification(makeHeader(configs[key]));
logContent += `<span style="color: orange">${key} Notification返回体 <br> ${JSON.stringify(NotificationRespond)}</span><br>`;
if(WalletRespond.data.free_time.free_time != undefined) {
successNum ++;
log.info(`签到完毕! 剩余时长:${WalletRespond.data.free_time.free_time}分钟`)
let NotificationLength = NotificationRespond.data.list.length
if(NotificationLength != 0) {
log.info(`已堆积 ${NotificationLength} 个签到通知 请及时处理!`)
}
} else {
log.error("签到失败")
}
// log.info(`Wallet ${Wallet(makeHeader(configs[key])).StringVersion}`)
// log.info(`Announcement ${Announcement(makeHeader(configs[key])).StringVersion}`)
// console.log(makeHeader(configs[key]));
}
if (globalConfig.sendMail == true) {
log.info(`运行完毕!丢出日志`)
SendLog(
transporter,
globalConfig.mailConfig.user,
globalConfig.mailConfig.mailto,
successNum,
totalNum,
logContent
)
}