* sendNotify 推送通知功能 * @param text 通知头 * @param desp 通知体 * @param params 某些推送通知方式点击弹窗可跳转, 例:{ url: 'https://abc.com' } * @param author 作者仓库等信息 例:`本脚本免费使用 By:xxxx` * @returns {Promise }
(text, desp, params = {}, author = `\n\nJDHelloWorld.ts\n${format(Date.now(), "yyyy-MM-dd HH:mm:ss")}`)
| 187 | * @returns {Promise<unknown>} |
| 188 | */ |
| 189 | async function sendNotify(text, desp, params = {}, author = `\n\nJDHelloWorld.ts\n${format(Date.now(), "yyyy-MM-dd HH:mm:ss")}`) { |
| 190 | //提供6种通知 |
| 191 | let remarks = ''; |
| 192 | try { |
| 193 | fs.accessSync('./utils/account.json') |
| 194 | remarks = JSON.parse(fs.readFileSync('./utils/account.json').toString() || '[]') |
| 195 | } catch (e) { |
| 196 | } |
| 197 | if (remarks) { |
| 198 | for (let account of remarks) { |
| 199 | let pt_pin = decodeURIComponent(account['pt_pin']).split(';')[0] |
| 200 | for (let subDesp of desp.split('\n\n')) { |
| 201 | if (subDesp.indexOf(pt_pin) > -1 && account['wxpusher_uid']) { |
| 202 | await wxpusher(text, subDesp, account['wxpusher_uid']) |
| 203 | } |
| 204 | } |
| 205 | if (pt_pin && account['remarks']) { |
| 206 | text = text.replace(new RegExp(pt_pin, 'gm'), account['remarks']) |
| 207 | desp = desp.replace(new RegExp(pt_pin, 'gm'), account['remarks']) |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | desp += author; |
| 212 | await Promise.all([ |
| 213 | serverNotify(text, desp),//微信server酱 |
| 214 | serverWecomNotify(text, desp), // 自建server酱推送 |
| 215 | pushPlusNotify(text, desp)//pushplus(推送加) |
| 216 | ]) |
| 217 | //由于上述两种微信通知需点击进去才能查看到详情,故text(标题内容)携带了账号序号以及昵称信息,方便不点击也可知道是哪个京东哪个活动 |
| 218 | text = text.match(/.*?(?=\s?-)/g) ? text.match(/.*?(?=\s?-)/g)[0] : text; |
| 219 | await Promise.all([ |
| 220 | BarkNotify(text, desp, params),//iOS Bark APP |
| 221 | tgBotNotify(text, desp),//telegram 机器人 |
| 222 | ddBotNotify(text, desp),//钉钉机器人 |
| 223 | qywxBotNotify(text, desp), //企业微信机器人 |
| 224 | qywxamNotify(text, desp), //企业微信应用消息推送 |
| 225 | iGotNotify(text, desp, params),//iGot |
| 226 | goCQhttp(text, desp) // go-cqhttp |
| 227 | ]) |
| 228 | } |
| 229 | |
| 230 | function goCQhttp(text, desp) { |
| 231 | if (go_cqhttp_url && go_cqhttp_qq && go_cqhttp_method) { |
no test coverage detected