// prettier-ignore function Env(t, s) { return new (class { constructor(t, s) { this.userIdx = 1; this.userList = []; this.userCount = 0; this.name = t; this.notifyStr = []; this.logSeparator = "\n"; this.startTime = new Date().getTime(); Object.assign(this, s); this.log(`\ud83d\udd14${this.name},\u5f00\u59cb!`); } checkEnv(ckName) { const envSplitor = ["&", "\n"]; let userCookie = (this.isNode() ? process.env[ckName] : "") || ""; this.userList = userCookie.split(envSplitor.find((o) => userCookie.includes(o)) || "&").filter((n) => n); this.userCount = this.userList.length; this.log(`共找到${this.userCount}个账号`); } async sendMsg() { this.log("==============📣Center 通知📣==============") for (let i = 0; i < this.notifyStr.length; i++) { if (Object.prototype.toString.call(this.notifyStr[i]) === '[object Object]' || Object.prototype.toString.call(this.notifyStr[i]) === '[object Array]') { this.notifyStr[i] = JSON.stringify(this.notifyStr[i]); } } let message = this.notifyStr.join(this.logSeparator); if (this.isNode()) { const notify = require("./sendNotify.js") await notify.sendNotify(this.name, message); } else { } } isNode() { return "undefined" != typeof module && !!module.exports; } jsonToStr(obj, c = '&', encodeUrl = false) { let ret = [] for (let keys of Object.keys(obj).sort()) { let v = obj[keys] if (v && encodeUrl) v = encodeURIComponent(v) ret.push(keys + '=' + v) } return ret.join(c); } 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; } 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; } randomNumber(length) { const characters = "0123456789"; return Array.from( { length }, () => characters[Math.floor(Math.random() * characters.length)] ).join(""); } randomString(length) { const characters = "abcdefghijklmnopqrstuvwxyz0123456789"; return Array.from( { length }, () => characters[Math.floor(Math.random() * characters.length)] ).join(""); } uuid() { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace( /[xy]/g, function (c) { var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8; return v.toString(16); } ); } time(t) { let s = { "M+": new Date().getMonth() + 1, "d+": new Date().getDate(), "H+": new Date().getHours(), "m+": new Date().getMinutes(), "s+": new Date().getSeconds(), "q+": Math.floor((new Date().getMonth() + 3) / 3), S: new Date().getMilliseconds(), }; /(y+)/.test(t) && (t = t.replace( RegExp.$1, (new Date().getFullYear() + "").substr(4 - RegExp.$1.length) )); for (let e in s) { new RegExp("(" + e + ")").test(t) && (t = t.replace( RegExp.$1, 1 == RegExp.$1.length ? s[e] : ("00" + s[e]).substr(("" + s[e]).length) )); } return t; } log(content) { this.notifyStr.push(content) console.log(content) } wait(t) { return new Promise((s) => setTimeout(s, t)); } async done() { await this.sendMsg(); const s = new Date().getTime(), e = (s - this.startTime) / 1e3; this.log( `\ud83d\udd14${this.name},\u7ed3\u675f!\ud83d\udd5b ${e}\u79d2` ); if (this.isNode()) { process.exit(1); } } })(t, s); } module.exports = { Env }