MCPcopy Create free account
hub / github.com/Semporia/Scripts / serverNotify

Function serverNotify

sendNotify.js:217–260  ·  view source on GitHub ↗
(text, desp, time = 2100)

Source from the content-addressed store, hash-verified

215}
216
217function serverNotify(text, desp, time = 2100) {
218 return new Promise(resolve => {
219 if (SCKEY) {
220 //微信server酱推送通知一个\n不会换行,需要两个\n才能换行,故做此替换
221 desp = desp.replace(/[\n\r]/g, '\n\n');
222 const options = {
223 url: SCKEY.includes('SCT') ? `https://sctapi.ftqq.com/${SCKEY}.send` : `https://sc.ftqq.com/${SCKEY}.send`,
224 body: `text=${text}&desp=${desp}`,
225 headers: {
226 'Content-Type': 'application/x-www-form-urlencoded'
227 },
228 timeout
229 }
230 setTimeout(() => {
231 $.post(options, (err, resp, data) => {
232 try {
233 if (err) {
234 console.log('发送通知调用API失败!!\n')
235 console.log(err);
236 } else {
237 data = JSON.parse(data);
238 //server酱和Server酱·Turbo版的返回json格式不太一样
239 if (data.errno === 0 || data.data.errno === 0) {
240 console.log('server酱发送通知消息成功🎉\n')
241 } else if (data.errno === 1024) {
242 // 一分钟内发送相同的内容会触发
243 console.log(`server酱发送通知消息异常: ${data.errmsg}\n`)
244 } else {
245 console.log(`server酱发送通知消息异常\n${JSON.stringify(data)}`)
246 }
247 }
248 } catch (e) {
249 $.logErr(e, resp);
250 } finally {
251 resolve(data);
252 }
253 })
254 }, time)
255 } else {
256 console.log('\n\n您未提供server酱的SCKEY,取消微信推送消息通知🚫\n');
257 resolve()
258 }
259 })
260}
261
262function BarkNotify(text, desp, params = {}) {
263 return new Promise(resolve => {

Callers 1

sendNotifyFunction · 0.85

Calls 3

postMethod · 0.45
logMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected