-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend-onebot-group-msg.js
More file actions
70 lines (62 loc) · 1.82 KB
/
send-onebot-group-msg.js
File metadata and controls
70 lines (62 loc) · 1.82 KB
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
// v1
// 发送 onebot 群消息
//#region 修改
const HOST = 'http://napcat:6100'
const TOKEN = 'ltxhhz'
const GROUP_ID = '1051912409'
//#endregion
const axios = ctx.http
const result = []
const reqCert = ctx.pipeline.stages.find(stage => stage.title === '证书申请阶段')?.tasks?.[0]
const reqCertResult = reqCert?.status?.result
const reader = new ctx.CertReader(ctx.self.cert)
const expires = reader.expires
/** @type {{commonName:string,altNames:string[]}} */
const domains = reader.detail.domains
if (reqCert) {
result.push({
title: reqCert.title,
result: reqCertResult,
expires: new ctx.CertReader(ctx.self.cert).expires
})
}
ctx.logger.info(Object.keys(ctx.self))
// ctx.logger.info(ctx.inputChanged)
// ctx.logger.info(JSON.stringify(ctx.pipeline))
if (reqCertResult === 'error') {
const reqCertProcess = reqCert.processes.find(process => process.title === '处理证书阶段')
for (let i = 0; i < reqCertProcess.tasks.length; i++) {
const task = reqCertProcess.tasks[i]
for (let j = 0; j < task.steps.length; j++) {
const step = task.steps[j]
if (step.disabled === false) {
result.push({
title: `${task.title}/${step.title}`,
result: step.status.result
})
}
}
}
}
ctx.logger.info(JSON.stringify(result))
await axios({
url: `${HOST}/send_group_msg`,
method: 'POST',
headers: {
Authorization: `Bearer ${TOKEN}`
},
data: {
group_id: GROUP_ID,
message: `证书申请结果
${domains.altNames.join('|')}
距离到期: ${Math.floor((expires - new Date()) / 1000 / 60 / 60 / 24)}天
=============
${result.map(item => `${item.title}: ${item.result}`).join('\n\n')}`
}
}).then(e => {
ctx.logger.info('status', e.status)
ctx.logger.info('data', JSON.stringify(e.data))
if (!e.data) {
throw new Error('发送通知失败')
}
})