@aracna/telegram-bot 1.9.9 → 1.9.11

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.
@@ -10,7 +10,7 @@ class Download extends child_1.Child {
10
10
  file = await this.telegram.get.file(id);
11
11
  if (file instanceof Error)
12
12
  return file;
13
- buffer = await this.api.get(file.file_path || '');
13
+ buffer = await this.api.get(file.file_path ?? '');
14
14
  if (buffer instanceof Error)
15
15
  return buffer;
16
16
  return buffer.data;
@@ -3,7 +3,7 @@ import { Child } from '../modules/child';
3
3
  export declare class Polling extends Child {
4
4
  active: boolean;
5
5
  offset: number;
6
- start(ms: number | undefined, parameters: Partial<GetUpdates>): void;
6
+ start(ms?: number, parameters?: Partial<GetUpdates>): void;
7
7
  stop(): void;
8
8
  private get;
9
9
  }
@@ -1,11 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.REGEXP_COMMAND_WITH_USERNAME = exports.REGEXP_COMMAND = void 0;
4
- // export const REGEXP_ARRAY: RegExp = /^\[.+\]$/
5
4
  exports.REGEXP_COMMAND = /\/[a-z_]+/m;
6
5
  exports.REGEXP_COMMAND_WITH_USERNAME = /\/[a-zA-Z0-9_@]+/;
7
- // export const REGEXP_ID: RegExp = /^[a-z0-9]{16}$/
8
- // export const REGEXP_NUMBER: RegExp = /^(\+|-)?[0-9]+(\.[0-9])?[0-9]*$/
9
- // export const REGEXP_OBJECT: RegExp = /^\{.+\}$/
10
- // export const REGEXP_REPLY_TO_MESSAGE_CHAT_ID: RegExp = /:\s(\+|-)?[0-9]+/m
11
- // export const REGEXP_USERNAME: RegExp = /[a-zA-Z_0-9]{5,32}/
package/index.d.ts CHANGED
@@ -80,12 +80,6 @@ import { Update } from '@aracna/telegram-bot-types';
80
80
  import { User } from '@aracna/telegram-bot-types';
81
81
  import { UserProfilePhotos } from '@aracna/telegram-bot-types';
82
82
 
83
- declare class _ {
84
- api: ConfigurationAPI;
85
- default: ConfigurationDefault;
86
- handler: ConfigurationHandler;
87
- }
88
-
89
83
  declare class Add extends Child {
90
84
  stickerToSet(userID: number, name: string, sticker: InputSticker, parameters: Partial<AddStickerToSet>): Promise<Message | FetchError>;
91
85
  }
@@ -155,6 +149,12 @@ declare interface ConfigurationAPI {
155
149
  };
156
150
  }
157
151
 
152
+ declare class ConfigurationBuilder {
153
+ api: ConfigurationAPI;
154
+ default: ConfigurationDefault;
155
+ handler: ConfigurationHandler;
156
+ }
157
+
158
158
  declare interface ConfigurationDefault {
159
159
  buttons: {
160
160
  text: (chatID: number) => Promise<InlineKeyboardButton[]>;
@@ -273,7 +273,7 @@ export declare interface HandlerOptions {
273
273
  export declare class HTMLUtils {
274
274
  static tags: string[];
275
275
  static sanitize(text: string): string;
276
- static progress(value: number, minimum?: number, maximum?: number, size?: number): string;
276
+ static progress(value: number, min?: number, max?: number, size?: number): string;
277
277
  }
278
278
 
279
279
  export declare class InlineKeyboardUtils {
@@ -303,7 +303,7 @@ declare class Pin extends Child {
303
303
  declare class Polling extends Child {
304
304
  active: boolean;
305
305
  offset: number;
306
- start(ms: number | undefined, parameters: Partial<GetUpdates>): void;
306
+ start(ms?: number, parameters?: Partial<GetUpdates>): void;
307
307
  stop(): void;
308
308
  private get;
309
309
  }
@@ -446,7 +446,7 @@ export declare class Telegram {
446
446
  private get handlerIDs();
447
447
  }
448
448
 
449
- export declare const TelegramConfiguration: _;
449
+ export declare const TelegramConfiguration: ConfigurationBuilder;
450
450
 
451
451
  export declare enum TelegramLoggerName {
452
452
  MODULE = "TELEGRAM_MODULE"
@@ -1,8 +1,8 @@
1
1
  import { ConfigurationAPI, ConfigurationDefault, ConfigurationHandler } from '../definitions/interfaces';
2
- declare class _ {
2
+ declare class ConfigurationBuilder {
3
3
  api: ConfigurationAPI;
4
4
  default: ConfigurationDefault;
5
5
  handler: ConfigurationHandler;
6
6
  }
7
- export declare const Configuration: _;
7
+ export declare const Configuration: ConfigurationBuilder;
8
8
  export {};
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Configuration = void 0;
4
4
  const dummy_1 = require("./dummy");
5
- class _ {
5
+ class ConfigurationBuilder {
6
6
  api = dummy_1.Dummy.configurationAPI;
7
7
  default = dummy_1.Dummy.configurationDefault;
8
8
  handler = dummy_1.Dummy.configurationHandler;
9
9
  }
10
- exports.Configuration = new _();
10
+ exports.Configuration = new ConfigurationBuilder();
@@ -105,8 +105,8 @@ class Telegram {
105
105
  return;
106
106
  this.id = v.id;
107
107
  this.name.first = v.first_name;
108
- this.name.last = v.last_name || '';
109
- this.username = v.username || '';
108
+ this.name.last = v.last_name ?? '';
109
+ this.username = v.username ?? '';
110
110
  });
111
111
  }
112
112
  on(type, middleware, key, description, options) {
@@ -117,7 +117,7 @@ class Telegram {
117
117
  handler.key = key;
118
118
  handler.middleware = middleware;
119
119
  handler.type = type;
120
- handler.options = (0, core_1.mergeObjects)(handler.options, options || {});
120
+ handler.options = (0, core_1.mergeObjects)(handler.options, options ?? {});
121
121
  potential = this.findMatchingHandler(handler.type, handler.key);
122
122
  potential.id ? (potential.middleware = middleware) : this.handlers.push(handler);
123
123
  module_logger_1.ModuleLogger.debug('Telegram', 'register', `The handler has been registered.`, handler);
@@ -305,7 +305,7 @@ class Telegram {
305
305
  }
306
306
  handleReplyToMessage(reply) {
307
307
  let body, handler;
308
- body = reply_to_message_utils_1.ReplyToMessageUtils.decodeBody(reply.reply_to_message?.entities || []);
308
+ body = reply_to_message_utils_1.ReplyToMessageUtils.decodeBody(reply.reply_to_message?.entities ?? []);
309
309
  (0, core_1.setObjectProperty)(reply, 'body', body);
310
310
  handler = this.findMatchingHandler(enums_1.UpdateType.REPLY_TO_MESSAGE, body.type);
311
311
  if (!handler.id)
@@ -334,17 +334,17 @@ class Telegram {
334
334
  return handler;
335
335
  handler.middleware(start);
336
336
  if (handler.id.length > 0 && handler.options.deleteOnMessageStart) {
337
- this.delete.message(body.chatID ? start.from?.id || 0 : start.chat.id, start.message_id);
337
+ this.delete.message(body.chatID ? start.from?.id ?? 0 : start.chat.id, start.message_id);
338
338
  }
339
339
  return handler;
340
340
  }
341
341
  findMatchingHandler(type, key = '') {
342
- return this.handlers.find((v) => v.key === key && v.type === type) || dummy_1.Dummy.handler;
342
+ return this.handlers.find((v) => v.key === key && v.type === type) ?? dummy_1.Dummy.handler;
343
343
  }
344
344
  get commands() {
345
345
  return this.handlers
346
346
  .filter((v) => v.key && v.type === enums_1.UpdateType.MESSAGE)
347
- .map((v) => ({ command: v.key || '', description: v.description || '' }));
347
+ .map((v) => ({ command: v.key ?? '', description: v.description ?? '' }));
348
348
  }
349
349
  get handlerIDs() {
350
350
  return this.handlers.reduce((r, v) => [...r, v.id], []);
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "author": "Dario Sechi",
3
3
  "devDependencies": {
4
- "@aracna/core": "^1.1.73",
5
- "@aracna/telegram-bot-types": "^1.2.9",
4
+ "@aracna/core": "^1.1.77",
5
+ "@aracna/telegram-bot-types": "^1.2.10",
6
6
  "@microsoft/api-extractor": "^7.39.0",
7
7
  "@types/node": "^20.10.5",
8
8
  "@vitest/coverage-v8": "^1.1.0",
@@ -12,6 +12,10 @@
12
12
  "typescript": "^5.3.3",
13
13
  "vitest": "^1.1.0"
14
14
  },
15
+ "engines": {
16
+ "node": ">=16",
17
+ "pnpm": ">=8"
18
+ },
15
19
  "license": "MIT",
16
20
  "main": "index.js",
17
21
  "name": "@aracna/telegram-bot",
@@ -23,7 +27,7 @@
23
27
  "directory": "dist"
24
28
  },
25
29
  "types": "index.d.ts",
26
- "version": "1.9.9",
30
+ "version": "1.9.11",
27
31
  "scripts": {
28
32
  "build": "rm -rf dist && pnpm tsc && pnpm api-extractor run --local",
29
33
  "prepublish": "pnpm test && pnpm build && pnpm version patch && cp LICENSE package.json README.md dist",
@@ -20,7 +20,7 @@ class CommandUtils {
20
20
  return this.get(string);
21
21
  }
22
22
  static get(string) {
23
- return (constants_1.REGEXP_COMMAND.exec(string?.slice(0, 512) || '') || [''])[0].slice(1);
23
+ return (constants_1.REGEXP_COMMAND.exec(string?.slice(0, 512) ?? '') ?? [''])[0].slice(1);
24
24
  }
25
25
  static omit(string) {
26
26
  return string.replace(constants_1.REGEXP_COMMAND_WITH_USERNAME, '').trim();
@@ -26,10 +26,10 @@ class ContextUtils {
26
26
  return this.getUser(context).first_name;
27
27
  }
28
28
  static getUserLastName(context) {
29
- return this.getUser(context).last_name || '';
29
+ return this.getUser(context).last_name ?? '';
30
30
  }
31
31
  static getUserUsername(context) {
32
- return this.getUser(context).username || '';
32
+ return this.getUser(context).username ?? '';
33
33
  }
34
34
  static getUser(context) {
35
35
  switch (true) {
@@ -1,5 +1,5 @@
1
1
  export declare class HTMLUtils {
2
2
  static tags: string[];
3
3
  static sanitize(text: string): string;
4
- static progress(value: number, minimum?: number, maximum?: number, size?: number): string;
4
+ static progress(value: number, min?: number, max?: number, size?: number): string;
5
5
  }
@@ -10,10 +10,10 @@ class HTMLUtils {
10
10
  .replace(new RegExp(`(?<!(${this.tags.join('|')}))>`, 'gm'), '&gt;')
11
11
  .replace(/&/gm, '&amp;');
12
12
  }
13
- static progress(value, minimum = 0, maximum = 100, size = 20) {
13
+ static progress(value, min = 0, max = 100, size = 20) {
14
14
  let percentage, steps;
15
- percentage = (0, core_1.getNumberPercentage)(value, minimum, maximum);
16
- steps = new Array(size).fill(0).map((v, k) => ((k * maximum) / size < percentage ? '=' : ' '));
15
+ percentage = (0, core_1.getNumberPercentage)(value, { min, max });
16
+ steps = new Array(size).fill(0).map((v, k) => ((k * max) / size < percentage ? '=' : ' '));
17
17
  return `<code>[${steps.join('')}]</code>`;
18
18
  }
19
19
  }
@@ -7,7 +7,7 @@ class ReplyToMessageUtils {
7
7
  static decodeBody(entities) {
8
8
  let entity, encoded, body;
9
9
  entity = entities[entities.length - 1];
10
- if (!entity || !entity.url)
10
+ if (!entity?.url)
11
11
  return dummy_1.Dummy.messageBody;
12
12
  encoded = entity.url.replace('https://t.me/?a=', '');
13
13
  body = (0, core_1.tc)(() => JSON.parse(Buffer.from(encoded, 'base64').toString()));