MCPcopy Index your code
hub / github.com/smallfawn/QLScriptPublic / serverNotify

Function serverNotify

sendNofity.js:277–323  ·  view source on GitHub ↗
(text, desp)

Source from the content-addressed store, hash-verified

275}
276
277function serverNotify(text, desp) {
278 return new Promise((resolve) => {
279 const { PUSH_KEY } = push_config;
280 if (PUSH_KEY) {
281 // 微信server酱推送通知一个\n不会换行,需要两个\n才能换行,故做此替换
282 desp = desp.replace(/[\n\r]/g, '\n\n');
283
284 const matchResult = PUSH_KEY.match(/^sctp(\d+)t/i);
285 const options = {
286 url:
287 matchResult && matchResult[1]
288 ? `https://${matchResult[1]}.push.ft07.com/send/${PUSH_KEY}.send`
289 : `https://sctapi.ftqq.com/${PUSH_KEY}.send`,
290 body: `text=${encodeURIComponent(text)}&desp=${encodeURIComponent(
291 desp,
292 )}`,
293 headers: {
294 'Content-Type': 'application/x-www-form-urlencoded',
295 },
296 timeout,
297 };
298 $.post(options, (err, resp, data) => {
299 try {
300 if (err) {
301 console.log('Server 酱发送通知调用API失败😞\n', err);
302 } else {
303 // server酱和Server酱·Turbo版的返回json格式不太一样
304 if (data.errno === 0 || data.data.errno === 0) {
305 console.log('Server 酱发送通知消息成功🎉\n');
306 } else if (data.errno === 1024) {
307 // 一分钟内发送相同的内容会触发
308 console.log(`Server 酱发送通知消息异常 ${data.errmsg}\n`);
309 } else {
310 console.log(`Server 酱发送通知消息异常 ${JSON.stringify(data)}`);
311 }
312 }
313 } catch (e) {
314 $.logErr(e, resp);
315 } finally {
316 resolve(data);
317 }
318 });
319 } else {
320 resolve();
321 }
322 });
323}
324
325function pushDeerNotify(text, desp) {
326 return new Promise((resolve) => {

Callers 1

sendNotifyFunction · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected