UNPKG

@islamic-kit/zikr

Version:

islamic lessons, quotes, hadith, etc to share

68 lines (67 loc) 2.88 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "@islamic-kit/common", "@islamic-kit/scheduler", "path"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("@islamic-kit/common"); const scheduler_1 = require("@islamic-kit/scheduler"); const path_1 = require("path"); class ZikrNotifier { constructor(config) { this.config = config; this.scheduler = new scheduler_1.Scheduler(); this.targets = { slack: [] }; } scheduleZikrList() { this.scheduleSlackZikr(this.config); } scheduleSlackZikr(zikrConfig) { this.targets.slack.forEach((target) => { zikrConfig.list.forEach((zikr) => { this.scheduleSlackNotification(target.options, zikr); }); }); } scheduleSlackNotification(slackMessageConfig, zikr) { const { time, date, year, month, utcOffset } = zikr; const datetime = common_1.formatDate({ time, date, year, month, utcOffset }); this.scheduler.schedule({ name: zikr.content, description: zikr.content, datetime, script: { path: path_1.resolve(__dirname, 'sendToSlack.js'), args: [JSON.stringify(slackMessageConfig), zikr.content] } }); } configureTarget(target) { this.targets[target.name].push(target); } start() { this.scheduleZikrList(); this.scheduler.start(); } } __decorate([ common_1.logger({ group: 'zikr', params: ['name'] }) ], ZikrNotifier.prototype, "configureTarget", null); __decorate([ common_1.logger({ group: 'zikr', hint: 'Zikr Notifier' }) ], ZikrNotifier.prototype, "start", null); exports.ZikrNotifier = ZikrNotifier; });