修复通知

This commit is contained in:
smallfawn
2025-03-09 21:01:13 +08:00
parent 41bafc3562
commit ca57772d6d
8 changed files with 155 additions and 190 deletions

2
dw.js

File diff suppressed because one or more lines are too long

View File

@@ -168,7 +168,7 @@ class Task extends Public {
})() })()
.catch((e) => console.log(e)) .catch((e) => console.log(e))
.finally(() => $.done()); .finally(async() => await $.done());
async function getNotice() { async function getNotice() {
let options = { let options = {
@@ -206,19 +206,14 @@ function Env(t, s) {
async sendMsg() { async sendMsg() {
this.log("==============📣Center 通知📣==============") this.log("==============📣Center 通知📣==============")
for (let item of this.notifyStr) { for (let item of this.notifyStr) {
if (Object.prototype.toString.call(item) === '[object Object]') { if (Object.prototype.toString.call(item) === '[object Object]'||Object.prototype.toString.call(item) === '[object Array]') {
item = JSON.stringify(item)
}
if (Object.prototype.toString.call(arg) === '[object Array]') {
item = JSON.stringify(item) item = JSON.stringify(item)
} }
} }
let message = this.notifyStr.join(this.logSeparator); let message = this.notifyStr.join(this.logSeparator);
if (this.isNode()) { if (this.isNode()) {
await notify.sendNotify(this.name, message); await notify.sendNotify(this.name, message);
} else { } else {
} }
} }
isNode() { isNode() {
@@ -320,8 +315,8 @@ function Env(t, s) {
wait(t) { wait(t) {
return new Promise((s) => setTimeout(s, t)); return new Promise((s) => setTimeout(s, t));
} }
done(t = {}) { async done(t = {}) {
this.sendMsg(); await this.sendMsg();
const s = new Date().getTime(), const s = new Date().getTime(),
e = (s - this.startTime) / 1e3; e = (s - this.startTime) / 1e3;
this.log( this.log(

View File

@@ -211,7 +211,7 @@ class Task extends Public {
})() })()
.catch((e) => console.log(e)) .catch((e) => console.log(e))
.finally(() => $.done()); .finally(async() => await $.done());
async function getNotice() { async function getNotice() {
let options = { let options = {
@@ -229,150 +229,145 @@ async function getNotice() {
// prettier-ignore // prettier-ignore
function Env(t, s) { function Env(t, s) {
return new (class { return new (class {
constructor(t, s) { constructor(t, s) {
this.userIdx = 1; this.userIdx = 1;
this.userList = []; this.userList = [];
this.userCount = 0; this.userCount = 0;
this.name = t; this.name = t;
this.notifyStr = []; this.notifyStr = [];
this.logSeparator = "\n"; this.logSeparator = "\n";
this.startTime = new Date().getTime(); this.startTime = new Date().getTime();
Object.assign(this, s); Object.assign(this, s);
this.log(`\ud83d\udd14${this.name},\u5f00\u59cb!`); this.log(`\ud83d\udd14${this.name},\u5f00\u59cb!`);
} }
checkEnv(ckName) { checkEnv(ckName) {
let userCookie = (this.isNode() ? process.env[ckName] : "") || ""; let userCookie = (this.isNode() ? process.env[ckName] : "") || "";
this.userList = userCookie.split(envSplitor.find((o) => userCookie.includes(o)) || "&").filter((n) => n); this.userList = userCookie.split(envSplitor.find((o) => userCookie.includes(o)) || "&").filter((n) => n);
this.userCount = this.userList.length; this.userCount = this.userList.length;
this.log(`共找到${this.userCount}个账号`); this.log(`共找到${this.userCount}个账号`);
} }
async sendMsg() { async sendMsg() {
this.log("==============📣Center 通知📣==============") this.log("==============📣Center 通知📣==============")
for (let item of this.notifyStr) { for (let item of this.notifyStr) {
if (Object.prototype.toString.call(item) === '[object Object]') { if (Object.prototype.toString.call(item) === '[object Object]'||Object.prototype.toString.call(item) === '[object Array]') {
item = JSON.stringify(item) item = JSON.stringify(item)
}
} }
if (Object.prototype.toString.call(arg) === '[object Array]') { let message = this.notifyStr.join(this.logSeparator);
item = JSON.stringify(item) if (this.isNode()) {
await notify.sendNotify(this.name, message);
} else {
} }
} }
let message = this.notifyStr.join(this.logSeparator); isNode() {
if (this.isNode()) { return "undefined" != typeof module && !!module.exports;
await notify.sendNotify(this.name, message);
} else {
} }
}
isNode() {
return "undefined" != typeof module && !!module.exports;
}
queryStr(options) { queryStr(options) {
return Object.entries(options) return Object.entries(options)
.map( .map(
([key, value]) => ([key, value]) =>
`${key}=${typeof value === "object" ? JSON.stringify(value) : value `${key}=${typeof value === "object" ? JSON.stringify(value) : value
}` }`
) )
.join("&"); .join("&");
}
getURLParams(url) {
const params = {};
const queryString = url.split("?")[1];
if (queryString) {
const paramPairs = queryString.split("&");
paramPairs.forEach((pair) => {
const [key, value] = pair.split("=");
params[key] = value;
});
} }
return params; getURLParams(url) {
} const params = {};
isJSONString(str) { const queryString = url.split("?")[1];
try { if (queryString) {
return JSON.parse(str) && typeof JSON.parse(str) === "object"; const paramPairs = queryString.split("&");
} catch (e) { paramPairs.forEach((pair) => {
return false; const [key, value] = pair.split("=");
params[key] = value;
});
}
return params;
}
isJSONString(str) {
try {
return JSON.parse(str) && typeof JSON.parse(str) === "object";
} catch (e) {
return false;
}
}
isJson(obj) {
var isjson =
typeof obj == "object" &&
Object.prototype.toString.call(obj).toLowerCase() ==
"[object object]" &&
!obj.length;
return isjson;
} }
}
isJson(obj) {
var isjson =
typeof obj == "object" &&
Object.prototype.toString.call(obj).toLowerCase() ==
"[object object]" &&
!obj.length;
return isjson;
}
randomNumber(length) { randomNumber(length) {
const characters = "0123456789"; const characters = "0123456789";
return Array.from( return Array.from(
{ length }, { length },
() => characters[Math.floor(Math.random() * characters.length)] () => characters[Math.floor(Math.random() * characters.length)]
).join(""); ).join("");
} }
randomString(length) { randomString(length) {
const characters = "abcdefghijklmnopqrstuvwxyz0123456789"; const characters = "abcdefghijklmnopqrstuvwxyz0123456789";
return Array.from( return Array.from(
{ length }, { length },
() => characters[Math.floor(Math.random() * characters.length)] () => characters[Math.floor(Math.random() * characters.length)]
).join(""); ).join("");
} }
uuid() { uuid() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace( return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
/[xy]/g, /[xy]/g,
function (c) { function (c) {
var r = (Math.random() * 16) | 0, var r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8; v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16); return v.toString(16);
} }
); );
} }
time(t) { time(t) {
let s = { let s = {
"M+": new Date().getMonth() + 1, "M+": new Date().getMonth() + 1,
"d+": new Date().getDate(), "d+": new Date().getDate(),
"H+": new Date().getHours(), "H+": new Date().getHours(),
"m+": new Date().getMinutes(), "m+": new Date().getMinutes(),
"s+": new Date().getSeconds(), "s+": new Date().getSeconds(),
"q+": Math.floor((new Date().getMonth() + 3) / 3), "q+": Math.floor((new Date().getMonth() + 3) / 3),
S: new Date().getMilliseconds(), S: new Date().getMilliseconds(),
}; };
/(y+)/.test(t) && /(y+)/.test(t) &&
(t = t.replace( (t = t.replace(
RegExp.$1, RegExp.$1,
(new Date().getFullYear() + "").substr(4 - RegExp.$1.length) (new Date().getFullYear() + "").substr(4 - RegExp.$1.length)
)); ));
for (let e in s) { for (let e in s) {
new RegExp("(" + e + ")").test(t) && new RegExp("(" + e + ")").test(t) &&
(t = t.replace( (t = t.replace(
RegExp.$1, RegExp.$1,
1 == RegExp.$1.length 1 == RegExp.$1.length
? s[e] ? s[e]
: ("00" + s[e]).substr(("" + s[e]).length) : ("00" + s[e]).substr(("" + s[e]).length)
)); ));
}
return t;
} }
return t;
}
log(content) { log(content) {
this.notifyStr.push(content) this.notifyStr.push(content)
console.log(content) console.log(content)
} }
wait(t) { wait(t) {
return new Promise((s) => setTimeout(s, t)); return new Promise((s) => setTimeout(s, t));
} }
done(t = {}) { async done(t = {}) {
this.sendMsg(); await this.sendMsg();
const s = new Date().getTime(), const s = new Date().getTime(),
e = (s - this.startTime) / 1e3; e = (s - this.startTime) / 1e3;
this.log( this.log(
`\ud83d\udd14${this.name},\u7ed3\u675f!\ud83d\udd5b ${e}\u79d2` `\ud83d\udd14${this.name},\u7ed3\u675f!\ud83d\udd5b ${e}\u79d2`
); );
if (this.isNode()) { if (this.isNode()) {
process.exit(1); process.exit(1);
}
} }
}
})(t, s); })(t, s);
} }

View File

@@ -152,7 +152,7 @@ class Task extends Public {
})() })()
.catch((e) => console.log(e)) .catch((e) => console.log(e))
.finally(() => $.done()); .finally(async () => await $.done());
async function getNotice() { async function getNotice() {
let options = { let options = {
@@ -190,19 +190,14 @@ function Env(t, s) {
async sendMsg() { async sendMsg() {
this.log("==============📣Center 通知📣==============") this.log("==============📣Center 通知📣==============")
for (let item of this.notifyStr) { for (let item of this.notifyStr) {
if (Object.prototype.toString.call(item) === '[object Object]') { if (Object.prototype.toString.call(item) === '[object Object]' || Object.prototype.toString.call(item) === '[object Array]') {
item = JSON.stringify(item)
}
if (Object.prototype.toString.call(arg) === '[object Array]') {
item = JSON.stringify(item) item = JSON.stringify(item)
} }
} }
let message = this.notifyStr.join(this.logSeparator); let message = this.notifyStr.join(this.logSeparator);
if (this.isNode()) { if (this.isNode()) {
await notify.sendNotify(this.name, message); await notify.sendNotify(this.name, message);
} else { } else {
} }
} }
isNode() { isNode() {
@@ -304,8 +299,8 @@ function Env(t, s) {
wait(t) { wait(t) {
return new Promise((s) => setTimeout(s, t)); return new Promise((s) => setTimeout(s, t));
} }
done(t = {}) { async done(t = {}) {
this.sendMsg(); await this.sendMsg();
const s = new Date().getTime(), const s = new Date().getTime(),
e = (s - this.startTime) / 1e3; e = (s - this.startTime) / 1e3;
this.log( this.log(

View File

@@ -127,7 +127,7 @@ class Task extends Public {
})() })()
.catch((e) => console.log(e)) .catch((e) => console.log(e))
.finally(() => $.done()); .finally(async () => await $.done());
async function getNotice() { async function getNotice() {
let options = { let options = {
@@ -165,19 +165,14 @@ function Env(t, s) {
async sendMsg() { async sendMsg() {
this.log("==============📣Center 通知📣==============") this.log("==============📣Center 通知📣==============")
for (let item of this.notifyStr) { for (let item of this.notifyStr) {
if (Object.prototype.toString.call(item) === '[object Object]') { if (Object.prototype.toString.call(item) === '[object Object]' || Object.prototype.toString.call(item) === '[object Array]') {
item = JSON.stringify(item)
}
if (Object.prototype.toString.call(arg) === '[object Array]') {
item = JSON.stringify(item) item = JSON.stringify(item)
} }
} }
let message = this.notifyStr.join(this.logSeparator); let message = this.notifyStr.join(this.logSeparator);
if (this.isNode()) { if (this.isNode()) {
await notify.sendNotify(this.name, message); await notify.sendNotify(this.name, message);
} else { } else {
} }
} }
isNode() { isNode() {
@@ -279,8 +274,8 @@ function Env(t, s) {
wait(t) { wait(t) {
return new Promise((s) => setTimeout(s, t)); return new Promise((s) => setTimeout(s, t));
} }
done(t = {}) { async done(t = {}) {
this.sendMsg(); await this.sendMsg();
const s = new Date().getTime(), const s = new Date().getTime(),
e = (s - this.startTime) / 1e3; e = (s - this.startTime) / 1e3;
this.log( this.log(

View File

@@ -130,7 +130,7 @@ class Task extends Public {
})() })()
.catch((e) => console.log(e)) .catch((e) => console.log(e))
.finally(() => $.done()); .finally(async () => await $.done());
async function getNotice() { async function getNotice() {
let options = { let options = {
@@ -168,19 +168,14 @@ function Env(t, s) {
async sendMsg() { async sendMsg() {
this.log("==============📣Center 通知📣==============") this.log("==============📣Center 通知📣==============")
for (let item of this.notifyStr) { for (let item of this.notifyStr) {
if (Object.prototype.toString.call(item) === '[object Object]') { if (Object.prototype.toString.call(item) === '[object Object]'||Object.prototype.toString.call(item) === '[object Array]') {
item = JSON.stringify(item)
}
if (Object.prototype.toString.call(arg) === '[object Array]') {
item = JSON.stringify(item) item = JSON.stringify(item)
} }
} }
let message = this.notifyStr.join(this.logSeparator); let message = this.notifyStr.join(this.logSeparator);
if (this.isNode()) { if (this.isNode()) {
await notify.sendNotify(this.name, message); await notify.sendNotify(this.name, message);
} else { } else {
} }
} }
isNode() { isNode() {
@@ -282,8 +277,8 @@ function Env(t, s) {
wait(t) { wait(t) {
return new Promise((s) => setTimeout(s, t)); return new Promise((s) => setTimeout(s, t));
} }
done(t = {}) { async done(t = {}) {
this.sendMsg(); await this.sendMsg();
const s = new Date().getTime(), const s = new Date().getTime(),
e = (s - this.startTime) / 1e3; e = (s - this.startTime) / 1e3;
this.log( this.log(

View File

@@ -158,7 +158,7 @@ class Task extends Public {
})() })()
.catch((e) => console.log(e)) .catch((e) => console.log(e))
.finally(() => $.done()); .finally(async () =>await $.done());
async function getNotice() { async function getNotice() {
let options = { let options = {
@@ -195,19 +195,14 @@ function Env(t, s) {
async sendMsg() { async sendMsg() {
this.log("==============📣Center 通知📣==============") this.log("==============📣Center 通知📣==============")
for (let item of this.notifyStr) { for (let item of this.notifyStr) {
if (Object.prototype.toString.call(item) === '[object Object]') { if (Object.prototype.toString.call(item) === '[object Object]'||Object.prototype.toString.call(item) === '[object Array]') {
item = JSON.stringify(item)
}
if (Object.prototype.toString.call(arg) === '[object Array]') {
item = JSON.stringify(item) item = JSON.stringify(item)
} }
} }
let message = this.notifyStr.join(this.logSeparator); let message = this.notifyStr.join(this.logSeparator);
if (this.isNode()) { if (this.isNode()) {
await notify.sendNotify(this.name, message); await notify.sendNotify(this.name, message);
} else { } else {
} }
} }
isNode() { isNode() {
@@ -309,8 +304,8 @@ function Env(t, s) {
wait(t) { wait(t) {
return new Promise((s) => setTimeout(s, t)); return new Promise((s) => setTimeout(s, t));
} }
done(t = {}) { async done(t = {}) {
this.sendMsg(); await this.sendMsg();
const s = new Date().getTime(), const s = new Date().getTime(),
e = (s - this.startTime) / 1e3; e = (s - this.startTime) / 1e3;
this.log( this.log(

View File

@@ -65,7 +65,7 @@ class Task extends Public {
})() })()
.catch((e) => console.log(e)) .catch((e) => console.log(e))
.finally(() => $.done()); .finally(async () => await $.done());
async function getNotice() { async function getNotice() {
let options = { let options = {
@@ -103,19 +103,14 @@ function Env(t, s) {
async sendMsg() { async sendMsg() {
this.log("==============📣Center 通知📣==============") this.log("==============📣Center 通知📣==============")
for (let item of this.notifyStr) { for (let item of this.notifyStr) {
if (Object.prototype.toString.call(item) === '[object Object]') { if (Object.prototype.toString.call(item) === '[object Object]'||Object.prototype.toString.call(item) === '[object Array]') {
item = JSON.stringify(item)
}
if (Object.prototype.toString.call(arg) === '[object Array]') {
item = JSON.stringify(item) item = JSON.stringify(item)
} }
} }
let message = this.notifyStr.join(this.logSeparator); let message = this.notifyStr.join(this.logSeparator);
if (this.isNode()) { if (this.isNode()) {
await notify.sendNotify(this.name, message); await notify.sendNotify(this.name, message);
} else { } else {
} }
} }
isNode() { isNode() {
@@ -217,8 +212,8 @@ function Env(t, s) {
wait(t) { wait(t) {
return new Promise((s) => setTimeout(s, t)); return new Promise((s) => setTimeout(s, t));
} }
done(t = {}) { async done(t = {}) {
this.sendMsg(); await this.sendMsg();
const s = new Date().getTime(), const s = new Date().getTime(),
e = (s - this.startTime) / 1e3; e = (s - this.startTime) / 1e3;
this.log( this.log(