UNPKG

@memo28.pro/notification

Version:

企业级消息通知解决方案 - 支持多平台消息推送的轻量级 TypeScript SDK

2 lines (1 loc) 976 B
"use strict";class o{constructor(){this.moduleList=[]}registerModule(e){return Array.isArray(e)?this.moduleList.push(...e):this.moduleList.push(e),this}getModuleList(){return this.moduleList}checkModule(e){return e.getMessageBulder()?e.getPlatform()?e.getWebhook()?[!0,""]:[!1,"缺少Webhook地址"]:[!1,"缺少平台标识"]:[!1,"缺少消息构建器"]}seed(e){return this.moduleList.forEach(t=>{t.setMessageBulder(e);const[s,r]=this.checkModule(t);s?console.log(`模块 ${t.getPlatform()} 已就绪`):console.warn(`模块 ${t.getPlatform()} 配置检查失败: ${r}`)}),this}async sendAll(){const e=[];for(const t of this.moduleList)try{if(typeof t.send=="function"){const s=await t.send();e.push(s)}else console.warn(`模块 ${t.getPlatform()} 没有send方法`),e.push(!1)}catch(s){console.error(`模块 ${t.getPlatform()} 发送失败:`,s),e.push(!1)}return e}clearModules(){return this.moduleList=[],this}getModuleCount(){return this.moduleList.length}}exports.Core=o;