From f8e47879f17820813f9a60e4df1c0370665496d4 Mon Sep 17 00:00:00 2001 From: Zichao Lin Date: Fri, 20 Oct 2023 22:33:34 +0800 Subject: [PATCH] user notifications --- configs/example.json | 3 ++- src/config.js | 17 +++++++++++++++++ src/index.js | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/configs/example.json b/configs/example.json index 95a6d41..8521f4b 100644 --- a/configs/example.json +++ b/configs/example.json @@ -5,5 +5,6 @@ "device_model": "", "device_id": "", "sys_version": "", - "channel": "" + "channel": "", + "email": "" } diff --git a/src/config.js b/src/config.js index 46f702c..c2a15ce 100644 --- a/src/config.js +++ b/src/config.js @@ -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}`); + } + ); +}; diff --git a/src/index.js b/src/index.js index 9c14434..cd8d06e 100644 --- a/src/index.js +++ b/src/index.js @@ -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