chz-telegram-bot 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,33 +1,22 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.startBot = startBot;
7
- exports.stopBots = stopBots;
8
- const promises_1 = require("fs/promises");
9
- const bot_js_1 = __importDefault(require("./entities/bot.js"));
10
- const taskScheduler_js_1 = __importDefault(require("./services/taskScheduler.js"));
11
- const storage_js_1 = __importDefault(require("./services/storage.js"));
12
- const logger_js_1 = __importDefault(require("./services/logger.js"));
13
- const bots = [];
14
- function log(text) {
15
- logger_js_1.default.logWithTraceId('ALL BOTS', 'System:Bot', 'System', text);
16
- }
17
- async function startBot(name, tokenFile, commands, scheduled, chats) {
18
- const token = await (0, promises_1.readFile)(tokenFile, 'utf8');
19
- const bot = new bot_js_1.default(name, token, commands, scheduled, chats);
20
- bots.push(bot);
21
- return bot;
22
- }
23
- async function stopBots(reason) {
24
- log(`Recieved termination code: ${reason}`);
25
- taskScheduler_js_1.default.stopAll();
26
- log('Acquiring storage semaphore...');
27
- await storage_js_1.default.semaphoreInstance.acquire();
28
- log('Stopping bots...');
29
- for (const bot of bots) {
30
- bot.stop(reason);
31
- }
32
- process.exit(0);
33
- }
17
+ exports.stopBots = exports.startBot = void 0;
18
+ var main_1 = require("./main");
19
+ Object.defineProperty(exports, "startBot", { enumerable: true, get: function () { return main_1.startBot; } });
20
+ Object.defineProperty(exports, "stopBots", { enumerable: true, get: function () { return main_1.stopBots; } });
21
+ __exportStar(require("./helpers/builders/commandActionBuilder"), exports);
22
+ __exportStar(require("./helpers/builders/scheduledActionBuilder"), exports);
package/dist/main.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.startBot = startBot;
7
+ exports.stopBots = stopBots;
8
+ const promises_1 = require("fs/promises");
9
+ const bot_js_1 = __importDefault(require("./entities/bot.js"));
10
+ const taskScheduler_js_1 = __importDefault(require("./services/taskScheduler.js"));
11
+ const storage_js_1 = __importDefault(require("./services/storage.js"));
12
+ const logger_js_1 = __importDefault(require("./services/logger.js"));
13
+ const bots = [];
14
+ function log(text) {
15
+ logger_js_1.default.logWithTraceId('ALL BOTS', 'System:Bot', 'System', text);
16
+ }
17
+ async function startBot(name, tokenFile, commands, scheduled, chats) {
18
+ const token = await (0, promises_1.readFile)(tokenFile, 'utf8');
19
+ const bot = new bot_js_1.default(name, token, commands, scheduled, chats);
20
+ bots.push(bot);
21
+ return bot;
22
+ }
23
+ async function stopBots(reason) {
24
+ log(`Recieved termination code: ${reason}`);
25
+ taskScheduler_js_1.default.stopAll();
26
+ log('Acquiring storage semaphore...');
27
+ await storage_js_1.default.semaphoreInstance.acquire();
28
+ log('Stopping bots...');
29
+ for (const bot of bots) {
30
+ bot.stop(reason);
31
+ }
32
+ process.exit(0);
33
+ }
package/index.ts CHANGED
@@ -1,47 +1,3 @@
1
- import { readFile } from 'fs/promises';
2
- import BotInstance from './entities/bot.js';
3
- import taskScheduler from './services/taskScheduler.js';
4
- import { setTimeout } from 'timers/promises';
5
- import { Seconds } from './types/timeValues.js';
6
- import { secondsToMilliseconds } from './helpers/timeConvertions.js';
7
- import storage from './services/storage.js';
8
- import logger from './services/logger.js';
9
- import CommandAction from './entities/actions/commandAction.js';
10
- import IActionState from './types/actionState.js';
11
- import ScheduledAction from './entities/actions/scheduledAction.js';
12
-
13
- const bots: BotInstance[] = [];
14
-
15
- function log(text: string) {
16
- logger.logWithTraceId('ALL BOTS', 'System:Bot', 'System', text);
17
- }
18
-
19
- async function startBot(
20
- name: string,
21
- tokenFile: string,
22
- commands: CommandAction<IActionState>[],
23
- scheduled: ScheduledAction[],
24
- chats: Map<string, number>
25
- ) {
26
- const token = await readFile(tokenFile, 'utf8');
27
- const bot = new BotInstance(name, token, commands, scheduled, chats);
28
- bots.push(bot);
29
-
30
- return bot;
31
- }
32
-
33
- async function stopBots(reason: string) {
34
- log(`Recieved termination code: ${reason}`);
35
- taskScheduler.stopAll();
36
- log('Acquiring storage semaphore...');
37
- await storage.semaphoreInstance.acquire();
38
-
39
- log('Stopping bots...');
40
- for (const bot of bots) {
41
- bot.stop(reason);
42
- }
43
-
44
- process.exit(0);
45
- }
46
-
47
- export { startBot, stopBots };
1
+ export { startBot, stopBots } from './main';
2
+ export * from './helpers/builders/commandActionBuilder';
3
+ export * from './helpers/builders/scheduledActionBuilder';
package/main.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { readFile } from 'fs/promises';
2
+ import BotInstance from './entities/bot.js';
3
+ import taskScheduler from './services/taskScheduler.js';
4
+ import storage from './services/storage.js';
5
+ import logger from './services/logger.js';
6
+ import CommandAction from './entities/actions/commandAction.js';
7
+ import IActionState from './types/actionState.js';
8
+ import ScheduledAction from './entities/actions/scheduledAction.js';
9
+
10
+ const bots: BotInstance[] = [];
11
+
12
+ function log(text: string) {
13
+ logger.logWithTraceId('ALL BOTS', 'System:Bot', 'System', text);
14
+ }
15
+
16
+ async function startBot(
17
+ name: string,
18
+ tokenFile: string,
19
+ commands: CommandAction<IActionState>[],
20
+ scheduled: ScheduledAction[],
21
+ chats: Map<string, number>
22
+ ) {
23
+ const token = await readFile(tokenFile, 'utf8');
24
+ const bot = new BotInstance(name, token, commands, scheduled, chats);
25
+ bots.push(bot);
26
+
27
+ return bot;
28
+ }
29
+
30
+ async function stopBots(reason: string) {
31
+ log(`Recieved termination code: ${reason}`);
32
+ taskScheduler.stopAll();
33
+ log('Acquiring storage semaphore...');
34
+ await storage.semaphoreInstance.acquire();
35
+
36
+ log('Stopping bots...');
37
+ for (const bot of bots) {
38
+ bot.stop(reason);
39
+ }
40
+
41
+ process.exit(0);
42
+ }
43
+
44
+ export { startBot, stopBots };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chz-telegram-bot",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "async-sema": "^3.1.1",