chz-telegram-bot 0.3.10 → 0.3.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.
Files changed (127) hide show
  1. package/builtin/helpAction.ts +1 -1
  2. package/dist/builtin/helpAction.js +1 -1
  3. package/dist/dtos/chatInfo.js +4 -0
  4. package/dist/dtos/commandTriggerCheckResult.js +3 -0
  5. package/dist/dtos/incomingMessage.js +9 -1
  6. package/dist/dtos/incomingQuery.js +5 -0
  7. package/dist/dtos/replyInfo.js +2 -0
  8. package/dist/dtos/responses/delay.js +6 -2
  9. package/dist/dtos/responses/imageMessage.js +10 -4
  10. package/dist/dtos/responses/inlineQueryResponse.js +6 -2
  11. package/dist/dtos/responses/reaction.js +7 -2
  12. package/dist/dtos/responses/textMessage.js +10 -3
  13. package/dist/dtos/responses/unpin.js +6 -2
  14. package/dist/dtos/responses/videoMessage.js +10 -4
  15. package/dist/entities/actions/commandAction.d.ts +4 -1
  16. package/dist/entities/actions/commandAction.d.ts.map +1 -1
  17. package/dist/entities/actions/commandAction.js +46 -17
  18. package/dist/entities/actions/inlineQueryAction.d.ts.map +1 -1
  19. package/dist/entities/actions/inlineQueryAction.js +8 -1
  20. package/dist/entities/actions/replyCaptureAction.d.ts.map +1 -1
  21. package/dist/entities/actions/replyCaptureAction.js +8 -1
  22. package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
  23. package/dist/entities/actions/scheduledAction.js +13 -14
  24. package/dist/entities/botInstance.js +6 -1
  25. package/dist/entities/cachedStateFactory.js +2 -0
  26. package/dist/entities/context/baseContext.js +14 -2
  27. package/dist/entities/context/chatContext.d.ts +0 -3
  28. package/dist/entities/context/chatContext.d.ts.map +1 -1
  29. package/dist/entities/context/chatContext.js +38 -41
  30. package/dist/entities/context/inlineQueryContext.d.ts +0 -3
  31. package/dist/entities/context/inlineQueryContext.d.ts.map +1 -1
  32. package/dist/entities/context/inlineQueryContext.js +12 -6
  33. package/dist/entities/context/messageContext.d.ts +0 -3
  34. package/dist/entities/context/messageContext.d.ts.map +1 -1
  35. package/dist/entities/context/messageContext.js +77 -68
  36. package/dist/entities/context/replyContext.d.ts +0 -3
  37. package/dist/entities/context/replyContext.d.ts.map +1 -1
  38. package/dist/entities/context/replyContext.js +90 -65
  39. package/dist/entities/states/actionStateBase.js +2 -4
  40. package/dist/entities/taskRecord.js +3 -0
  41. package/dist/helpers/builders/commandActionBuilder.d.ts +3 -0
  42. package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
  43. package/dist/helpers/builders/commandActionBuilder.js +18 -9
  44. package/dist/helpers/builders/inlineQueryActionBuilder.js +7 -6
  45. package/dist/helpers/builders/scheduledActionBuilder.js +7 -5
  46. package/dist/helpers/mapUtils.d.ts +3 -0
  47. package/dist/helpers/mapUtils.d.ts.map +1 -0
  48. package/dist/helpers/mapUtils.js +17 -0
  49. package/dist/helpers/noop.d.ts +3 -4
  50. package/dist/helpers/noop.d.ts.map +1 -1
  51. package/dist/helpers/noop.js +2 -1
  52. package/dist/helpers/traceFactory.d.ts +1 -1
  53. package/dist/helpers/traceFactory.d.ts.map +1 -1
  54. package/dist/main.js +1 -3
  55. package/dist/services/actionProcessingService.d.ts.map +1 -1
  56. package/dist/services/actionProcessingService.js +15 -3
  57. package/dist/services/actionProcessors/baseProcessor.d.ts +1 -3
  58. package/dist/services/actionProcessors/baseProcessor.d.ts.map +1 -1
  59. package/dist/services/actionProcessors/baseProcessor.js +6 -2
  60. package/dist/services/actionProcessors/commandActionProcessor.d.ts +0 -4
  61. package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
  62. package/dist/services/actionProcessors/commandActionProcessor.js +10 -13
  63. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +0 -4
  64. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +1 -1
  65. package/dist/services/actionProcessors/inlineQueryActionProcessor.js +4 -6
  66. package/dist/services/actionProcessors/scheduledActionProcessor.js +6 -4
  67. package/dist/services/jsonFileStorage.d.ts +4 -3
  68. package/dist/services/jsonFileStorage.d.ts.map +1 -1
  69. package/dist/services/jsonFileStorage.js +22 -14
  70. package/dist/services/jsonLogger.d.ts +1 -1
  71. package/dist/services/jsonLogger.d.ts.map +1 -1
  72. package/dist/services/jsonLogger.js +9 -3
  73. package/dist/services/nodeTimeoutScheduler.d.ts +2 -2
  74. package/dist/services/nodeTimeoutScheduler.d.ts.map +1 -1
  75. package/dist/services/nodeTimeoutScheduler.js +6 -5
  76. package/dist/services/responseProcessingQueue.d.ts.map +1 -1
  77. package/dist/services/responseProcessingQueue.js +9 -7
  78. package/dist/services/telegramApi.d.ts.map +1 -1
  79. package/dist/services/telegramApi.js +17 -8
  80. package/dist/types/commandTrigger.d.ts +1 -2
  81. package/dist/types/commandTrigger.d.ts.map +1 -1
  82. package/dist/types/handlers.d.ts +1 -1
  83. package/dist/types/handlers.d.ts.map +1 -1
  84. package/dist/types/logger.d.ts +2 -2
  85. package/dist/types/logger.d.ts.map +1 -1
  86. package/dist/types/scheduler.d.ts +2 -2
  87. package/dist/types/scheduler.d.ts.map +1 -1
  88. package/dist/types/storage.d.ts +2 -2
  89. package/dist/types/storage.d.ts.map +1 -1
  90. package/dist/types/timeValues.d.ts +3 -3
  91. package/dist/types/timeValues.d.ts.map +1 -1
  92. package/dist/types/trace.d.ts +1 -1
  93. package/dist/types/trace.d.ts.map +1 -1
  94. package/dtos/incomingMessage.ts +1 -1
  95. package/entities/actions/commandAction.ts +55 -28
  96. package/entities/actions/inlineQueryAction.ts +5 -1
  97. package/entities/actions/replyCaptureAction.ts +5 -1
  98. package/entities/actions/scheduledAction.ts +11 -13
  99. package/entities/botInstance.ts +7 -7
  100. package/entities/context/chatContext.ts +0 -6
  101. package/entities/context/inlineQueryContext.ts +0 -6
  102. package/entities/context/messageContext.ts +0 -6
  103. package/entities/context/replyContext.ts +18 -15
  104. package/eslint.config.js +26 -1
  105. package/helpers/builders/commandActionBuilder.ts +10 -0
  106. package/helpers/mapUtils.ts +15 -0
  107. package/helpers/noop.ts +4 -4
  108. package/helpers/traceFactory.ts +2 -2
  109. package/package.json +1 -1
  110. package/services/actionProcessingService.ts +8 -4
  111. package/services/actionProcessors/baseProcessor.ts +5 -8
  112. package/services/actionProcessors/commandActionProcessor.ts +5 -17
  113. package/services/actionProcessors/inlineQueryActionProcessor.ts +5 -15
  114. package/services/actionProcessors/scheduledActionProcessor.ts +4 -4
  115. package/services/jsonFileStorage.ts +39 -21
  116. package/services/jsonLogger.ts +12 -8
  117. package/services/nodeTimeoutScheduler.ts +6 -6
  118. package/services/responseProcessingQueue.ts +9 -4
  119. package/services/telegramApi.ts +7 -5
  120. package/tsconfig.json +1 -1
  121. package/types/commandTrigger.ts +1 -3
  122. package/types/handlers.ts +1 -1
  123. package/types/logger.ts +3 -6
  124. package/types/scheduler.ts +2 -2
  125. package/types/storage.ts +2 -2
  126. package/types/timeValues.ts +3 -3
  127. package/types/trace.ts +3 -1
@@ -4,7 +4,7 @@ import { Seconds } from '../types/timeValues';
4
4
  export function buildHelpCommand(readmes: string[], botUsername: string) {
5
5
  return new CommandActionBuilder('Reaction.Help')
6
6
  .on(['/help', `/help@${botUsername}`])
7
- .do(async (ctx) => {
7
+ .do((ctx) => {
8
8
  if (readmes.length == 0) return;
9
9
 
10
10
  ctx.reply.withText(readmes.join('\n\n'));
@@ -5,7 +5,7 @@ const commandActionBuilder_1 = require("../helpers/builders/commandActionBuilder
5
5
  function buildHelpCommand(readmes, botUsername) {
6
6
  return new commandActionBuilder_1.CommandActionBuilder('Reaction.Help')
7
7
  .on(['/help', `/help@${botUsername}`])
8
- .do(async (ctx) => {
8
+ .do((ctx) => {
9
9
  if (readmes.length == 0)
10
10
  return;
11
11
  ctx.reply.withText(readmes.join('\n\n'));
@@ -2,6 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChatInfo = void 0;
4
4
  class ChatInfo {
5
+ /** Id of a chat that action is executed in. */
6
+ id;
7
+ /** Name of a chat that action is executed in. */
8
+ name;
5
9
  constructor(chatId, chatName) {
6
10
  this.id = chatId;
7
11
  this.name = chatName;
@@ -11,6 +11,9 @@ class CommandTriggerCheckResult {
11
11
  static get Trigger() {
12
12
  return new CommandTriggerCheckResult(true, [], false);
13
13
  }
14
+ shouldExecute;
15
+ matchResults;
16
+ skipCooldown;
14
17
  constructor(shouldExecute, matchResults, skipCooldown) {
15
18
  this.shouldExecute = shouldExecute;
16
19
  this.matchResults = matchResults;
@@ -6,6 +6,14 @@ const messageTypes_1 = require("../types/messageTypes");
6
6
  const chatInfo_1 = require("./chatInfo");
7
7
  const traceFactory_1 = require("../helpers/traceFactory");
8
8
  class IncomingMessage {
9
+ messageId;
10
+ chatInfo;
11
+ from;
12
+ text;
13
+ type;
14
+ traceId;
15
+ replyToMessageId;
16
+ updateObject;
9
17
  detectMessageType(message) {
10
18
  if ('forward_origin' in message)
11
19
  return messageTypes_1.MessageType.Forward;
@@ -50,7 +58,7 @@ class IncomingMessage {
50
58
  ? ctxMessage.caption ?? ''
51
59
  : '';
52
60
  this.chatInfo = new chatInfo_1.ChatInfo(ctxMessage.chat.id, 'title' in ctxMessage.chat
53
- ? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
61
+ ? `${ctxMessage.chat.title} ${ctxMessage.chat.id}`
54
62
  : 'DM');
55
63
  this.type = this.detectMessageType(ctxMessage);
56
64
  this.updateObject = ctxMessage;
@@ -2,6 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IncomingInlineQuery = void 0;
4
4
  class IncomingInlineQuery {
5
+ queryId;
6
+ query;
7
+ userId;
8
+ traceId;
9
+ abortController;
5
10
  constructor(queryId, query, userId, traceId) {
6
11
  this.queryId = queryId;
7
12
  this.query = query;
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReplyInfo = void 0;
4
4
  class ReplyInfo {
5
+ id;
6
+ quote;
5
7
  constructor(id, quote) {
6
8
  this.id = id;
7
9
  this.quote = quote;
@@ -3,9 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DelayResponse = void 0;
4
4
  const response_1 = require("../../types/response");
5
5
  class DelayResponse {
6
+ kind = response_1.BotResponseTypes.delay;
7
+ createdAt = Date.now();
8
+ chatInfo;
9
+ traceId;
10
+ delay;
11
+ action;
6
12
  constructor(delay, chatInfo, traceId, action) {
7
- this.kind = response_1.BotResponseTypes.delay;
8
- this.createdAt = Date.now();
9
13
  this.chatInfo = chatInfo;
10
14
  this.delay = delay;
11
15
  this.traceId = traceId;
@@ -3,11 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImageMessage = void 0;
4
4
  const response_1 = require("../../types/response");
5
5
  class ImageMessage {
6
+ kind = response_1.BotResponseTypes.image;
7
+ createdAt = Date.now();
8
+ captures = [];
9
+ content;
10
+ chatInfo;
11
+ replyInfo;
12
+ traceId;
13
+ disableWebPreview = false;
14
+ shouldPin;
15
+ action;
6
16
  constructor(image, chatInfo, traceId, action, replyInfo, options) {
7
- this.kind = response_1.BotResponseTypes.image;
8
- this.createdAt = Date.now();
9
- this.captures = [];
10
- this.disableWebPreview = false;
11
17
  this.content = image;
12
18
  this.chatInfo = chatInfo;
13
19
  this.replyInfo = replyInfo;
@@ -3,9 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InlineQueryResponse = void 0;
4
4
  const response_1 = require("../../types/response");
5
5
  class InlineQueryResponse {
6
+ kind = response_1.BotResponseTypes.inlineQuery;
7
+ createdAt = Date.now();
8
+ queryId;
9
+ traceId;
10
+ action;
11
+ queryResults;
6
12
  constructor(queryResult, queryId, traceId, action) {
7
- this.kind = response_1.BotResponseTypes.inlineQuery;
8
- this.createdAt = Date.now();
9
13
  this.queryResults = queryResult;
10
14
  this.queryId = queryId;
11
15
  this.traceId = traceId;
@@ -3,9 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Reaction = void 0;
4
4
  const response_1 = require("../../types/response");
5
5
  class Reaction {
6
+ kind = response_1.BotResponseTypes.react;
7
+ createdAt = Date.now();
8
+ chatInfo;
9
+ messageId;
10
+ traceId;
11
+ emoji;
12
+ action;
6
13
  constructor(traceId, chatInfo, messageId, emoji, action) {
7
- this.kind = response_1.BotResponseTypes.react;
8
- this.createdAt = Date.now();
9
14
  this.chatInfo = chatInfo;
10
15
  this.messageId = messageId;
11
16
  this.emoji = emoji;
@@ -3,10 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TextMessage = void 0;
4
4
  const response_1 = require("../../types/response");
5
5
  class TextMessage {
6
+ kind = response_1.BotResponseTypes.text;
7
+ createdAt = Date.now();
8
+ captures = [];
9
+ content;
10
+ chatInfo;
11
+ replyInfo;
12
+ traceId;
13
+ disableWebPreview;
14
+ shouldPin;
15
+ action;
6
16
  constructor(text, chatInfo, traceId, action, replyInfo, options) {
7
- this.kind = response_1.BotResponseTypes.text;
8
- this.createdAt = Date.now();
9
- this.captures = [];
10
17
  this.content = text;
11
18
  this.chatInfo = chatInfo;
12
19
  this.replyInfo = replyInfo;
@@ -3,9 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UnpinResponse = void 0;
4
4
  const response_1 = require("../../types/response");
5
5
  class UnpinResponse {
6
+ kind = response_1.BotResponseTypes.unpin;
7
+ createdAt = Date.now();
8
+ messageId;
9
+ chatInfo;
10
+ traceId;
11
+ action;
6
12
  constructor(messageId, chatInfo, traceId, action) {
7
- this.kind = response_1.BotResponseTypes.unpin;
8
- this.createdAt = Date.now();
9
13
  this.messageId = messageId;
10
14
  this.chatInfo = chatInfo;
11
15
  this.traceId = traceId;
@@ -3,11 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VideoMessage = void 0;
4
4
  const response_1 = require("../../types/response");
5
5
  class VideoMessage {
6
+ kind = response_1.BotResponseTypes.video;
7
+ createdAt = Date.now();
8
+ captures = [];
9
+ content;
10
+ chatInfo;
11
+ replyInfo;
12
+ traceId;
13
+ disableWebPreview = false;
14
+ shouldPin;
15
+ action;
6
16
  constructor(video, chatInfo, traceId, action, replyInfo, options) {
7
- this.kind = response_1.BotResponseTypes.video;
8
- this.createdAt = Date.now();
9
- this.captures = [];
10
- this.disableWebPreview = false;
11
17
  this.content = video;
12
18
  this.chatInfo = chatInfo;
13
19
  this.replyInfo = replyInfo;
@@ -5,7 +5,9 @@ import { IActionState } from '../../types/actionState';
5
5
  import { IActionWithState, ActionKey } from '../../types/action';
6
6
  import { MessageContext } from '../context/messageContext';
7
7
  import { CommandTrigger } from '../../types/commandTrigger';
8
+ import { Sema as Semaphore } from 'async-sema';
8
9
  export declare class CommandAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
10
+ readonly ratelimitSemaphores: Map<number, Semaphore>;
9
11
  readonly triggers: CommandTrigger[];
10
12
  readonly handler: CommandHandler<TActionState>;
11
13
  readonly name: string;
@@ -17,7 +19,8 @@ export declare class CommandAction<TActionState extends IActionState> implements
17
19
  readonly stateConstructor: () => TActionState;
18
20
  readonly key: ActionKey;
19
21
  readonly readmeFactory: (botName: string) => string;
20
- constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState, readmeFactory: (botName: string) => string);
22
+ readonly maxAllowedSimultaniousExecutions: number;
23
+ constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], maxAllowedSimultaniousExecutions: number, condition: CommandCondition<TActionState>, stateConstructor: () => TActionState, readmeFactory: (botName: string) => string);
21
24
  exec(ctx: MessageContext<TActionState>): Promise<import("../../types/response").BotResponse[]>;
22
25
  private checkIfShouldBeExecuted;
23
26
  private checkTrigger;
@@ -1 +1 @@
1
- {"version":3,"file":"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,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IACpD,QAAQ,CAAC,gCAAgC,EAAE,MAAM,CAAC;gBAG9C,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,EAC1C,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO,EACjB,cAAc,EAAE,MAAM,EAAE,EACxB,YAAY,EAAE,MAAM,EAAE,EACtB,gCAAgC,EAAE,MAAM,EACxC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY,EACpC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM;IAkBxC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC;IA8D5C,OAAO,CAAC,uBAAuB;IA+B/B,OAAO,CAAC,YAAY;CAuCvB"}
@@ -10,8 +10,23 @@ const toArray_1 = require("../../helpers/toArray");
10
10
  const commandTriggerCheckResult_1 = require("../../dtos/commandTriggerCheckResult");
11
11
  const noop_1 = require("../../helpers/noop");
12
12
  const messageTypes_1 = require("../../types/messageTypes");
13
+ const async_sema_1 = require("async-sema");
14
+ const mapUtils_1 = require("../../helpers/mapUtils");
13
15
  class CommandAction {
14
- constructor(trigger, handler, name, active, cooldown, chatsBlacklist, allowedUsers, condition, stateConstructor, readmeFactory) {
16
+ ratelimitSemaphores = new Map();
17
+ triggers;
18
+ handler;
19
+ name;
20
+ cooldownInSeconds;
21
+ active;
22
+ chatsBlacklist;
23
+ allowedUsers;
24
+ condition;
25
+ stateConstructor;
26
+ key;
27
+ readmeFactory;
28
+ maxAllowedSimultaniousExecutions;
29
+ constructor(trigger, handler, name, active, cooldown, chatsBlacklist, allowedUsers, maxAllowedSimultaniousExecutions, condition, stateConstructor, readmeFactory) {
15
30
  this.triggers = (0, toArray_1.toArray)(trigger);
16
31
  this.handler = handler;
17
32
  this.name = name;
@@ -22,6 +37,8 @@ class CommandAction {
22
37
  this.condition = condition;
23
38
  this.stateConstructor = stateConstructor;
24
39
  this.readmeFactory = readmeFactory;
40
+ this.maxAllowedSimultaniousExecutions =
41
+ maxAllowedSimultaniousExecutions;
25
42
  this.key = `command:${this.name.replace('.', '-')}`;
26
43
  }
27
44
  async exec(ctx) {
@@ -29,23 +46,33 @@ class CommandAction {
29
46
  throw new Error(`Context for ${this.key} is not initialized or already consumed`);
30
47
  if (!this.active || this.chatsBlacklist.includes(ctx.chatInfo.id))
31
48
  return noop_1.Noop.NoResponse;
32
- const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
33
- const { shouldExecute, matchResults, skipCooldown } = this.triggers
34
- .map((x) => this.checkIfShouldBeExecuted(ctx, x, state))
35
- .reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger);
36
- if (!shouldExecute)
37
- return noop_1.Noop.NoResponse;
38
- ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
39
- ctx.matchResults = matchResults;
40
- await this.handler(ctx, state);
41
- if (skipCooldown) {
42
- ctx.startCooldown = false;
49
+ let lock;
50
+ if (this.maxAllowedSimultaniousExecutions != 0) {
51
+ lock = (0, mapUtils_1.getOrSetIfNotExists)(this.ratelimitSemaphores, ctx.chatInfo.id, new async_sema_1.Sema(this.maxAllowedSimultaniousExecutions));
52
+ await lock.acquire();
53
+ }
54
+ try {
55
+ const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
56
+ const { shouldExecute, matchResults, skipCooldown } = this.triggers
57
+ .map((x) => this.checkIfShouldBeExecuted(ctx, x, state))
58
+ .reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger);
59
+ if (!shouldExecute)
60
+ return noop_1.Noop.NoResponse;
61
+ ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
62
+ ctx.matchResults = matchResults;
63
+ await this.handler(ctx, state);
64
+ if (skipCooldown) {
65
+ ctx.startCooldown = false;
66
+ }
67
+ if (ctx.startCooldown) {
68
+ state.lastExecutedDate = (0, moment_1.default)().valueOf();
69
+ }
70
+ await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
71
+ return ctx.responses;
43
72
  }
44
- if (ctx.startCooldown) {
45
- state.lastExecutedDate = (0, moment_1.default)().valueOf();
73
+ finally {
74
+ lock?.release();
46
75
  }
47
- await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
48
- return ctx.responses;
49
76
  }
50
77
  checkIfShouldBeExecuted(ctx, trigger, state) {
51
78
  if (!ctx.fromUserId)
@@ -75,13 +102,15 @@ class CommandAction {
75
102
  trigger.lastIndex = 0;
76
103
  const execResult = trigger.exec(ctx.messageText);
77
104
  if (execResult != null) {
105
+ let regexMatchLimit = 100;
78
106
  matchResults.push(execResult);
79
107
  if (trigger.global) {
80
- while (true) {
108
+ while (regexMatchLimit > 0) {
81
109
  const nextResult = trigger.exec(ctx.messageText);
82
110
  if (nextResult == null)
83
111
  break;
84
112
  matchResults.push(nextResult);
113
+ regexMatchLimit -= 1;
85
114
  }
86
115
  }
87
116
  }
@@ -1 +1 @@
1
- {"version":3,"file":"inlineQueryAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/inlineQueryAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBAAa,iBAAkB,YAAW,OAAO;IAC7C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAGrB,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,MAAM;IAUb,IAAI,CAAC,GAAG,EAAE,kBAAkB;CAmCrC"}
1
+ {"version":3,"file":"inlineQueryAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/inlineQueryAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBAAa,iBAAkB,YAAW,OAAO;IAC7C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAGrB,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,MAAM;IAUb,IAAI,CAAC,GAAG,EAAE,kBAAkB;CAuCrC"}
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InlineQueryAction = void 0;
4
4
  const noop_1 = require("../../helpers/noop");
5
5
  class InlineQueryAction {
6
+ key;
7
+ active;
8
+ handler;
9
+ name;
10
+ pattern;
6
11
  constructor(handler, name, active, pattern) {
7
12
  this.handler = handler;
8
13
  this.name = name;
@@ -19,13 +24,15 @@ class InlineQueryAction {
19
24
  this.pattern.lastIndex = 0;
20
25
  const execResult = this.pattern.exec(ctx.queryText);
21
26
  if (execResult != null) {
27
+ let regexMatchLimit = 100;
22
28
  matchResults.push(execResult);
23
29
  if (this.pattern.global) {
24
- while (true) {
30
+ while (regexMatchLimit > 0) {
25
31
  const nextResult = this.pattern.exec(ctx.queryText);
26
32
  if (nextResult == null)
27
33
  break;
28
34
  matchResults.push(nextResult);
35
+ regexMatchLimit -= 1;
29
36
  }
30
37
  }
31
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"replyCaptureAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/replyCaptureAction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,qBAAa,kBAAkB,CAAC,kBAAkB,SAAS,YAAY,CACnE,YAAW,OAAO;IAElB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,CACd,YAAY,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAC7C,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;gBAGtC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,gBAAgB,CAAC,kBAA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AC,uBAAuB;CA0ClC"}
@@ -4,6 +4,11 @@ exports.ReplyCaptureAction = void 0;
4
4
  const commandTriggerCheckResult_1 = require("../../dtos/commandTriggerCheckResult");
5
5
  const noop_1 = require("../../helpers/noop");
6
6
  class ReplyCaptureAction {
7
+ parentMessageId;
8
+ key;
9
+ handler;
10
+ triggers;
11
+ abortController;
7
12
  constructor(parentMessageId, parentAction, handler, triggers, abortController) {
8
13
  this.parentMessageId = parentMessageId;
9
14
  this.handler = handler;
@@ -40,13 +45,15 @@ class ReplyCaptureAction {
40
45
  trigger.lastIndex = 0;
41
46
  const execResult = trigger.exec(ctx.messageText);
42
47
  if (execResult != null) {
48
+ let regexMatchLimit = 100;
43
49
  matchResults.push(execResult);
44
50
  if (trigger.global) {
45
- while (true) {
51
+ while (regexMatchLimit > 0) {
46
52
  const nextResult = trigger.exec(ctx.messageText);
47
53
  if (nextResult == null)
48
54
  break;
49
55
  matchResults.push(nextResult);
56
+ regexMatchLimit -= 1;
50
57
  }
51
58
  }
52
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scheduledAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/scheduledAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAIrD,qBAAa,eAAe,CAAC,YAAY,SAAS,YAAY,CAC1D,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,MAAM,CAAC,QAAQ,CAAC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AC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAKrD,qBAAa,eAAe,CAAC,YAAY,SAAS,YAAY,CAC1D,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,MAAM,CAAC,QAAQ,CAAC,KAAK,yBAAgC;IAErD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IAExB,QAAQ,CAAC,WAAW,uBAA8B;IAClD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG7C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACvC,WAAW,EAAE,UAAU,EACvB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EAAE,EACnB,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EACrD,gBAAgB,EAAE,MAAM,YAAY;IAYlC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC;YAuC3B,cAAc;IA4C5B,OAAO,CAAC,uBAAuB;CAalC"}
@@ -8,9 +8,19 @@ const moment_1 = __importDefault(require("moment"));
8
8
  const async_sema_1 = require("async-sema");
9
9
  const timeConvertions_1 = require("../../helpers/timeConvertions");
10
10
  const noop_1 = require("../../helpers/noop");
11
+ const mapUtils_1 = require("../../helpers/mapUtils");
11
12
  class ScheduledAction {
13
+ static locks = new Map();
14
+ name;
15
+ timeinHours;
16
+ active;
17
+ chatsWhitelist;
18
+ key;
19
+ cachedState = new Map();
20
+ stateConstructor;
21
+ cachedStateFactories;
22
+ handler;
12
23
  constructor(name, handler, timeinHours, active, whitelist, cachedStateFactories, stateConstructor) {
13
- this.cachedState = new Map();
14
24
  this.name = name;
15
25
  this.handler = handler;
16
26
  this.timeinHours = timeinHours;
@@ -36,24 +46,14 @@ class ScheduledAction {
36
46
  return ctx.responses;
37
47
  }
38
48
  async getCachedValue(key, botName, scheduler) {
39
- if (!this.cachedStateFactories.has(key)) {
40
- throw new Error(`No shared cache was set up for the key [${key}] in action '${this.name}'`);
41
- }
49
+ const cachedItemFactory = (0, mapUtils_1.getOrThrow)(this.cachedStateFactories, key, `No shared cache was set up for the key [${key}] in action '${this.name}'`);
42
50
  const semaphoreKey = `${this.key}_cached:${key}`;
43
- let semaphore;
44
- if (ScheduledAction.locks.has(semaphoreKey)) {
45
- semaphore = ScheduledAction.locks.get(semaphoreKey);
46
- }
47
- else {
48
- semaphore = new async_sema_1.Sema(1);
49
- ScheduledAction.locks.set(semaphoreKey, semaphore);
50
- }
51
+ const semaphore = (0, mapUtils_1.getOrSetIfNotExists)(ScheduledAction.locks, semaphoreKey, new async_sema_1.Sema(1));
51
52
  await semaphore.acquire();
52
53
  try {
53
54
  if (this.cachedState.has(key)) {
54
55
  return this.cachedState.get(key);
55
56
  }
56
- const cachedItemFactory = this.cachedStateFactories.get(key);
57
57
  const value = await cachedItemFactory.getValue();
58
58
  this.cachedState.set(key, value);
59
59
  scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () => this.cachedState.delete(key), (0, timeConvertions_1.hoursToMilliseconds)(cachedItemFactory.invalidationTimeoutInHours), botName);
@@ -76,4 +76,3 @@ class ScheduledAction {
76
76
  }
77
77
  }
78
78
  exports.ScheduledAction = ScheduledAction;
79
- ScheduledAction.locks = new Map();
@@ -7,6 +7,11 @@ const nodeTimeoutScheduler_1 = require("../services/nodeTimeoutScheduler");
7
7
  const traceFactory_1 = require("../helpers/traceFactory");
8
8
  const actionProcessingService_1 = require("../services/actionProcessingService");
9
9
  class BotInstance {
10
+ storage;
11
+ scheduler;
12
+ logger;
13
+ actionProcessingService;
14
+ name;
10
15
  constructor(options) {
11
16
  const actions = [
12
17
  ...options.actions.commands,
@@ -23,8 +28,8 @@ class BotInstance {
23
28
  this.actionProcessingService = new actionProcessingService_1.ActionProcessingService(this.name, options.chats, this.storage, this.scheduler, this.logger);
24
29
  }
25
30
  async start(token, actions, scheduledPeriod, verboseLoggingForIncomingMessage) {
26
- this.actionProcessingService.initialize(token, actions, scheduledPeriod, verboseLoggingForIncomingMessage);
27
31
  this.logger.logWithTraceId(this.name, (0, traceFactory_1.createTrace)(this, this.name, 'Start'), 'System', 'Starting bot...');
32
+ await this.actionProcessingService.initialize(token, actions, scheduledPeriod, verboseLoggingForIncomingMessage);
28
33
  }
29
34
  async stop(code) {
30
35
  this.logger.logWithTraceId(this.name, (0, traceFactory_1.createTrace)(this, this.name, 'Stop'), 'System', 'Stopping bot...');
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CachedStateFactory = void 0;
4
4
  class CachedStateFactory {
5
+ getValue;
6
+ invalidationTimeoutInHours;
5
7
  constructor(itemFactory, invalidationTimeout) {
6
8
  this.getValue = itemFactory;
7
9
  this.invalidationTimeoutInHours = invalidationTimeout;
@@ -2,6 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseContext = void 0;
4
4
  class BaseContext {
5
+ isInitialized = false;
6
+ _responses = [];
7
+ action;
8
+ /** Storage client instance for the bot executing this action. */
9
+ storage;
10
+ /** Scheduler instance for the bot executing this action */
11
+ scheduler;
12
+ logger;
13
+ /** Trace id of a action execution. */
14
+ traceId;
15
+ /** Name of a bot that executes this action. */
16
+ botName;
17
+ /** Chat information. */
18
+ chatInfo;
5
19
  /** Ordered collection of responses to be processed */
6
20
  get responses() {
7
21
  return this._responses;
@@ -10,8 +24,6 @@ class BaseContext {
10
24
  this._responses = value;
11
25
  }
12
26
  constructor(storage, scheduler) {
13
- this.isInitialized = false;
14
- this._responses = [];
15
27
  this.storage = storage;
16
28
  this.scheduler = scheduler;
17
29
  }
@@ -1,10 +1,8 @@
1
- import { IStorageClient } from '../../types/storage';
2
1
  import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
3
2
  import { IActionWithState } from '../../types/action';
4
3
  import { IActionState } from '../../types/actionState';
5
4
  import { IReplyResponse } from '../../types/response';
6
5
  import { Milliseconds } from '../../types/timeValues';
7
- import { IScheduler } from '../../types/scheduler';
8
6
  import { ICaptureController } from '../../types/capture';
9
7
  import { BaseContext } from './baseContext';
10
8
  import { ScheduledAction } from '../actions/scheduledAction';
@@ -12,7 +10,6 @@ import { ScheduledAction } from '../actions/scheduledAction';
12
10
  * Context of action executed in chat.
13
11
  */
14
12
  export declare class ChatContext<TActionState extends IActionState, TAction extends IActionWithState<TActionState> = ScheduledAction<TActionState>> extends BaseContext<TAction> {
15
- constructor(storage: IStorageClient, scheduler: IScheduler);
16
13
  protected createCaptureController(response: IReplyResponse): ICaptureController;
17
14
  /**
18
15
  * Collection of actions that send something to chat as a standalone message.
@@ -1 +1 @@
1
- {"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,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