-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathmain.js
More file actions
107 lines (104 loc) · 3.32 KB
/
main.js
File metadata and controls
107 lines (104 loc) · 3.32 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const glados = async () => {
const notice = []
if (!process.env.GLADOS) return
for (const cookie of String(process.env.GLADOS).split('\n')) {
if (!cookie) continue
try {
const common = {
'cookie': cookie,
'referer': 'https://glados.cloud/console/checkin',
'user-agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)',
}
const action = await fetch('https://glados.cloud/api/user/checkin', {
method: 'POST',
headers: { ...common, 'content-type': 'application/json' },
body: '{"token":"glados.cloud"}',
}).then((r) => r.json())
if (action?.code) throw new Error(action?.message)
const status = await fetch('https://glados.cloud/api/user/status', {
method: 'GET',
headers: { ...common },
}).then((r) => r.json())
if (status?.code) throw new Error(status?.message)
notice.push(
'Checkin OK',
`${action?.message}`,
`Left Days ${Number(status?.data?.leftDays)}`
)
} catch (error) {
notice.push(
'Checkin Error',
`${error}`,
`<${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}>`
)
}
}
return notice
}
const notify = async (notice) => {
if (!process.env.NOTIFY || !notice) return
for (const option of String(process.env.NOTIFY).split('\n')) {
if (!option) continue
try {
if (option.startsWith('console:')) {
for (const line of notice) {
console.log(line)
}
} else if (option.startsWith('wxpusher:')) {
await fetch(`https://wxpusher.zjiecode.com/api/send/message`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
appToken: option.split(':')[1],
summary: notice[0],
content: notice.join('<br>'),
contentType: 3,
uids: option.split(':').slice(2),
}),
})
} else if (option.startsWith('pushplus:')) {
await fetch(`https://www.pushplus.plus/send`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
token: option.split(':')[1],
title: notice[0],
content: notice.join('<br>'),
template: 'markdown',
}),
})
} else if (option.startsWith('qyweixin:')) {
const qyweixinToken = option.split(':')[1]
const qyweixinNotifyRebotUrl = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' + qyweixinToken;
await fetch(qyweixinNotifyRebotUrl, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
msgtype: 'markdown',
markdown: {
content: notice.join('<br>')
}
}),
})
} else {
// fallback
await fetch(`https://www.pushplus.plus/send`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
token: option,
title: notice[0],
content: notice.join('<br>'),
template: 'markdown',
}),
})
}
} catch (error) {
throw error
}
}
}
const main = async () => {
await notify(await glados())
}
main()