user notifications

This commit is contained in:
Zichao Lin 2023-10-20 22:33:34 +08:00
parent dd86b82e1c
commit f8e47879f1
Signed by: earthjasonlin
GPG Key ID: 406D9913DE2E42FB
3 changed files with 36 additions and 1 deletions

View File

@ -5,5 +5,6 @@
"device_model": "",
"device_id": "",
"sys_version": "",
"channel": ""
"channel": "",
"email": ""
}

View File

@ -164,3 +164,20 @@ exports.SendLog = function (
}
);
};
exports.SendResult = function (transporter, mailfrom, mailto, content) {
transporter.sendMail(
{
from: `"Genshin Cloud Game Helper" <${mailfrom}>`, //邮件来源
to: mailto, //邮件发送到哪里,多个邮箱使用逗号隔开
subject: `Genshin Cloud Game Helper`, // 邮件主题
text: `${content}`, // 存文本类型的邮件正文
},
(error) => {
if (error) {
return console.log(error);
}
log.info(`已发送通知至${mailto}`);
}
);
};

View File

@ -8,6 +8,7 @@ const {
SendLog,
AppVersion,
getGlobalConfig,
SendResult,
} = require("./config");
const { log, addLogContent, getLogs, sleep } = require("./util");
@ -64,6 +65,14 @@ const nodemailer = require("nodemailer");
log.info(
`签到完毕! 获得时长:${WalletRespond.data.free_time.send_freetime}分钟,总时长:${WalletRespond.data.free_time.free_time}分钟`
);
if (configs[key].email != null) {
SendResult(
transporter,
globalConfig.mailConfig.user,
configs[key].email,
`签到完毕! 获得时长:${WalletRespond.data.free_time.send_freetime}分钟,总时长:${WalletRespond.data.free_time.free_time}分钟`
);
}
let NotificationLength = NotificationRespond.data.list.length;
let postHeader = header;
Object.assign(postHeader, {
@ -78,6 +87,14 @@ const nodemailer = require("nodemailer");
}
} else {
log.error("签到失败");
if (configs[key].email != null) {
SendResult(
transporter,
globalConfig.mailConfig.user,
configs[key].email,
"签到失败"
);
}
}
var delay = Math.round(
Math.random() * (maxDelay - minDelay) + minDelay