/
notify.js
46 lines (41 loc) · 1.19 KB
/
notify.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
const fs = require('fs')
const os = require('os')
const axios = require('axios')
const inquirer = require('inquirer')
const wechat = async () => {
const configDirPath = os.homedir() + '/.webmonitor/'
let config = {}
if (fs.existsSync(configDirPath + 'config.json')) {
const rawdata = fs.readFileSync(configDirPath + 'config.json')
config = JSON.parse(rawdata)
}
if (!config.server_sckey) {
console.log(error('Error: server酱 SCKEY no configured.'))
console.log(info('please run \'wmcli config\' to config SCKEY'))
console.log('process exit.')
return false
}
const promptList = [{
type: 'input',
message: '请输入通知消息标题:',
name: 'title'
}, {
type: 'input',
message: '请输入通知消息内容:',
name: 'content'
},]
return await inquirer.prompt(promptList).then(answers => {
// console.log(`https://sc.ftqq.com/${config.server_sckey}.send?text=${answers.title}&desp=${answers.content}`)
return function () {
axios.get(`https://sc.ftqq.com/${config.server_sckey}.send`, {
params: {
text: answers.title,
desp: answers.content
}
})
}
})
}
module.exports = {
wechat
}