chz-telegram-bot 0.0.10 → 0.0.12

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/main.d.ts CHANGED
@@ -3,7 +3,15 @@ import CommandAction from './entities/actions/commandAction.js';
3
3
  import IActionState from './types/actionState.js';
4
4
  import ScheduledAction from './entities/actions/scheduledAction.js';
5
5
  import { IStorageClient } from './types/storage.js';
6
- declare function startBot(name: string, tokenFilePath: string, commands: CommandAction<IActionState>[], scheduled: ScheduledAction[], chats: Map<string, number>, storageClient?: IStorageClient, storagePath?: string): Promise<BotInstance>;
6
+ declare function startBot(options: {
7
+ name: string;
8
+ tokenFilePath: string;
9
+ commands: CommandAction<IActionState>[];
10
+ scheduled: ScheduledAction[];
11
+ chats: Map<string, number>;
12
+ storageClient?: IStorageClient;
13
+ storagePath?: string;
14
+ }): Promise<BotInstance>;
7
15
  declare function stopBots(reason: string): Promise<void>;
8
16
  export { startBot, stopBots };
9
17
  //# sourceMappingURL=main.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAG5C,OAAO,aAAa,MAAM,qCAAqC,CAAC;AAChE,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,eAAe,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAQpD,iBAAe,QAAQ,CACnB,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,SAAS,EAAE,eAAe,EAAE,EAC5B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1B,aAAa,CAAC,EAAE,cAAc,EAC9B,WAAW,CAAC,EAAE,MAAM,wBAevB;AAED,iBAAe,QAAQ,CAAC,MAAM,EAAE,MAAM,iBASrC;AAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAG5C,OAAO,aAAa,MAAM,qCAAqC,CAAC;AAChE,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,eAAe,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAQpD,iBAAe,QAAQ,CAAC,OAAO,EAAE;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;IACxC,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,wBAcA;AAED,iBAAe,QAAQ,CAAC,MAAM,EAAE,MAAM,iBASrC;AAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC"}
package/dist/main.js CHANGED
@@ -13,16 +13,16 @@ const bots = [];
13
13
  function log(text) {
14
14
  logger_js_1.default.logWithTraceId('ALL BOTS', 'System:Bot', 'System', text);
15
15
  }
16
- async function startBot(name, tokenFilePath, commands, scheduled, chats, storageClient, storagePath) {
17
- const token = await (0, promises_1.readFile)(tokenFilePath, 'utf8');
16
+ async function startBot(options) {
17
+ const token = await (0, promises_1.readFile)(options.tokenFilePath, 'utf8');
18
18
  const bot = new bot_js_1.default({
19
- name,
19
+ name: options.name,
20
20
  token,
21
- commands,
22
- scheduled,
23
- chats,
24
- storageClient,
25
- storagePath
21
+ commands: options.commands,
22
+ scheduled: options.scheduled,
23
+ chats: options.chats,
24
+ storageClient: options.storageClient,
25
+ storagePath: options.storagePath
26
26
  });
27
27
  bots.push(bot);
28
28
  return bot;
@@ -10,9 +10,10 @@ class JsonFileStorage {
10
10
  this.cache = new Map();
11
11
  this.botName = botName;
12
12
  this.storagePath = path ?? 'storage';
13
- const folderName = (0, path_1.dirname)(`${this.storagePath}/${this.botName}/`);
14
- if (!(0, fs_1.existsSync)(folderName)) {
15
- (0, fs_1.mkdirSync)(folderName, { recursive: true });
13
+ if (!(0, fs_1.existsSync)(`${this.storagePath}/${this.botName}/`)) {
14
+ (0, fs_1.mkdirSync)(`${this.storagePath}/${this.botName}/`, {
15
+ recursive: true
16
+ });
16
17
  }
17
18
  }
18
19
  async lock(action) {
package/main.ts CHANGED
@@ -13,24 +13,24 @@ function log(text: string) {
13
13
  logger.logWithTraceId('ALL BOTS', 'System:Bot', 'System', text);
14
14
  }
15
15
 
16
- async function startBot(
17
- name: string,
18
- tokenFilePath: string,
19
- commands: CommandAction<IActionState>[],
20
- scheduled: ScheduledAction[],
21
- chats: Map<string, number>,
22
- storageClient?: IStorageClient,
23
- storagePath?: string
24
- ) {
25
- const token = await readFile(tokenFilePath, 'utf8');
16
+ async function startBot(options: {
17
+ name: string;
18
+ tokenFilePath: string;
19
+ commands: CommandAction<IActionState>[];
20
+ scheduled: ScheduledAction[];
21
+ chats: Map<string, number>;
22
+ storageClient?: IStorageClient;
23
+ storagePath?: string;
24
+ }) {
25
+ const token = await readFile(options.tokenFilePath, 'utf8');
26
26
  const bot = new BotInstance({
27
- name,
27
+ name: options.name,
28
28
  token,
29
- commands,
30
- scheduled,
31
- chats,
32
- storageClient,
33
- storagePath
29
+ commands: options.commands,
30
+ scheduled: options.scheduled,
31
+ chats: options.chats,
32
+ storageClient: options.storageClient,
33
+ storagePath: options.storagePath
34
34
  });
35
35
  bots.push(bot);
36
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chz-telegram-bot",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "async-sema": "^3.1.1",
@@ -19,10 +19,10 @@ export default class JsonFileStorage implements IStorageClient {
19
19
  this.botName = botName;
20
20
  this.storagePath = path ?? 'storage';
21
21
 
22
- const folderName = dirname(`${this.storagePath}/${this.botName}/`);
23
-
24
- if (!existsSync(folderName)) {
25
- mkdirSync(folderName, { recursive: true });
22
+ if (!existsSync(`${this.storagePath}/${this.botName}/`)) {
23
+ mkdirSync(`${this.storagePath}/${this.botName}/`, {
24
+ recursive: true
25
+ });
26
26
  }
27
27
  }
28
28