chz-telegram-bot 0.5.2 → 0.5.4

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 (216) hide show
  1. package/dtos/chatHistoryMessage.ts +9 -1
  2. package/package.json +1 -1
  3. package/services/actionProcessors/commandActionProcessor.ts +2 -1
  4. package/dist/builtin/helpAction.d.ts +0 -2
  5. package/dist/builtin/helpAction.d.ts.map +0 -1
  6. package/dist/builtin/helpAction.js +0 -14
  7. package/dist/dtos/chatHistoryMessage.d.ts +0 -13
  8. package/dist/dtos/chatHistoryMessage.d.ts.map +0 -1
  9. package/dist/dtos/chatHistoryMessage.js +0 -16
  10. package/dist/dtos/chatInfo.d.ts +0 -17
  11. package/dist/dtos/chatInfo.d.ts.map +0 -1
  12. package/dist/dtos/chatInfo.js +0 -16
  13. package/dist/dtos/commandTriggerCheckResult.d.ts +0 -24
  14. package/dist/dtos/commandTriggerCheckResult.d.ts.map +0 -1
  15. package/dist/dtos/commandTriggerCheckResult.js +0 -34
  16. package/dist/dtos/cooldownInfo.d.ts +0 -13
  17. package/dist/dtos/cooldownInfo.d.ts.map +0 -1
  18. package/dist/dtos/cooldownInfo.js +0 -12
  19. package/dist/dtos/incomingMessage.d.ts +0 -19
  20. package/dist/dtos/incomingMessage.d.ts.map +0 -1
  21. package/dist/dtos/incomingMessage.js +0 -63
  22. package/dist/dtos/incomingQuery.d.ts +0 -10
  23. package/dist/dtos/incomingQuery.d.ts.map +0 -1
  24. package/dist/dtos/incomingQuery.js +0 -14
  25. package/dist/dtos/messageInfo.d.ts +0 -22
  26. package/dist/dtos/messageInfo.d.ts.map +0 -1
  27. package/dist/dtos/messageInfo.js +0 -20
  28. package/dist/dtos/propertyProviderSets.d.ts +0 -16
  29. package/dist/dtos/propertyProviderSets.d.ts.map +0 -1
  30. package/dist/dtos/propertyProviderSets.js +0 -1
  31. package/dist/dtos/replyInfo.d.ts +0 -6
  32. package/dist/dtos/replyInfo.d.ts.map +0 -1
  33. package/dist/dtos/replyInfo.js +0 -8
  34. package/dist/dtos/responses/delay.d.ts +0 -16
  35. package/dist/dtos/responses/delay.d.ts.map +0 -1
  36. package/dist/dtos/responses/delay.js +0 -15
  37. package/dist/dtos/responses/imageMessage.d.ts +0 -22
  38. package/dist/dtos/responses/imageMessage.d.ts.map +0 -1
  39. package/dist/dtos/responses/imageMessage.js +0 -21
  40. package/dist/dtos/responses/inlineQueryResponse.d.ts +0 -13
  41. package/dist/dtos/responses/inlineQueryResponse.d.ts.map +0 -1
  42. package/dist/dtos/responses/inlineQueryResponse.js +0 -15
  43. package/dist/dtos/responses/reaction.d.ts +0 -16
  44. package/dist/dtos/responses/reaction.d.ts.map +0 -1
  45. package/dist/dtos/responses/reaction.js +0 -17
  46. package/dist/dtos/responses/textMessage.d.ts +0 -23
  47. package/dist/dtos/responses/textMessage.d.ts.map +0 -1
  48. package/dist/dtos/responses/textMessage.js +0 -24
  49. package/dist/dtos/responses/unpin.d.ts +0 -15
  50. package/dist/dtos/responses/unpin.d.ts.map +0 -1
  51. package/dist/dtos/responses/unpin.js +0 -15
  52. package/dist/dtos/responses/videoMessage.d.ts +0 -22
  53. package/dist/dtos/responses/videoMessage.d.ts.map +0 -1
  54. package/dist/dtos/responses/videoMessage.js +0 -21
  55. package/dist/dtos/userInfo.d.ts +0 -12
  56. package/dist/dtos/userInfo.d.ts.map +0 -1
  57. package/dist/dtos/userInfo.js +0 -12
  58. package/dist/entities/actions/commandAction.d.ts +0 -31
  59. package/dist/entities/actions/commandAction.d.ts.map +0 -1
  60. package/dist/entities/actions/commandAction.js +0 -139
  61. package/dist/entities/actions/inlineQueryAction.d.ts +0 -14
  62. package/dist/entities/actions/inlineQueryAction.d.ts.map +0 -1
  63. package/dist/entities/actions/inlineQueryAction.js +0 -43
  64. package/dist/entities/actions/replyCaptureAction.d.ts +0 -15
  65. package/dist/entities/actions/replyCaptureAction.d.ts.map +0 -1
  66. package/dist/entities/actions/replyCaptureAction.js +0 -58
  67. package/dist/entities/actions/scheduledAction.d.ts +0 -24
  68. package/dist/entities/actions/scheduledAction.d.ts.map +0 -1
  69. package/dist/entities/actions/scheduledAction.js +0 -72
  70. package/dist/entities/botInstance.d.ts +0 -37
  71. package/dist/entities/botInstance.d.ts.map +0 -1
  72. package/dist/entities/botInstance.js +0 -37
  73. package/dist/entities/cachedStateFactory.d.ts +0 -7
  74. package/dist/entities/cachedStateFactory.d.ts.map +0 -1
  75. package/dist/entities/cachedStateFactory.js +0 -8
  76. package/dist/entities/context/baseContext.d.ts +0 -39
  77. package/dist/entities/context/baseContext.d.ts.map +0 -1
  78. package/dist/entities/context/baseContext.js +0 -55
  79. package/dist/entities/context/chatContext.d.ts +0 -50
  80. package/dist/entities/context/chatContext.d.ts.map +0 -1
  81. package/dist/entities/context/chatContext.js +0 -65
  82. package/dist/entities/context/inlineQueryContext.d.ts +0 -27
  83. package/dist/entities/context/inlineQueryContext.d.ts.map +0 -1
  84. package/dist/entities/context/inlineQueryContext.js +0 -29
  85. package/dist/entities/context/messageContext.d.ts +0 -92
  86. package/dist/entities/context/messageContext.d.ts.map +0 -1
  87. package/dist/entities/context/messageContext.js +0 -116
  88. package/dist/entities/context/replyContext.d.ts +0 -89
  89. package/dist/entities/context/replyContext.d.ts.map +0 -1
  90. package/dist/entities/context/replyContext.js +0 -124
  91. package/dist/entities/states/actionStateBase.d.ts +0 -6
  92. package/dist/entities/states/actionStateBase.d.ts.map +0 -1
  93. package/dist/entities/states/actionStateBase.js +0 -4
  94. package/dist/entities/taskRecord.d.ts +0 -8
  95. package/dist/entities/taskRecord.d.ts.map +0 -1
  96. package/dist/entities/taskRecord.js +0 -10
  97. package/dist/eslint.config.d.ts +0 -3
  98. package/dist/eslint.config.d.ts.map +0 -1
  99. package/dist/eslint.config.js +0 -51
  100. package/dist/helpers/builders/commandActionBuilder.d.ts +0 -100
  101. package/dist/helpers/builders/commandActionBuilder.d.ts.map +0 -1
  102. package/dist/helpers/builders/commandActionBuilder.js +0 -146
  103. package/dist/helpers/builders/inlineQueryActionBuilder.d.ts +0 -37
  104. package/dist/helpers/builders/inlineQueryActionBuilder.d.ts.map +0 -1
  105. package/dist/helpers/builders/inlineQueryActionBuilder.js +0 -50
  106. package/dist/helpers/builders/scheduledActionBuilder.d.ts +0 -68
  107. package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +0 -1
  108. package/dist/helpers/builders/scheduledActionBuilder.js +0 -95
  109. package/dist/helpers/mapUtils.d.ts +0 -10
  110. package/dist/helpers/mapUtils.d.ts.map +0 -1
  111. package/dist/helpers/mapUtils.js +0 -13
  112. package/dist/helpers/noop.d.ts +0 -9
  113. package/dist/helpers/noop.d.ts.map +0 -1
  114. package/dist/helpers/noop.js +0 -17
  115. package/dist/helpers/objectFromEntries.d.ts +0 -2
  116. package/dist/helpers/objectFromEntries.d.ts.map +0 -1
  117. package/dist/helpers/objectFromEntries.js +0 -3
  118. package/dist/helpers/timeConvertions.d.ts +0 -5
  119. package/dist/helpers/timeConvertions.d.ts.map +0 -1
  120. package/dist/helpers/timeConvertions.js +0 -9
  121. package/dist/helpers/toArray.d.ts +0 -2
  122. package/dist/helpers/toArray.d.ts.map +0 -1
  123. package/dist/helpers/toArray.js +0 -3
  124. package/dist/helpers/traceFactory.d.ts +0 -3
  125. package/dist/helpers/traceFactory.d.ts.map +0 -1
  126. package/dist/helpers/traceFactory.js +0 -3
  127. package/dist/index.d.ts +0 -27
  128. package/dist/index.d.ts.map +0 -1
  129. package/dist/index.js +0 -20
  130. package/dist/main.d.ts +0 -52
  131. package/dist/main.d.ts.map +0 -1
  132. package/dist/main.js +0 -34
  133. package/dist/services/actionProcessingService.d.ts +0 -25
  134. package/dist/services/actionProcessingService.d.ts.map +0 -1
  135. package/dist/services/actionProcessingService.js +0 -50
  136. package/dist/services/actionProcessors/baseProcessor.d.ts +0 -18
  137. package/dist/services/actionProcessors/baseProcessor.d.ts.map +0 -1
  138. package/dist/services/actionProcessors/baseProcessor.js +0 -29
  139. package/dist/services/actionProcessors/commandActionProcessor.d.ts +0 -20
  140. package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +0 -1
  141. package/dist/services/actionProcessors/commandActionProcessor.js +0 -116
  142. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +0 -11
  143. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +0 -1
  144. package/dist/services/actionProcessors/inlineQueryActionProcessor.js +0 -61
  145. package/dist/services/actionProcessors/scheduledActionProcessor.d.ts +0 -17
  146. package/dist/services/actionProcessors/scheduledActionProcessor.d.ts.map +0 -1
  147. package/dist/services/actionProcessors/scheduledActionProcessor.js +0 -56
  148. package/dist/services/jsonFileStorage.d.ts +0 -23
  149. package/dist/services/jsonFileStorage.d.ts.map +0 -1
  150. package/dist/services/jsonFileStorage.js +0 -109
  151. package/dist/services/jsonLogger.d.ts +0 -11
  152. package/dist/services/jsonLogger.d.ts.map +0 -1
  153. package/dist/services/jsonLogger.js +0 -66
  154. package/dist/services/nodeTimeoutScheduler.d.ts +0 -13
  155. package/dist/services/nodeTimeoutScheduler.d.ts.map +0 -1
  156. package/dist/services/nodeTimeoutScheduler.js +0 -31
  157. package/dist/services/responseProcessingQueue.d.ts +0 -12
  158. package/dist/services/responseProcessingQueue.d.ts.map +0 -1
  159. package/dist/services/responseProcessingQueue.js +0 -37
  160. package/dist/services/telegramApi.d.ts +0 -23
  161. package/dist/services/telegramApi.d.ts.map +0 -1
  162. package/dist/services/telegramApi.js +0 -133
  163. package/dist/types/action.d.ts +0 -14
  164. package/dist/types/action.d.ts.map +0 -1
  165. package/dist/types/action.js +0 -1
  166. package/dist/types/actionState.d.ts +0 -5
  167. package/dist/types/actionState.d.ts.map +0 -1
  168. package/dist/types/actionState.js +0 -1
  169. package/dist/types/cachedValueAccessor.d.ts +0 -2
  170. package/dist/types/cachedValueAccessor.d.ts.map +0 -1
  171. package/dist/types/cachedValueAccessor.js +0 -1
  172. package/dist/types/capture.d.ts +0 -24
  173. package/dist/types/capture.d.ts.map +0 -1
  174. package/dist/types/capture.js +0 -1
  175. package/dist/types/commandCondition.d.ts +0 -8
  176. package/dist/types/commandCondition.d.ts.map +0 -1
  177. package/dist/types/commandCondition.js +0 -1
  178. package/dist/types/commandTrigger.d.ts +0 -2
  179. package/dist/types/commandTrigger.d.ts.map +0 -1
  180. package/dist/types/commandTrigger.js +0 -1
  181. package/dist/types/externalAliases.d.ts +0 -11
  182. package/dist/types/externalAliases.d.ts.map +0 -1
  183. package/dist/types/externalAliases.js +0 -1
  184. package/dist/types/handlers.d.ts +0 -21
  185. package/dist/types/handlers.d.ts.map +0 -1
  186. package/dist/types/handlers.js +0 -1
  187. package/dist/types/inputFile.d.ts +0 -5
  188. package/dist/types/inputFile.d.ts.map +0 -1
  189. package/dist/types/inputFile.js +0 -1
  190. package/dist/types/logger.d.ts +0 -13
  191. package/dist/types/logger.d.ts.map +0 -1
  192. package/dist/types/logger.js +0 -1
  193. package/dist/types/messageSendingOptions.d.ts +0 -9
  194. package/dist/types/messageSendingOptions.d.ts.map +0 -1
  195. package/dist/types/messageSendingOptions.js +0 -1
  196. package/dist/types/messageTypes.d.ts +0 -20
  197. package/dist/types/messageTypes.d.ts.map +0 -1
  198. package/dist/types/messageTypes.js +0 -18
  199. package/dist/types/propertyProvider.d.ts +0 -8
  200. package/dist/types/propertyProvider.d.ts.map +0 -1
  201. package/dist/types/propertyProvider.js +0 -1
  202. package/dist/types/response.d.ts +0 -39
  203. package/dist/types/response.d.ts.map +0 -1
  204. package/dist/types/response.js +0 -9
  205. package/dist/types/scheduler.d.ts +0 -7
  206. package/dist/types/scheduler.d.ts.map +0 -1
  207. package/dist/types/scheduler.js +0 -1
  208. package/dist/types/storage.d.ts +0 -11
  209. package/dist/types/storage.d.ts.map +0 -1
  210. package/dist/types/storage.js +0 -1
  211. package/dist/types/timeValues.d.ts +0 -15
  212. package/dist/types/timeValues.d.ts.map +0 -1
  213. package/dist/types/timeValues.js +0 -1
  214. package/dist/types/trace.d.ts +0 -6
  215. package/dist/types/trace.d.ts.map +0 -1
  216. package/dist/types/trace.js +0 -1
@@ -1,23 +0,0 @@
1
- import { TextMessageSendingOptions } from '../../types/messageSendingOptions';
2
- import { IReplyResponseWithContent } from '../../types/response';
3
- import { IAction } from '../../types/action';
4
- import { ChatInfo } from '../chatInfo';
5
- import { TraceId } from '../../types/trace';
6
- import { ReplyInfo } from '../replyInfo';
7
- import { IReplyCapture } from '../../types/capture';
8
- import { TelegramInlineKeyboardButton } from '../../types/externalAliases';
9
- export declare class TextMessage implements IReplyResponseWithContent<string> {
10
- readonly kind: "text";
11
- readonly createdAt: number;
12
- readonly captures: IReplyCapture[];
13
- readonly content: string;
14
- readonly chatInfo: ChatInfo;
15
- readonly replyInfo: ReplyInfo | undefined;
16
- readonly traceId: TraceId;
17
- readonly disableWebPreview: boolean;
18
- readonly shouldPin: boolean;
19
- readonly action: IAction;
20
- readonly keyboard?: TelegramInlineKeyboardButton[][];
21
- constructor(text: string, chatInfo: ChatInfo, traceId: TraceId, action: IAction, replyInfo?: ReplyInfo, options?: TextMessageSendingOptions);
22
- }
23
- //# sourceMappingURL=textMessage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"textMessage.d.ts","sourceRoot":"","sources":["../../../dtos/responses/textMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAEH,yBAAyB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAE3E,qBAAa,WAAY,YAAW,yBAAyB,CAAC,MAAM,CAAC;IACjE,QAAQ,CAAC,IAAI,SAAyB;IACtC,QAAQ,CAAC,SAAS,SAAc;IAChC,QAAQ,CAAC,QAAQ,EAAE,aAAa,EAAE,CAAM;IAExC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,4BAA4B,EAAE,EAAE,CAAC;gBAGjD,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,OAAO,EACf,SAAS,CAAC,EAAE,SAAS,EACrB,OAAO,CAAC,EAAE,yBAAyB;CAW1C"}
@@ -1,24 +0,0 @@
1
- import { BotResponseTypes } from '../../types/response';
2
- export class TextMessage {
3
- kind = BotResponseTypes.text;
4
- createdAt = Date.now();
5
- captures = [];
6
- content;
7
- chatInfo;
8
- replyInfo;
9
- traceId;
10
- disableWebPreview;
11
- shouldPin;
12
- action;
13
- keyboard;
14
- constructor(text, chatInfo, traceId, action, replyInfo, options) {
15
- this.content = text;
16
- this.chatInfo = chatInfo;
17
- this.replyInfo = replyInfo;
18
- this.traceId = traceId;
19
- this.disableWebPreview = options?.disableWebPreview ?? false;
20
- this.shouldPin = options?.pin ?? false;
21
- this.action = action;
22
- this.keyboard = options?.keyboard;
23
- }
24
- }
@@ -1,15 +0,0 @@
1
- import { IChatResponse } from '../../types/response';
2
- import { IActionWithState } from '../../types/action';
3
- import { IActionState } from '../../types/actionState';
4
- import { ChatInfo } from '../chatInfo';
5
- import { TraceId } from '../../types/trace';
6
- export declare class UnpinResponse implements IChatResponse {
7
- readonly kind: "unpin";
8
- readonly createdAt: number;
9
- readonly messageId: number;
10
- readonly chatInfo: ChatInfo;
11
- readonly traceId: TraceId;
12
- readonly action: IActionWithState<IActionState>;
13
- constructor(messageId: number, chatInfo: ChatInfo, traceId: TraceId, action: IActionWithState<IActionState>);
14
- }
15
- //# sourceMappingURL=unpin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unpin.d.ts","sourceRoot":"","sources":["../../../dtos/responses/unpin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,qBAAa,aAAc,YAAW,aAAa;IAC/C,QAAQ,CAAC,IAAI,UAA0B;IACvC,QAAQ,CAAC,SAAS,SAAc;IAEhC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG5C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC;CAO7C"}
@@ -1,15 +0,0 @@
1
- import { BotResponseTypes } from '../../types/response';
2
- export class UnpinResponse {
3
- kind = BotResponseTypes.unpin;
4
- createdAt = Date.now();
5
- messageId;
6
- chatInfo;
7
- traceId;
8
- action;
9
- constructor(messageId, chatInfo, traceId, action) {
10
- this.messageId = messageId;
11
- this.chatInfo = chatInfo;
12
- this.traceId = traceId;
13
- this.action = action;
14
- }
15
- }
@@ -1,22 +0,0 @@
1
- import { IReplyResponseWithContent } from '../../types/response';
2
- import { MessageSendingOptions } from '../../types/messageSendingOptions';
3
- import { IAction } from '../../types/action';
4
- import { ChatInfo } from '../chatInfo';
5
- import { TraceId } from '../../types/trace';
6
- import { ReplyInfo } from '../replyInfo';
7
- import { IReplyCapture } from '../../types/capture';
8
- import { InputFile } from '../../types/inputFile';
9
- export declare class VideoMessage implements IReplyResponseWithContent<InputFile> {
10
- readonly kind: "video";
11
- readonly createdAt: number;
12
- readonly captures: IReplyCapture[];
13
- readonly content: InputFile;
14
- readonly chatInfo: ChatInfo;
15
- readonly replyInfo: ReplyInfo | undefined;
16
- readonly traceId: TraceId;
17
- readonly disableWebPreview = false;
18
- readonly shouldPin: boolean;
19
- readonly action: IAction;
20
- constructor(video: InputFile, chatInfo: ChatInfo, traceId: TraceId, action: IAction, replyInfo: ReplyInfo | undefined, options?: MessageSendingOptions);
21
- }
22
- //# sourceMappingURL=videoMessage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"videoMessage.d.ts","sourceRoot":"","sources":["../../../dtos/responses/videoMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,yBAAyB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,qBAAa,YAAa,YAAW,yBAAyB,CAAC,SAAS,CAAC;IACrE,QAAQ,CAAC,IAAI,UAA0B;IACvC,QAAQ,CAAC,SAAS,SAAc;IAChC,QAAQ,CAAC,QAAQ,EAAE,aAAa,EAAE,CAAM;IAExC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,iBAAiB,SAAS;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;gBAGrB,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE,qBAAqB;CAStC"}
@@ -1,21 +0,0 @@
1
- import { BotResponseTypes } from '../../types/response';
2
- export class VideoMessage {
3
- kind = BotResponseTypes.video;
4
- createdAt = Date.now();
5
- captures = [];
6
- content;
7
- chatInfo;
8
- replyInfo;
9
- traceId;
10
- disableWebPreview = false;
11
- shouldPin;
12
- action;
13
- constructor(video, chatInfo, traceId, action, replyInfo, options) {
14
- this.content = video;
15
- this.chatInfo = chatInfo;
16
- this.replyInfo = replyInfo;
17
- this.traceId = traceId;
18
- this.shouldPin = options?.pin ?? false;
19
- this.action = action;
20
- }
21
- }
@@ -1,12 +0,0 @@
1
- export declare class UserInfo {
2
- /** Id of a user that sent a message that triggered this action. */
3
- readonly id: number;
4
- /** Name of a user that sent a message that triggered this action. */
5
- readonly name: string;
6
- constructor(
7
- /** Id of a user that sent a message that triggered this action. */
8
- id: number,
9
- /** Name of a user that sent a message that triggered this action. */
10
- name: string);
11
- }
12
- //# sourceMappingURL=userInfo.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userInfo.d.ts","sourceRoot":"","sources":["../../dtos/userInfo.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IAEb,mEAAmE;IACnE,QAAQ,CAAC,EAAE,EAAE,MAAM;IACnB,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM;;IAHrB,mEAAmE;IAC1D,EAAE,EAAE,MAAM;IACnB,qEAAqE;IAC5D,IAAI,EAAE,MAAM;CAE5B"}
@@ -1,12 +0,0 @@
1
- export class UserInfo {
2
- id;
3
- name;
4
- constructor(
5
- /** Id of a user that sent a message that triggered this action. */
6
- id,
7
- /** Name of a user that sent a message that triggered this action. */
8
- name) {
9
- this.id = id;
10
- this.name = name;
11
- }
12
- }
@@ -1,31 +0,0 @@
1
- import { CommandHandler } from '../../types/handlers';
2
- import { CommandCondition } from '../../types/commandCondition';
3
- import { IActionState } from '../../types/actionState';
4
- import { IActionWithState, ActionKey } from '../../types/action';
5
- import { MessageContextInternal } from '../context/messageContext';
6
- import { CommandTrigger } from '../../types/commandTrigger';
7
- import { Sema as Semaphore } from 'async-sema';
8
- import { CommandActionProviders } from '../../dtos/propertyProviderSets';
9
- import { BotResponse } from '../../types/response';
10
- export declare class CommandAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
11
- private readonly cooldownInfoProvider;
12
- private readonly isActiveProvider;
13
- private readonly chatsBlacklistProvider;
14
- private readonly chatsWhitelistProvider;
15
- private readonly usersWhitelistProvider;
16
- readonly key: ActionKey;
17
- readonly name: string;
18
- readonly ratelimitSemaphores: Map<number, Semaphore>;
19
- readonly maxAllowedSimultaniousExecutions: number;
20
- readonly triggers: CommandTrigger[];
21
- readonly handler: CommandHandler<TActionState>;
22
- readonly condition: CommandCondition<TActionState>;
23
- readonly stateConstructor: () => TActionState;
24
- readonly readmeFactory: (botName: string) => string;
25
- private lastCustomCooldown;
26
- constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, providers: CommandActionProviders, maxAllowedSimultaniousExecutions: number, condition: CommandCondition<TActionState>, stateConstructor: () => TActionState, readmeFactory: (botName: string) => string);
27
- exec(ctx: MessageContextInternal<TActionState>): Promise<BotResponse[]>;
28
- private checkIfShouldBeExecuted;
29
- private checkTrigger;
30
- }
31
- //# sourceMappingURL=commandAction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commandAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/commandAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAO/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA8C;IACnF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAyC;IAC1E,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAErC;IACF,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAErC;IACF,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAErC;IAEF,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,mBAAmB,yBAAgC;IAC5D,QAAQ,CAAC,gCAAgC,EAAE,MAAM,CAAC;IAElD,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IAEpC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAEpD,OAAO,CAAC,kBAAkB,CAAsB;gBAG5C,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,EAC1C,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,sBAAsB,EACjC,gCAAgC,EAAE,MAAM,EACxC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY,EACpC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM;IAsBxC,IAAI,CACN,GAAG,EAAE,sBAAsB,CAAC,YAAY,CAAC,GAC1C,OAAO,CAAC,WAAW,EAAE,CAAC;IAiFzB,OAAO,CAAC,uBAAuB;IA6D/B,OAAO,CAAC,YAAY;CAuCvB"}
@@ -1,139 +0,0 @@
1
- import moment from 'moment';
2
- import { secondsToMilliseconds } from '../../helpers/timeConvertions';
3
- import { toArray } from '../../helpers/toArray';
4
- import { CommandTriggerCheckResult } from '../../dtos/commandTriggerCheckResult';
5
- import { Noop } from '../../helpers/noop';
6
- import { MessageType } from '../../types/messageTypes';
7
- import { Sema as Semaphore } from 'async-sema';
8
- import { getOrSetIfNotExists } from '../../helpers/mapUtils';
9
- import { TextMessage } from '../../dtos/responses/textMessage';
10
- import { ReplyInfo } from '../../dtos/replyInfo';
11
- export class CommandAction {
12
- cooldownInfoProvider;
13
- isActiveProvider;
14
- chatsBlacklistProvider;
15
- chatsWhitelistProvider;
16
- usersWhitelistProvider;
17
- key;
18
- name;
19
- ratelimitSemaphores = new Map();
20
- maxAllowedSimultaniousExecutions;
21
- triggers;
22
- handler;
23
- condition;
24
- stateConstructor;
25
- readmeFactory;
26
- lastCustomCooldown;
27
- constructor(trigger, handler, name, providers, maxAllowedSimultaniousExecutions, condition, stateConstructor, readmeFactory) {
28
- this.triggers = toArray(trigger);
29
- this.name = name;
30
- this.cooldownInfoProvider = providers.cooldownProvider;
31
- this.isActiveProvider = providers.isActiveProvider;
32
- this.chatsBlacklistProvider = providers.chatsBlacklistProvider;
33
- this.chatsWhitelistProvider = providers.chatsWhitelistProvider;
34
- this.usersWhitelistProvider = providers.usersWhitelistProvider;
35
- this.handler = handler;
36
- this.condition = condition;
37
- this.stateConstructor = stateConstructor;
38
- this.readmeFactory = readmeFactory;
39
- this.maxAllowedSimultaniousExecutions =
40
- maxAllowedSimultaniousExecutions;
41
- this.key = `command:${this.name.replace('.', '-')}`;
42
- }
43
- async exec(ctx) {
44
- if (!ctx.isInitialized)
45
- throw new Error(`Context for ${this.key} is not initialized or already consumed`);
46
- let lock;
47
- if (this.maxAllowedSimultaniousExecutions != 0) {
48
- lock = getOrSetIfNotExists(this.ratelimitSemaphores, ctx.chatInfo.id, new Semaphore(this.maxAllowedSimultaniousExecutions));
49
- await lock.acquire();
50
- }
51
- try {
52
- const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
53
- const { shouldExecute, matchResults, skipCooldown, reason } = this.triggers
54
- .map((x) => this.checkIfShouldBeExecuted(ctx, x, state))
55
- .reduce((acc, curr) => acc.mergeWith(curr), CommandTriggerCheckResult.DoNotTrigger('Other'));
56
- if (!shouldExecute) {
57
- if (reason == 'OnCooldown') {
58
- const cooldownMessage = this.cooldownInfoProvider(ctx).message;
59
- return cooldownMessage
60
- ? [
61
- new TextMessage(cooldownMessage, ctx.chatInfo, ctx.traceId, this, new ReplyInfo(ctx.messageInfo.id))
62
- ]
63
- : Noop.NoResponse;
64
- }
65
- return Noop.NoResponse;
66
- }
67
- ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
68
- ctx.matchResults = matchResults;
69
- await this.handler(ctx, state);
70
- if (skipCooldown) {
71
- ctx.startCooldown = false;
72
- }
73
- if (ctx.startCooldown) {
74
- this.lastCustomCooldown = ctx.customCooldown;
75
- state.lastExecutedDate = moment().valueOf();
76
- }
77
- await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
78
- return ctx.responses;
79
- }
80
- finally {
81
- lock?.release();
82
- }
83
- }
84
- checkIfShouldBeExecuted(ctx, trigger, state) {
85
- if (!this.isActiveProvider(ctx))
86
- return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ActionDisabled');
87
- const chatsBlacklist = this.chatsBlacklistProvider(ctx);
88
- const chatsWhitelist = this.chatsWhitelistProvider(ctx);
89
- const isChatInBlacklist = chatsBlacklist.includes(ctx.chatInfo.id);
90
- const isChatInWhitelist = chatsWhitelist.length == 0 ||
91
- chatsWhitelist.includes(ctx.chatInfo.id);
92
- if (isChatInBlacklist || !isChatInWhitelist)
93
- return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ChatForbidden');
94
- const triggerCheckResult = this.checkTrigger(ctx, trigger);
95
- if (!triggerCheckResult.shouldExecute)
96
- return triggerCheckResult;
97
- if (!ctx.userInfo.id)
98
- return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserIdMissing');
99
- const usersWhitelist = this.usersWhitelistProvider(ctx);
100
- const isUserAllowed = usersWhitelist.length == 0 ||
101
- usersWhitelist.includes(ctx.userInfo.id);
102
- if (!isUserAllowed)
103
- return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserForbidden');
104
- const lastExecutedDate = moment(state.lastExecutedDate);
105
- const cooldownInMilliseconds = secondsToMilliseconds(this.lastCustomCooldown ?? this.cooldownInfoProvider(ctx).cooldown);
106
- const onCooldown = moment().diff(lastExecutedDate) < cooldownInMilliseconds;
107
- if (onCooldown)
108
- return CommandTriggerCheckResult.DoNotTrigger('OnCooldown');
109
- const isCustomConditionMet = this.condition(ctx, state);
110
- if (!isCustomConditionMet)
111
- return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('CustomConditionNotMet');
112
- return triggerCheckResult;
113
- }
114
- checkTrigger(ctx, trigger) {
115
- if (trigger == MessageType.Any || trigger == ctx.messageInfo.type)
116
- return CommandTriggerCheckResult.Trigger();
117
- if (typeof trigger == 'string')
118
- return ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase()
119
- ? CommandTriggerCheckResult.Trigger()
120
- : CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
121
- const matchResults = [];
122
- trigger.lastIndex = 0;
123
- const execResult = trigger.exec(ctx.messageInfo.text);
124
- if (execResult != null) {
125
- let regexMatchLimit = 100;
126
- matchResults.push(execResult);
127
- if (trigger.global) {
128
- while (regexMatchLimit > 0) {
129
- const nextResult = trigger.exec(ctx.messageInfo.text);
130
- if (nextResult == null)
131
- break;
132
- matchResults.push(nextResult);
133
- regexMatchLimit -= 1;
134
- }
135
- }
136
- }
137
- return new CommandTriggerCheckResult(matchResults.length > 0, matchResults, false);
138
- }
139
- }
@@ -1,14 +0,0 @@
1
- import { ActionKey, IAction } from '../../types/action';
2
- import { InlineQueryContextInternal } from '../context/inlineQueryContext';
3
- import { InlineQueryHandler } from '../../types/handlers';
4
- import { InlineActionPropertyProvider } from '../../types/propertyProvider';
5
- export declare class InlineQueryAction implements IAction {
6
- readonly key: ActionKey;
7
- readonly isActiveProvider: InlineActionPropertyProvider<boolean>;
8
- readonly handler: InlineQueryHandler;
9
- readonly name: string;
10
- readonly pattern: RegExp;
11
- constructor(handler: InlineQueryHandler, name: string, activeProvider: InlineActionPropertyProvider<boolean>, pattern: RegExp);
12
- exec(ctx: InlineQueryContextInternal): Promise<import("../../types/response").BotResponse[]>;
13
- }
14
- //# sourceMappingURL=inlineQueryAction.d.ts.map
@@ -1 +0,0 @@
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,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAE5E,qBAAa,iBAAkB,YAAW,OAAO;IAC7C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAC;IACjE,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,cAAc,EAAE,4BAA4B,CAAC,OAAO,CAAC,EACrD,OAAO,EAAE,MAAM;IAUb,IAAI,CAAC,GAAG,EAAE,0BAA0B;CAuC7C"}
@@ -1,43 +0,0 @@
1
- import { Noop } from '../../helpers/noop';
2
- export class InlineQueryAction {
3
- key;
4
- isActiveProvider;
5
- handler;
6
- name;
7
- pattern;
8
- constructor(handler, name, activeProvider, pattern) {
9
- this.handler = handler;
10
- this.name = name;
11
- this.isActiveProvider = activeProvider;
12
- this.pattern = pattern;
13
- this.key = `inline:${this.name.replace('.', '-')}`;
14
- }
15
- async exec(ctx) {
16
- if (!ctx.isInitialized)
17
- throw new Error(`Context for ${this.key} is not initialized or already consumed`);
18
- if (!this.isActiveProvider(ctx))
19
- return Noop.NoResponse;
20
- const matchResults = [];
21
- this.pattern.lastIndex = 0;
22
- const execResult = this.pattern.exec(ctx.queryText);
23
- if (execResult != null) {
24
- let regexMatchLimit = 100;
25
- matchResults.push(execResult);
26
- if (this.pattern.global) {
27
- while (regexMatchLimit > 0) {
28
- const nextResult = this.pattern.exec(ctx.queryText);
29
- if (nextResult == null)
30
- break;
31
- matchResults.push(nextResult);
32
- regexMatchLimit -= 1;
33
- }
34
- }
35
- }
36
- if (matchResults.length == 0)
37
- return Noop.NoResponse;
38
- ctx.matchResults = matchResults;
39
- ctx.logger.logWithTraceId(` - Executing [${this.name}]`);
40
- await this.handler(ctx);
41
- return ctx.responses;
42
- }
43
- }
@@ -1,15 +0,0 @@
1
- import { IActionState } from '../../types/actionState';
2
- import { CommandTrigger } from '../../types/commandTrigger';
3
- import { ActionKey, IAction } from '../../types/action';
4
- import { ReplyContextInternal } from '../context/replyContext';
5
- export declare class ReplyCaptureAction<TParentActionState extends IActionState> implements IAction {
6
- readonly parentMessageId: number;
7
- readonly key: ActionKey;
8
- readonly handler: (replyContext: ReplyContextInternal<TParentActionState>) => Promise<void>;
9
- readonly triggers: CommandTrigger[];
10
- readonly abortController: AbortController;
11
- constructor(parentMessageId: number, parentAction: IAction, handler: (replyContext: ReplyContextInternal<TParentActionState>) => Promise<void>, triggers: CommandTrigger[], abortController: AbortController);
12
- exec(ctx: ReplyContextInternal<TParentActionState>): Promise<import("../../types/response").BotResponse[]>;
13
- private checkIfShouldBeExecuted;
14
- }
15
- //# sourceMappingURL=replyCaptureAction.d.ts.map
@@ -1 +0,0 @@
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,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,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,oBAAoB,CAAC,kBAAkB,CAAC,KACrD,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,OAAO,EACrB,OAAO,EAAE,CACL,YAAY,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,KACrD,OAAO,CAAC,IAAI,CAAC,EAClB,QAAQ,EAAE,cAAc,EAAE,EAC1B,eAAe,EAAE,eAAe;IAY9B,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,kBAAkB,CAAC;IAyBxD,OAAO,CAAC,uBAAuB;CA4ClC"}
@@ -1,58 +0,0 @@
1
- import { CommandTriggerCheckResult } from '../../dtos/commandTriggerCheckResult';
2
- import { Noop } from '../../helpers/noop';
3
- export class ReplyCaptureAction {
4
- parentMessageId;
5
- key;
6
- handler;
7
- triggers;
8
- abortController;
9
- constructor(parentMessageId, parentAction, handler, triggers, abortController) {
10
- this.parentMessageId = parentMessageId;
11
- this.handler = handler;
12
- this.triggers = triggers;
13
- this.abortController = abortController;
14
- this.key = `capture:${parentAction.key}:${Math.random()
15
- .toString()
16
- .replace('.', '')}`;
17
- }
18
- async exec(ctx) {
19
- if (!ctx.isInitialized)
20
- throw new Error(`Context for ${this.key} is not initialized or already consumed`);
21
- const { shouldExecute, matchResults } = this.triggers
22
- .map((x) => this.checkIfShouldBeExecuted(ctx, x))
23
- .reduce((acc, curr) => acc.mergeWith(curr), CommandTriggerCheckResult.DoNotTrigger('Other'));
24
- if (!shouldExecute)
25
- return Noop.NoResponse;
26
- ctx.logger.logWithTraceId(` - Executing [${this.key}] in ${ctx.chatInfo.id}`);
27
- ctx.matchResults = matchResults;
28
- await this.handler(ctx);
29
- return ctx.responses;
30
- }
31
- checkIfShouldBeExecuted(ctx, trigger) {
32
- if (ctx.replyMessageId != this.parentMessageId)
33
- return CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
34
- if (trigger == ctx.messageInfo.type)
35
- return CommandTriggerCheckResult.Trigger();
36
- if (typeof trigger == 'string')
37
- return ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase()
38
- ? CommandTriggerCheckResult.Trigger()
39
- : CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
40
- const matchResults = [];
41
- trigger.lastIndex = 0;
42
- const execResult = trigger.exec(ctx.messageInfo.text);
43
- if (execResult != null) {
44
- let regexMatchLimit = 100;
45
- matchResults.push(execResult);
46
- if (trigger.global) {
47
- while (regexMatchLimit > 0) {
48
- const nextResult = trigger.exec(ctx.messageInfo.text);
49
- if (nextResult == null)
50
- break;
51
- matchResults.push(nextResult);
52
- regexMatchLimit -= 1;
53
- }
54
- }
55
- }
56
- return new CommandTriggerCheckResult(matchResults.length > 0, matchResults, false);
57
- }
58
- }
@@ -1,24 +0,0 @@
1
- import { Sema as Semaphore } from 'async-sema';
2
- import { ScheduledHandler } from '../../types/handlers';
3
- import { IActionState } from '../../types/actionState';
4
- import { IActionWithState, ActionKey } from '../../types/action';
5
- import { CachedStateFactory } from '../cachedStateFactory';
6
- import { ChatContextInternal } from '../context/chatContext';
7
- import { ScheduledActionProviders } from '../../dtos/propertyProviderSets';
8
- export declare class ScheduledAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
9
- static readonly locks: Map<string, Semaphore>;
10
- readonly name: string;
11
- readonly key: ActionKey;
12
- private readonly timeinHoursProvider;
13
- private readonly activeProvider;
14
- private readonly chatsWhitelistProvider;
15
- readonly cachedState: Map<string, unknown>;
16
- readonly stateConstructor: () => TActionState;
17
- readonly cachedStateFactories: Map<string, CachedStateFactory>;
18
- readonly handler: ScheduledHandler<TActionState>;
19
- constructor(name: string, handler: ScheduledHandler<TActionState>, providers: ScheduledActionProviders, cachedStateFactories: Map<string, CachedStateFactory>, stateConstructor: () => TActionState);
20
- exec(ctx: ChatContextInternal<TActionState>): Promise<import("../../types/response").BotResponse[]>;
21
- private getCachedValue;
22
- private checkIfShouldBeExecuted;
23
- }
24
- //# sourceMappingURL=scheduledAction.d.ts.map
@@ -1 +0,0 @@
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;AAGxD,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,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAK7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAE3E,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,GAAG,EAAE,SAAS,CAAC;IAExB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA8C;IAClF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA2C;IAC1E,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAErC;IAEF,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,SAAS,EAAE,wBAAwB,EACnC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EACrD,gBAAgB,EAAE,MAAM,YAAY;IAclC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,YAAY,CAAC;YA0CnC,cAAc;IA4C5B,OAAO,CAAC,uBAAuB;CAgBlC"}
@@ -1,72 +0,0 @@
1
- import moment from 'moment';
2
- import { Sema as Semaphore } from 'async-sema';
3
- import { hoursToMilliseconds } from '../../helpers/timeConvertions';
4
- import { Noop } from '../../helpers/noop';
5
- import { getOrSetIfNotExists, getOrThrow } from '../../helpers/mapUtils';
6
- export class ScheduledAction {
7
- static locks = new Map();
8
- name;
9
- key;
10
- timeinHoursProvider;
11
- activeProvider;
12
- chatsWhitelistProvider;
13
- cachedState = new Map();
14
- stateConstructor;
15
- cachedStateFactories;
16
- handler;
17
- constructor(name, handler, providers, cachedStateFactories, stateConstructor) {
18
- this.name = name;
19
- this.key = `scheduled:${this.name.replace('.', '-')}`;
20
- this.timeinHoursProvider = providers.timeinHoursProvider;
21
- this.activeProvider = providers.isActiveProvider;
22
- this.chatsWhitelistProvider = providers.chatsWhitelistProvider;
23
- this.cachedStateFactories = cachedStateFactories;
24
- this.stateConstructor = stateConstructor;
25
- this.handler = handler;
26
- }
27
- async exec(ctx) {
28
- if (!ctx.isInitialized)
29
- throw new Error(`Context for ${this.key} is not initialized or already consumed`);
30
- if (!this.activeProvider(ctx) ||
31
- !this.chatsWhitelistProvider(ctx).includes(ctx.chatInfo.id))
32
- return Noop.NoResponse;
33
- const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
34
- const isAllowedToTrigger = this.checkIfShouldBeExecuted(state, ctx);
35
- if (!isAllowedToTrigger)
36
- return Noop.NoResponse;
37
- ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
38
- await this.handler(ctx, (key) => this.getCachedValue(key, ctx.botName, ctx.scheduler), state);
39
- state.lastExecutedDate = moment().valueOf();
40
- await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
41
- return ctx.responses;
42
- }
43
- async getCachedValue(key, botName, scheduler) {
44
- const cachedItemFactory = getOrThrow(this.cachedStateFactories, key, `No shared cache was set up for the key [${key}] in action '${this.name}'`);
45
- const semaphoreKey = `${this.key}_cached:${key}`;
46
- const semaphore = getOrSetIfNotExists(ScheduledAction.locks, semaphoreKey, new Semaphore(1));
47
- await semaphore.acquire();
48
- try {
49
- if (this.cachedState.has(key)) {
50
- return this.cachedState.get(key);
51
- }
52
- const value = await cachedItemFactory.getValue();
53
- this.cachedState.set(key, value);
54
- scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () => this.cachedState.delete(key), hoursToMilliseconds(cachedItemFactory.invalidationTimeoutInHours), botName);
55
- return value;
56
- }
57
- finally {
58
- semaphore.release();
59
- }
60
- }
61
- checkIfShouldBeExecuted(state, ctx) {
62
- const startOfToday = moment().startOf('day').valueOf();
63
- const lastExecutedDate = moment(state.lastExecutedDate);
64
- const currentTime = moment();
65
- const scheduledTime = moment()
66
- .startOf('day')
67
- .add(this.timeinHoursProvider(ctx), 'hours');
68
- const isAllowedToTrigger = currentTime.isSameOrAfter(scheduledTime);
69
- const hasTriggeredToday = lastExecutedDate.isAfter(startOfToday);
70
- return isAllowedToTrigger && !hasTriggeredToday;
71
- }
72
- }
@@ -1,37 +0,0 @@
1
- import { Seconds } from '../types/timeValues';
2
- import { IStorageClient } from '../types/storage';
3
- import { IActionState } from '../types/actionState';
4
- import { CommandAction } from './actions/commandAction';
5
- import { ScheduledAction } from './actions/scheduledAction';
6
- import { ILogger } from '../types/logger';
7
- import { IScheduler } from '../types/scheduler';
8
- import { InlineQueryAction } from './actions/inlineQueryAction';
9
- export declare class BotInstance {
10
- private readonly storage;
11
- private readonly scheduler;
12
- private readonly logger;
13
- private readonly actionProcessingService;
14
- readonly name: string;
15
- constructor(options: {
16
- name: string;
17
- actions: {
18
- commands: CommandAction<IActionState>[];
19
- scheduled: ScheduledAction<IActionState>[];
20
- inlineQueries: InlineQueryAction[];
21
- };
22
- chats: Record<string, number>;
23
- storagePath?: string;
24
- services?: {
25
- storageClient?: IStorageClient;
26
- logger?: ILogger;
27
- scheduler?: IScheduler;
28
- };
29
- });
30
- start(token: string, actions: {
31
- commands: CommandAction<IActionState>[];
32
- scheduled: ScheduledAction<IActionState>[];
33
- inlineQueries: InlineQueryAction[];
34
- }, scheduledPeriod?: Seconds, verboseLoggingForIncomingMessage?: boolean): Promise<void>;
35
- stop(): Promise<void>;
36
- }
37
- //# sourceMappingURL=botInstance.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAA0B;IAElE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE;YACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;YACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;YAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;SACtC,CAAC;QACF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE;YACP,aAAa,CAAC,EAAE,cAAc,CAAC;YAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,SAAS,CAAC,EAAE,UAAU,CAAC;SAC1B,CAAC;KACL;IAwBK,KAAK,CACP,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;KACtC,EACD,eAAe,CAAC,EAAE,OAAO,EACzB,gCAAgC,CAAC,EAAE,OAAO;IAiBxC,IAAI;CAYb"}