chz-telegram-bot 0.5.1 → 0.5.3
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/dtos/chatHistoryMessage.ts +9 -1
- package/entities/botInstance.ts +1 -1
- package/entities/context/messageContext.ts +3 -3
- package/entities/context/replyContext.ts +3 -3
- package/{eslint.config.js → eslint.config.ts} +8 -5
- package/index.ts +3 -0
- package/package.json +38 -37
- package/services/actionProcessors/commandActionProcessor.ts +7 -7
- package/services/jsonFileStorage.ts +1 -1
- package/services/nodeTimeoutScheduler.ts +2 -2
- package/tsconfig.json +2 -2
- package/bun.lock +0 -301
- package/dist/builtin/helpAction.d.ts +0 -2
- package/dist/builtin/helpAction.d.ts.map +0 -1
- package/dist/builtin/helpAction.js +0 -17
- package/dist/dtos/chatHistoryMessage.d.ts +0 -13
- package/dist/dtos/chatHistoryMessage.d.ts.map +0 -1
- package/dist/dtos/chatHistoryMessage.js +0 -20
- package/dist/dtos/chatInfo.d.ts +0 -17
- package/dist/dtos/chatInfo.d.ts.map +0 -1
- package/dist/dtos/chatInfo.js +0 -20
- package/dist/dtos/commandTriggerCheckResult.d.ts +0 -24
- package/dist/dtos/commandTriggerCheckResult.d.ts.map +0 -1
- package/dist/dtos/commandTriggerCheckResult.js +0 -38
- package/dist/dtos/cooldownInfo.d.ts +0 -13
- package/dist/dtos/cooldownInfo.d.ts.map +0 -1
- package/dist/dtos/cooldownInfo.js +0 -16
- package/dist/dtos/incomingMessage.d.ts +0 -19
- package/dist/dtos/incomingMessage.d.ts.map +0 -1
- package/dist/dtos/incomingMessage.js +0 -67
- package/dist/dtos/incomingQuery.d.ts +0 -10
- package/dist/dtos/incomingQuery.d.ts.map +0 -1
- package/dist/dtos/incomingQuery.js +0 -18
- package/dist/dtos/messageInfo.d.ts +0 -22
- package/dist/dtos/messageInfo.d.ts.map +0 -1
- package/dist/dtos/messageInfo.js +0 -24
- package/dist/dtos/propertyProviderSets.d.ts +0 -16
- package/dist/dtos/propertyProviderSets.d.ts.map +0 -1
- package/dist/dtos/propertyProviderSets.js +0 -2
- package/dist/dtos/replyInfo.d.ts +0 -6
- package/dist/dtos/replyInfo.d.ts.map +0 -1
- package/dist/dtos/replyInfo.js +0 -12
- package/dist/dtos/responses/delay.d.ts +0 -16
- package/dist/dtos/responses/delay.d.ts.map +0 -1
- package/dist/dtos/responses/delay.js +0 -19
- package/dist/dtos/responses/imageMessage.d.ts +0 -22
- package/dist/dtos/responses/imageMessage.d.ts.map +0 -1
- package/dist/dtos/responses/imageMessage.js +0 -25
- package/dist/dtos/responses/inlineQueryResponse.d.ts +0 -13
- package/dist/dtos/responses/inlineQueryResponse.d.ts.map +0 -1
- package/dist/dtos/responses/inlineQueryResponse.js +0 -19
- package/dist/dtos/responses/reaction.d.ts +0 -16
- package/dist/dtos/responses/reaction.d.ts.map +0 -1
- package/dist/dtos/responses/reaction.js +0 -21
- package/dist/dtos/responses/textMessage.d.ts +0 -23
- package/dist/dtos/responses/textMessage.d.ts.map +0 -1
- package/dist/dtos/responses/textMessage.js +0 -28
- package/dist/dtos/responses/unpin.d.ts +0 -15
- package/dist/dtos/responses/unpin.d.ts.map +0 -1
- package/dist/dtos/responses/unpin.js +0 -19
- package/dist/dtos/responses/videoMessage.d.ts +0 -22
- package/dist/dtos/responses/videoMessage.d.ts.map +0 -1
- package/dist/dtos/responses/videoMessage.js +0 -25
- package/dist/dtos/userInfo.d.ts +0 -12
- package/dist/dtos/userInfo.d.ts.map +0 -1
- package/dist/dtos/userInfo.js +0 -16
- package/dist/entities/actions/commandAction.d.ts +0 -31
- package/dist/entities/actions/commandAction.d.ts.map +0 -1
- package/dist/entities/actions/commandAction.js +0 -146
- package/dist/entities/actions/inlineQueryAction.d.ts +0 -14
- package/dist/entities/actions/inlineQueryAction.d.ts.map +0 -1
- package/dist/entities/actions/inlineQueryAction.js +0 -47
- package/dist/entities/actions/replyCaptureAction.d.ts +0 -15
- package/dist/entities/actions/replyCaptureAction.d.ts.map +0 -1
- package/dist/entities/actions/replyCaptureAction.js +0 -62
- package/dist/entities/actions/scheduledAction.d.ts +0 -24
- package/dist/entities/actions/scheduledAction.d.ts.map +0 -1
- package/dist/entities/actions/scheduledAction.js +0 -79
- package/dist/entities/botInstance.d.ts +0 -37
- package/dist/entities/botInstance.d.ts.map +0 -1
- package/dist/entities/botInstance.js +0 -41
- package/dist/entities/cachedStateFactory.d.ts +0 -7
- package/dist/entities/cachedStateFactory.d.ts.map +0 -1
- package/dist/entities/cachedStateFactory.js +0 -12
- package/dist/entities/context/baseContext.d.ts +0 -39
- package/dist/entities/context/baseContext.d.ts.map +0 -1
- package/dist/entities/context/baseContext.js +0 -59
- package/dist/entities/context/chatContext.d.ts +0 -50
- package/dist/entities/context/chatContext.d.ts.map +0 -1
- package/dist/entities/context/chatContext.js +0 -69
- package/dist/entities/context/inlineQueryContext.d.ts +0 -27
- package/dist/entities/context/inlineQueryContext.d.ts.map +0 -1
- package/dist/entities/context/inlineQueryContext.js +0 -33
- package/dist/entities/context/messageContext.d.ts +0 -92
- package/dist/entities/context/messageContext.d.ts.map +0 -1
- package/dist/entities/context/messageContext.js +0 -120
- package/dist/entities/context/replyContext.d.ts +0 -89
- package/dist/entities/context/replyContext.d.ts.map +0 -1
- package/dist/entities/context/replyContext.js +0 -128
- package/dist/entities/states/actionStateBase.d.ts +0 -6
- package/dist/entities/states/actionStateBase.d.ts.map +0 -1
- package/dist/entities/states/actionStateBase.js +0 -8
- package/dist/entities/taskRecord.d.ts +0 -8
- package/dist/entities/taskRecord.d.ts.map +0 -1
- package/dist/entities/taskRecord.js +0 -14
- package/dist/helpers/builders/commandActionBuilder.d.ts +0 -100
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +0 -1
- package/dist/helpers/builders/commandActionBuilder.js +0 -151
- package/dist/helpers/builders/inlineQueryActionBuilder.d.ts +0 -37
- package/dist/helpers/builders/inlineQueryActionBuilder.d.ts.map +0 -1
- package/dist/helpers/builders/inlineQueryActionBuilder.js +0 -54
- package/dist/helpers/builders/scheduledActionBuilder.d.ts +0 -68
- package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +0 -1
- package/dist/helpers/builders/scheduledActionBuilder.js +0 -100
- package/dist/helpers/mapUtils.d.ts +0 -10
- package/dist/helpers/mapUtils.d.ts.map +0 -1
- package/dist/helpers/mapUtils.js +0 -17
- package/dist/helpers/noop.d.ts +0 -9
- package/dist/helpers/noop.d.ts.map +0 -1
- package/dist/helpers/noop.js +0 -21
- package/dist/helpers/objectFromEntries.d.ts +0 -2
- package/dist/helpers/objectFromEntries.d.ts.map +0 -1
- package/dist/helpers/objectFromEntries.js +0 -7
- package/dist/helpers/timeConvertions.d.ts +0 -5
- package/dist/helpers/timeConvertions.d.ts.map +0 -1
- package/dist/helpers/timeConvertions.js +0 -14
- package/dist/helpers/toArray.d.ts +0 -2
- package/dist/helpers/toArray.d.ts.map +0 -1
- package/dist/helpers/toArray.js +0 -6
- package/dist/helpers/traceFactory.d.ts +0 -3
- package/dist/helpers/traceFactory.d.ts.map +0 -1
- package/dist/helpers/traceFactory.js +0 -6
- package/dist/index.d.ts +0 -24
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -41
- package/dist/main.d.ts +0 -52
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js +0 -37
- package/dist/services/actionProcessingService.d.ts +0 -25
- package/dist/services/actionProcessingService.d.ts.map +0 -1
- package/dist/services/actionProcessingService.js +0 -54
- package/dist/services/actionProcessors/baseProcessor.d.ts +0 -18
- package/dist/services/actionProcessors/baseProcessor.d.ts.map +0 -1
- package/dist/services/actionProcessors/baseProcessor.js +0 -33
- package/dist/services/actionProcessors/commandActionProcessor.d.ts +0 -20
- package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +0 -1
- package/dist/services/actionProcessors/commandActionProcessor.js +0 -119
- package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +0 -11
- package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +0 -1
- package/dist/services/actionProcessors/inlineQueryActionProcessor.js +0 -65
- package/dist/services/actionProcessors/scheduledActionProcessor.d.ts +0 -17
- package/dist/services/actionProcessors/scheduledActionProcessor.d.ts.map +0 -1
- package/dist/services/actionProcessors/scheduledActionProcessor.js +0 -63
- package/dist/services/jsonFileStorage.d.ts +0 -23
- package/dist/services/jsonFileStorage.d.ts.map +0 -1
- package/dist/services/jsonFileStorage.js +0 -113
- package/dist/services/jsonLogger.d.ts +0 -11
- package/dist/services/jsonLogger.d.ts.map +0 -1
- package/dist/services/jsonLogger.js +0 -70
- package/dist/services/nodeTimeoutScheduler.d.ts +0 -13
- package/dist/services/nodeTimeoutScheduler.d.ts.map +0 -1
- package/dist/services/nodeTimeoutScheduler.js +0 -35
- package/dist/services/responseProcessingQueue.d.ts +0 -12
- package/dist/services/responseProcessingQueue.d.ts.map +0 -1
- package/dist/services/responseProcessingQueue.js +0 -41
- package/dist/services/telegramApi.d.ts +0 -23
- package/dist/services/telegramApi.d.ts.map +0 -1
- package/dist/services/telegramApi.js +0 -137
- package/dist/types/action.d.ts +0 -14
- package/dist/types/action.d.ts.map +0 -1
- package/dist/types/action.js +0 -2
- package/dist/types/actionState.d.ts +0 -5
- package/dist/types/actionState.d.ts.map +0 -1
- package/dist/types/actionState.js +0 -2
- package/dist/types/cachedValueAccessor.d.ts +0 -2
- package/dist/types/cachedValueAccessor.d.ts.map +0 -1
- package/dist/types/cachedValueAccessor.js +0 -2
- package/dist/types/capture.d.ts +0 -24
- package/dist/types/capture.d.ts.map +0 -1
- package/dist/types/capture.js +0 -2
- package/dist/types/commandCondition.d.ts +0 -8
- package/dist/types/commandCondition.d.ts.map +0 -1
- package/dist/types/commandCondition.js +0 -2
- package/dist/types/commandTrigger.d.ts +0 -2
- package/dist/types/commandTrigger.d.ts.map +0 -1
- package/dist/types/commandTrigger.js +0 -2
- package/dist/types/externalAliases.d.ts +0 -11
- package/dist/types/externalAliases.d.ts.map +0 -1
- package/dist/types/externalAliases.js +0 -2
- package/dist/types/handlers.d.ts +0 -21
- package/dist/types/handlers.d.ts.map +0 -1
- package/dist/types/handlers.js +0 -2
- package/dist/types/inputFile.d.ts +0 -5
- package/dist/types/inputFile.d.ts.map +0 -1
- package/dist/types/inputFile.js +0 -2
- package/dist/types/logger.d.ts +0 -13
- package/dist/types/logger.d.ts.map +0 -1
- package/dist/types/logger.js +0 -2
- package/dist/types/messageSendingOptions.d.ts +0 -9
- package/dist/types/messageSendingOptions.d.ts.map +0 -1
- package/dist/types/messageSendingOptions.js +0 -2
- package/dist/types/messageTypes.d.ts +0 -20
- package/dist/types/messageTypes.d.ts.map +0 -1
- package/dist/types/messageTypes.js +0 -21
- package/dist/types/propertyProvider.d.ts +0 -8
- package/dist/types/propertyProvider.d.ts.map +0 -1
- package/dist/types/propertyProvider.js +0 -2
- package/dist/types/response.d.ts +0 -39
- package/dist/types/response.d.ts.map +0 -1
- package/dist/types/response.js +0 -12
- package/dist/types/scheduler.d.ts +0 -7
- package/dist/types/scheduler.d.ts.map +0 -1
- package/dist/types/scheduler.js +0 -2
- package/dist/types/storage.d.ts +0 -11
- package/dist/types/storage.d.ts.map +0 -1
- package/dist/types/storage.js +0 -2
- package/dist/types/timeValues.d.ts +0 -15
- package/dist/types/timeValues.d.ts.map +0 -1
- package/dist/types/timeValues.js +0 -2
- package/dist/types/trace.d.ts +0 -6
- package/dist/types/trace.d.ts.map +0 -1
- package/dist/types/trace.js +0 -2
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TextMessage = void 0;
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
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;
|
|
16
|
-
keyboard;
|
|
17
|
-
constructor(text, chatInfo, traceId, action, replyInfo, options) {
|
|
18
|
-
this.content = text;
|
|
19
|
-
this.chatInfo = chatInfo;
|
|
20
|
-
this.replyInfo = replyInfo;
|
|
21
|
-
this.traceId = traceId;
|
|
22
|
-
this.disableWebPreview = options?.disableWebPreview ?? false;
|
|
23
|
-
this.shouldPin = options?.pin ?? false;
|
|
24
|
-
this.action = action;
|
|
25
|
-
this.keyboard = options?.keyboard;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.TextMessage = TextMessage;
|
|
@@ -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,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnpinResponse = void 0;
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class UnpinResponse {
|
|
6
|
-
kind = response_1.BotResponseTypes.unpin;
|
|
7
|
-
createdAt = Date.now();
|
|
8
|
-
messageId;
|
|
9
|
-
chatInfo;
|
|
10
|
-
traceId;
|
|
11
|
-
action;
|
|
12
|
-
constructor(messageId, chatInfo, traceId, action) {
|
|
13
|
-
this.messageId = messageId;
|
|
14
|
-
this.chatInfo = chatInfo;
|
|
15
|
-
this.traceId = traceId;
|
|
16
|
-
this.action = action;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.UnpinResponse = UnpinResponse;
|
|
@@ -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,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VideoMessage = void 0;
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
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;
|
|
16
|
-
constructor(video, chatInfo, traceId, action, replyInfo, options) {
|
|
17
|
-
this.content = video;
|
|
18
|
-
this.chatInfo = chatInfo;
|
|
19
|
-
this.replyInfo = replyInfo;
|
|
20
|
-
this.traceId = traceId;
|
|
21
|
-
this.shouldPin = options?.pin ?? false;
|
|
22
|
-
this.action = action;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.VideoMessage = VideoMessage;
|
package/dist/dtos/userInfo.d.ts
DELETED
|
@@ -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"}
|
package/dist/dtos/userInfo.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserInfo = void 0;
|
|
4
|
-
class UserInfo {
|
|
5
|
-
id;
|
|
6
|
-
name;
|
|
7
|
-
constructor(
|
|
8
|
-
/** Id of a user that sent a message that triggered this action. */
|
|
9
|
-
id,
|
|
10
|
-
/** Name of a user that sent a message that triggered this action. */
|
|
11
|
-
name) {
|
|
12
|
-
this.id = id;
|
|
13
|
-
this.name = name;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.UserInfo = UserInfo;
|
|
@@ -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,146 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CommandAction = void 0;
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const timeConvertions_1 = require("../../helpers/timeConvertions");
|
|
9
|
-
const toArray_1 = require("../../helpers/toArray");
|
|
10
|
-
const commandTriggerCheckResult_1 = require("../../dtos/commandTriggerCheckResult");
|
|
11
|
-
const noop_1 = require("../../helpers/noop");
|
|
12
|
-
const messageTypes_1 = require("../../types/messageTypes");
|
|
13
|
-
const async_sema_1 = require("async-sema");
|
|
14
|
-
const mapUtils_1 = require("../../helpers/mapUtils");
|
|
15
|
-
const textMessage_1 = require("../../dtos/responses/textMessage");
|
|
16
|
-
const replyInfo_1 = require("../../dtos/replyInfo");
|
|
17
|
-
class CommandAction {
|
|
18
|
-
cooldownInfoProvider;
|
|
19
|
-
isActiveProvider;
|
|
20
|
-
chatsBlacklistProvider;
|
|
21
|
-
chatsWhitelistProvider;
|
|
22
|
-
usersWhitelistProvider;
|
|
23
|
-
key;
|
|
24
|
-
name;
|
|
25
|
-
ratelimitSemaphores = new Map();
|
|
26
|
-
maxAllowedSimultaniousExecutions;
|
|
27
|
-
triggers;
|
|
28
|
-
handler;
|
|
29
|
-
condition;
|
|
30
|
-
stateConstructor;
|
|
31
|
-
readmeFactory;
|
|
32
|
-
lastCustomCooldown;
|
|
33
|
-
constructor(trigger, handler, name, providers, maxAllowedSimultaniousExecutions, condition, stateConstructor, readmeFactory) {
|
|
34
|
-
this.triggers = (0, toArray_1.toArray)(trigger);
|
|
35
|
-
this.name = name;
|
|
36
|
-
this.cooldownInfoProvider = providers.cooldownProvider;
|
|
37
|
-
this.isActiveProvider = providers.isActiveProvider;
|
|
38
|
-
this.chatsBlacklistProvider = providers.chatsBlacklistProvider;
|
|
39
|
-
this.chatsWhitelistProvider = providers.chatsWhitelistProvider;
|
|
40
|
-
this.usersWhitelistProvider = providers.usersWhitelistProvider;
|
|
41
|
-
this.handler = handler;
|
|
42
|
-
this.condition = condition;
|
|
43
|
-
this.stateConstructor = stateConstructor;
|
|
44
|
-
this.readmeFactory = readmeFactory;
|
|
45
|
-
this.maxAllowedSimultaniousExecutions =
|
|
46
|
-
maxAllowedSimultaniousExecutions;
|
|
47
|
-
this.key = `command:${this.name.replace('.', '-')}`;
|
|
48
|
-
}
|
|
49
|
-
async exec(ctx) {
|
|
50
|
-
if (!ctx.isInitialized)
|
|
51
|
-
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
52
|
-
let lock;
|
|
53
|
-
if (this.maxAllowedSimultaniousExecutions != 0) {
|
|
54
|
-
lock = (0, mapUtils_1.getOrSetIfNotExists)(this.ratelimitSemaphores, ctx.chatInfo.id, new async_sema_1.Sema(this.maxAllowedSimultaniousExecutions));
|
|
55
|
-
await lock.acquire();
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
|
|
59
|
-
const { shouldExecute, matchResults, skipCooldown, reason } = this.triggers
|
|
60
|
-
.map((x) => this.checkIfShouldBeExecuted(ctx, x, state))
|
|
61
|
-
.reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('Other'));
|
|
62
|
-
if (!shouldExecute) {
|
|
63
|
-
if (reason == 'OnCooldown') {
|
|
64
|
-
const cooldownMessage = this.cooldownInfoProvider(ctx).message;
|
|
65
|
-
return cooldownMessage
|
|
66
|
-
? [
|
|
67
|
-
new textMessage_1.TextMessage(cooldownMessage, ctx.chatInfo, ctx.traceId, this, new replyInfo_1.ReplyInfo(ctx.messageInfo.id))
|
|
68
|
-
]
|
|
69
|
-
: noop_1.Noop.NoResponse;
|
|
70
|
-
}
|
|
71
|
-
return noop_1.Noop.NoResponse;
|
|
72
|
-
}
|
|
73
|
-
ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
|
|
74
|
-
ctx.matchResults = matchResults;
|
|
75
|
-
await this.handler(ctx, state);
|
|
76
|
-
if (skipCooldown) {
|
|
77
|
-
ctx.startCooldown = false;
|
|
78
|
-
}
|
|
79
|
-
if (ctx.startCooldown) {
|
|
80
|
-
this.lastCustomCooldown = ctx.customCooldown;
|
|
81
|
-
state.lastExecutedDate = (0, moment_1.default)().valueOf();
|
|
82
|
-
}
|
|
83
|
-
await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
|
|
84
|
-
return ctx.responses;
|
|
85
|
-
}
|
|
86
|
-
finally {
|
|
87
|
-
lock?.release();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
checkIfShouldBeExecuted(ctx, trigger, state) {
|
|
91
|
-
if (!this.isActiveProvider(ctx))
|
|
92
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ActionDisabled');
|
|
93
|
-
const chatsBlacklist = this.chatsBlacklistProvider(ctx);
|
|
94
|
-
const chatsWhitelist = this.chatsWhitelistProvider(ctx);
|
|
95
|
-
const isChatInBlacklist = chatsBlacklist.includes(ctx.chatInfo.id);
|
|
96
|
-
const isChatInWhitelist = chatsWhitelist.length == 0 ||
|
|
97
|
-
chatsWhitelist.includes(ctx.chatInfo.id);
|
|
98
|
-
if (isChatInBlacklist || !isChatInWhitelist)
|
|
99
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ChatForbidden');
|
|
100
|
-
const triggerCheckResult = this.checkTrigger(ctx, trigger);
|
|
101
|
-
if (!triggerCheckResult.shouldExecute)
|
|
102
|
-
return triggerCheckResult;
|
|
103
|
-
if (!ctx.userInfo.id)
|
|
104
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserIdMissing');
|
|
105
|
-
const usersWhitelist = this.usersWhitelistProvider(ctx);
|
|
106
|
-
const isUserAllowed = usersWhitelist.length == 0 ||
|
|
107
|
-
usersWhitelist.includes(ctx.userInfo.id);
|
|
108
|
-
if (!isUserAllowed)
|
|
109
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserForbidden');
|
|
110
|
-
const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
|
|
111
|
-
const cooldownInMilliseconds = (0, timeConvertions_1.secondsToMilliseconds)(this.lastCustomCooldown ?? this.cooldownInfoProvider(ctx).cooldown);
|
|
112
|
-
const onCooldown = (0, moment_1.default)().diff(lastExecutedDate) < cooldownInMilliseconds;
|
|
113
|
-
if (onCooldown)
|
|
114
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('OnCooldown');
|
|
115
|
-
const isCustomConditionMet = this.condition(ctx, state);
|
|
116
|
-
if (!isCustomConditionMet)
|
|
117
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('CustomConditionNotMet');
|
|
118
|
-
return triggerCheckResult;
|
|
119
|
-
}
|
|
120
|
-
checkTrigger(ctx, trigger) {
|
|
121
|
-
if (trigger == messageTypes_1.MessageType.Any || trigger == ctx.messageInfo.type)
|
|
122
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger();
|
|
123
|
-
if (typeof trigger == 'string')
|
|
124
|
-
return ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase()
|
|
125
|
-
? commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger()
|
|
126
|
-
: commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
127
|
-
const matchResults = [];
|
|
128
|
-
trigger.lastIndex = 0;
|
|
129
|
-
const execResult = trigger.exec(ctx.messageInfo.text);
|
|
130
|
-
if (execResult != null) {
|
|
131
|
-
let regexMatchLimit = 100;
|
|
132
|
-
matchResults.push(execResult);
|
|
133
|
-
if (trigger.global) {
|
|
134
|
-
while (regexMatchLimit > 0) {
|
|
135
|
-
const nextResult = trigger.exec(ctx.messageInfo.text);
|
|
136
|
-
if (nextResult == null)
|
|
137
|
-
break;
|
|
138
|
-
matchResults.push(nextResult);
|
|
139
|
-
regexMatchLimit -= 1;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return new commandTriggerCheckResult_1.CommandTriggerCheckResult(matchResults.length > 0, matchResults, false);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
exports.CommandAction = CommandAction;
|
|
@@ -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,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InlineQueryAction = void 0;
|
|
4
|
-
const noop_1 = require("../../helpers/noop");
|
|
5
|
-
class InlineQueryAction {
|
|
6
|
-
key;
|
|
7
|
-
isActiveProvider;
|
|
8
|
-
handler;
|
|
9
|
-
name;
|
|
10
|
-
pattern;
|
|
11
|
-
constructor(handler, name, activeProvider, pattern) {
|
|
12
|
-
this.handler = handler;
|
|
13
|
-
this.name = name;
|
|
14
|
-
this.isActiveProvider = activeProvider;
|
|
15
|
-
this.pattern = pattern;
|
|
16
|
-
this.key = `inline:${this.name.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
|
-
if (!this.isActiveProvider(ctx))
|
|
22
|
-
return noop_1.Noop.NoResponse;
|
|
23
|
-
const matchResults = [];
|
|
24
|
-
this.pattern.lastIndex = 0;
|
|
25
|
-
const execResult = this.pattern.exec(ctx.queryText);
|
|
26
|
-
if (execResult != null) {
|
|
27
|
-
let regexMatchLimit = 100;
|
|
28
|
-
matchResults.push(execResult);
|
|
29
|
-
if (this.pattern.global) {
|
|
30
|
-
while (regexMatchLimit > 0) {
|
|
31
|
-
const nextResult = this.pattern.exec(ctx.queryText);
|
|
32
|
-
if (nextResult == null)
|
|
33
|
-
break;
|
|
34
|
-
matchResults.push(nextResult);
|
|
35
|
-
regexMatchLimit -= 1;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (matchResults.length == 0)
|
|
40
|
-
return noop_1.Noop.NoResponse;
|
|
41
|
-
ctx.matchResults = matchResults;
|
|
42
|
-
ctx.logger.logWithTraceId(` - Executing [${this.name}]`);
|
|
43
|
-
await this.handler(ctx);
|
|
44
|
-
return ctx.responses;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.InlineQueryAction = InlineQueryAction;
|
|
@@ -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,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReplyCaptureAction = void 0;
|
|
4
|
-
const commandTriggerCheckResult_1 = require("../../dtos/commandTriggerCheckResult");
|
|
5
|
-
const noop_1 = require("../../helpers/noop");
|
|
6
|
-
class ReplyCaptureAction {
|
|
7
|
-
parentMessageId;
|
|
8
|
-
key;
|
|
9
|
-
handler;
|
|
10
|
-
triggers;
|
|
11
|
-
abortController;
|
|
12
|
-
constructor(parentMessageId, parentAction, handler, triggers, abortController) {
|
|
13
|
-
this.parentMessageId = parentMessageId;
|
|
14
|
-
this.handler = handler;
|
|
15
|
-
this.triggers = triggers;
|
|
16
|
-
this.abortController = abortController;
|
|
17
|
-
this.key = `capture:${parentAction.key}:${Math.random()
|
|
18
|
-
.toString()
|
|
19
|
-
.replace('.', '')}`;
|
|
20
|
-
}
|
|
21
|
-
async exec(ctx) {
|
|
22
|
-
if (!ctx.isInitialized)
|
|
23
|
-
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
24
|
-
const { shouldExecute, matchResults } = this.triggers
|
|
25
|
-
.map((x) => this.checkIfShouldBeExecuted(ctx, x))
|
|
26
|
-
.reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('Other'));
|
|
27
|
-
if (!shouldExecute)
|
|
28
|
-
return noop_1.Noop.NoResponse;
|
|
29
|
-
ctx.logger.logWithTraceId(` - Executing [${this.key}] in ${ctx.chatInfo.id}`);
|
|
30
|
-
ctx.matchResults = matchResults;
|
|
31
|
-
await this.handler(ctx);
|
|
32
|
-
return ctx.responses;
|
|
33
|
-
}
|
|
34
|
-
checkIfShouldBeExecuted(ctx, trigger) {
|
|
35
|
-
if (ctx.replyMessageId != this.parentMessageId)
|
|
36
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
37
|
-
if (trigger == ctx.messageInfo.type)
|
|
38
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger();
|
|
39
|
-
if (typeof trigger == 'string')
|
|
40
|
-
return ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase()
|
|
41
|
-
? commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger()
|
|
42
|
-
: commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
43
|
-
const matchResults = [];
|
|
44
|
-
trigger.lastIndex = 0;
|
|
45
|
-
const execResult = trigger.exec(ctx.messageInfo.text);
|
|
46
|
-
if (execResult != null) {
|
|
47
|
-
let regexMatchLimit = 100;
|
|
48
|
-
matchResults.push(execResult);
|
|
49
|
-
if (trigger.global) {
|
|
50
|
-
while (regexMatchLimit > 0) {
|
|
51
|
-
const nextResult = trigger.exec(ctx.messageInfo.text);
|
|
52
|
-
if (nextResult == null)
|
|
53
|
-
break;
|
|
54
|
-
matchResults.push(nextResult);
|
|
55
|
-
regexMatchLimit -= 1;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return new commandTriggerCheckResult_1.CommandTriggerCheckResult(matchResults.length > 0, matchResults, false);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.ReplyCaptureAction = ReplyCaptureAction;
|
|
@@ -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,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ScheduledAction = void 0;
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const async_sema_1 = require("async-sema");
|
|
9
|
-
const timeConvertions_1 = require("../../helpers/timeConvertions");
|
|
10
|
-
const noop_1 = require("../../helpers/noop");
|
|
11
|
-
const mapUtils_1 = require("../../helpers/mapUtils");
|
|
12
|
-
class ScheduledAction {
|
|
13
|
-
static locks = new Map();
|
|
14
|
-
name;
|
|
15
|
-
key;
|
|
16
|
-
timeinHoursProvider;
|
|
17
|
-
activeProvider;
|
|
18
|
-
chatsWhitelistProvider;
|
|
19
|
-
cachedState = new Map();
|
|
20
|
-
stateConstructor;
|
|
21
|
-
cachedStateFactories;
|
|
22
|
-
handler;
|
|
23
|
-
constructor(name, handler, providers, cachedStateFactories, stateConstructor) {
|
|
24
|
-
this.name = name;
|
|
25
|
-
this.key = `scheduled:${this.name.replace('.', '-')}`;
|
|
26
|
-
this.timeinHoursProvider = providers.timeinHoursProvider;
|
|
27
|
-
this.activeProvider = providers.isActiveProvider;
|
|
28
|
-
this.chatsWhitelistProvider = providers.chatsWhitelistProvider;
|
|
29
|
-
this.cachedStateFactories = cachedStateFactories;
|
|
30
|
-
this.stateConstructor = stateConstructor;
|
|
31
|
-
this.handler = handler;
|
|
32
|
-
}
|
|
33
|
-
async exec(ctx) {
|
|
34
|
-
if (!ctx.isInitialized)
|
|
35
|
-
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
36
|
-
if (!this.activeProvider(ctx) ||
|
|
37
|
-
!this.chatsWhitelistProvider(ctx).includes(ctx.chatInfo.id))
|
|
38
|
-
return noop_1.Noop.NoResponse;
|
|
39
|
-
const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
|
|
40
|
-
const isAllowedToTrigger = this.checkIfShouldBeExecuted(state, ctx);
|
|
41
|
-
if (!isAllowedToTrigger)
|
|
42
|
-
return noop_1.Noop.NoResponse;
|
|
43
|
-
ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
|
|
44
|
-
await this.handler(ctx, (key) => this.getCachedValue(key, ctx.botName, ctx.scheduler), state);
|
|
45
|
-
state.lastExecutedDate = (0, moment_1.default)().valueOf();
|
|
46
|
-
await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
|
|
47
|
-
return ctx.responses;
|
|
48
|
-
}
|
|
49
|
-
async getCachedValue(key, botName, scheduler) {
|
|
50
|
-
const cachedItemFactory = (0, mapUtils_1.getOrThrow)(this.cachedStateFactories, key, `No shared cache was set up for the key [${key}] in action '${this.name}'`);
|
|
51
|
-
const semaphoreKey = `${this.key}_cached:${key}`;
|
|
52
|
-
const semaphore = (0, mapUtils_1.getOrSetIfNotExists)(ScheduledAction.locks, semaphoreKey, new async_sema_1.Sema(1));
|
|
53
|
-
await semaphore.acquire();
|
|
54
|
-
try {
|
|
55
|
-
if (this.cachedState.has(key)) {
|
|
56
|
-
return this.cachedState.get(key);
|
|
57
|
-
}
|
|
58
|
-
const value = await cachedItemFactory.getValue();
|
|
59
|
-
this.cachedState.set(key, value);
|
|
60
|
-
scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () => this.cachedState.delete(key), (0, timeConvertions_1.hoursToMilliseconds)(cachedItemFactory.invalidationTimeoutInHours), botName);
|
|
61
|
-
return value;
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
semaphore.release();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
checkIfShouldBeExecuted(state, ctx) {
|
|
68
|
-
const startOfToday = (0, moment_1.default)().startOf('day').valueOf();
|
|
69
|
-
const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
|
|
70
|
-
const currentTime = (0, moment_1.default)();
|
|
71
|
-
const scheduledTime = (0, moment_1.default)()
|
|
72
|
-
.startOf('day')
|
|
73
|
-
.add(this.timeinHoursProvider(ctx), 'hours');
|
|
74
|
-
const isAllowedToTrigger = currentTime.isSameOrAfter(scheduledTime);
|
|
75
|
-
const hasTriggeredToday = lastExecutedDate.isAfter(startOfToday);
|
|
76
|
-
return isAllowedToTrigger && !hasTriggeredToday;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.ScheduledAction = ScheduledAction;
|
|
@@ -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"}
|