chz-telegram-bot 0.0.50 → 0.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dtos/actionExecutionResult.d.ts +7 -0
- package/dist/dtos/actionExecutionResult.d.ts.map +1 -0
- package/dist/dtos/actionExecutionResult.js +10 -0
- package/dist/dtos/chatInfo.d.ts +8 -0
- package/dist/dtos/chatInfo.d.ts.map +1 -0
- package/dist/dtos/chatInfo.js +10 -0
- package/dist/dtos/commandTriggerCheckResult.d.ts +10 -0
- package/dist/dtos/commandTriggerCheckResult.d.ts.map +1 -0
- package/dist/dtos/commandTriggerCheckResult.js +20 -0
- package/dist/dtos/incomingMessage.d.ts +14 -0
- package/dist/dtos/incomingMessage.d.ts.map +1 -0
- package/dist/dtos/incomingMessage.js +44 -0
- package/dist/dtos/responses/delay.d.ts +14 -0
- package/dist/dtos/responses/delay.d.ts.map +1 -0
- package/dist/dtos/responses/delay.js +14 -0
- package/dist/dtos/responses/imageMessage.d.ts +18 -0
- package/dist/dtos/responses/imageMessage.d.ts.map +1 -0
- package/dist/dtos/responses/imageMessage.js +17 -0
- package/dist/dtos/responses/reaction.d.ts +15 -0
- package/dist/dtos/responses/reaction.d.ts.map +1 -0
- package/dist/dtos/responses/reaction.js +15 -0
- package/dist/dtos/responses/textMessage.d.ts +17 -0
- package/dist/dtos/responses/textMessage.d.ts.map +1 -0
- package/dist/dtos/responses/textMessage.js +17 -0
- package/dist/dtos/responses/unpin.d.ts +13 -0
- package/dist/dtos/responses/unpin.d.ts.map +1 -0
- package/dist/dtos/responses/unpin.js +14 -0
- package/dist/dtos/responses/videoMessage.d.ts +18 -0
- package/dist/dtos/responses/videoMessage.d.ts.map +1 -0
- package/dist/dtos/responses/videoMessage.js +17 -0
- package/dist/entities/actions/commandAction.d.ts +11 -10
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +41 -40
- package/dist/entities/actions/scheduledAction.d.ts +11 -11
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
- package/dist/entities/actions/scheduledAction.js +14 -18
- package/dist/entities/botInstance.d.ts +16 -8
- package/dist/entities/botInstance.d.ts.map +1 -1
- package/dist/entities/botInstance.js +26 -18
- package/dist/entities/cachedStateFactory.d.ts +2 -2
- package/dist/entities/cachedStateFactory.d.ts.map +1 -1
- package/dist/entities/context/chatContext.d.ts +13 -14
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +16 -24
- package/dist/entities/context/messageContext.d.ts +5 -3
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +13 -13
- package/dist/entities/taskRecord.d.ts +3 -3
- package/dist/entities/taskRecord.d.ts.map +1 -1
- package/dist/helpers/noop.d.ts +4 -2
- package/dist/helpers/noop.d.ts.map +1 -1
- package/dist/helpers/noop.js +3 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/main.d.ts +10 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -11
- package/dist/services/jsonFileStorage.d.ts +5 -6
- package/dist/services/jsonFileStorage.d.ts.map +1 -1
- package/dist/services/jsonFileStorage.js +3 -5
- package/dist/services/jsonLogger.d.ts +8 -0
- package/dist/services/jsonLogger.d.ts.map +1 -0
- package/dist/services/jsonLogger.js +28 -0
- package/dist/services/nodeTimeoutScheduler.d.ts +13 -0
- package/dist/services/nodeTimeoutScheduler.d.ts.map +1 -0
- package/dist/services/nodeTimeoutScheduler.js +33 -0
- package/dist/services/taskScheduler.d.ts +1 -1
- package/dist/services/taskScheduler.d.ts.map +1 -1
- package/dist/services/telegramApi.d.ts +7 -14
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +12 -20
- package/dist/types/actionWithState.d.ts +2 -2
- package/dist/types/actionWithState.d.ts.map +1 -1
- package/dist/types/commandCondition.d.ts +1 -1
- package/dist/types/commandCondition.d.ts.map +1 -1
- package/dist/types/logger.d.ts +6 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/logger.js +2 -0
- package/dist/types/response.d.ts +15 -14
- package/dist/types/response.d.ts.map +1 -1
- package/dist/types/scheduler.d.ts +7 -0
- package/dist/types/scheduler.d.ts.map +1 -0
- package/dist/types/scheduler.js +2 -0
- package/dist/types/storage.d.ts +1 -2
- package/dist/types/storage.d.ts.map +1 -1
- package/dtos/chatInfo.ts +11 -0
- package/{entities → dtos}/commandTriggerCheckResult.ts +10 -10
- package/{entities → dtos}/incomingMessage.ts +13 -12
- package/{entities → dtos}/responses/delay.ts +8 -7
- package/{entities → dtos}/responses/imageMessage.ts +11 -10
- package/{entities → dtos}/responses/reaction.ts +9 -8
- package/{entities → dtos}/responses/textMessage.ts +11 -10
- package/{entities → dtos}/responses/unpin.ts +8 -7
- package/{entities → dtos}/responses/videoMessage.ts +11 -10
- package/entities/actions/commandAction.ts +64 -56
- package/entities/actions/scheduledAction.ts +40 -43
- package/entities/botInstance.ts +64 -35
- package/entities/cachedStateFactory.ts +2 -2
- package/entities/context/chatContext.ts +40 -34
- package/entities/context/messageContext.ts +21 -18
- package/entities/taskRecord.ts +3 -3
- package/helpers/noop.ts +5 -2
- package/index.ts +3 -1
- package/main.ts +16 -15
- package/package.json +1 -1
- package/services/jsonFileStorage.ts +8 -10
- package/services/{logger.ts → jsonLogger.ts} +3 -3
- package/services/{taskScheduler.ts → nodeTimeoutScheduler.ts} +12 -8
- package/services/telegramApi.ts +19 -54
- package/types/actionWithState.ts +2 -2
- package/types/commandCondition.ts +1 -1
- package/types/logger.ts +24 -0
- package/types/response.ts +15 -14
- package/types/scheduler.ts +20 -0
- package/types/storage.ts +1 -2
- package/entities/actionExecutionResult.ts +0 -11
- package/helpers/inverseRecord.ts +0 -7
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IActionState } from '../types/actionState';
|
|
2
|
+
export declare class ActionExecutionResult<TActionState extends IActionState> {
|
|
3
|
+
readonly data: TActionState;
|
|
4
|
+
readonly shouldUpdate: boolean;
|
|
5
|
+
constructor(data: TActionState, shouldUpdate: boolean);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=actionExecutionResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionExecutionResult.d.ts","sourceRoot":"","sources":["../../dtos/actionExecutionResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,qBAAa,qBAAqB,CAAC,YAAY,SAAS,YAAY;IAChE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;gBAEnB,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO;CAIxD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionExecutionResult = void 0;
|
|
4
|
+
class ActionExecutionResult {
|
|
5
|
+
constructor(data, shouldUpdate) {
|
|
6
|
+
this.data = data;
|
|
7
|
+
this.shouldUpdate = shouldUpdate;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ActionExecutionResult = ActionExecutionResult;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class ChatInfo {
|
|
2
|
+
/** Id of a chat that action is executed in. */
|
|
3
|
+
readonly id: number;
|
|
4
|
+
/** Name of a chat that action is executed in. */
|
|
5
|
+
readonly name: string;
|
|
6
|
+
constructor(chatId: number, chatName: string);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=chatInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatInfo.d.ts","sourceRoot":"","sources":["../../dtos/chatInfo.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACjB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAI/C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class CommandTriggerCheckResult {
|
|
2
|
+
static get DontTriggerAndSkipCooldown(): CommandTriggerCheckResult;
|
|
3
|
+
static get DoNotTrigger(): CommandTriggerCheckResult;
|
|
4
|
+
readonly shouldExecute: boolean;
|
|
5
|
+
readonly matchResults: RegExpExecArray[];
|
|
6
|
+
readonly skipCooldown: boolean;
|
|
7
|
+
constructor(shouldExecute: boolean, matchResults: RegExpExecArray[], skipCooldown: boolean);
|
|
8
|
+
mergeWith(other: CommandTriggerCheckResult): CommandTriggerCheckResult;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=commandTriggerCheckResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandTriggerCheckResult.d.ts","sourceRoot":"","sources":["../../dtos/commandTriggerCheckResult.ts"],"names":[],"mappings":"AAAA,qBAAa,yBAAyB;IAClC,MAAM,KAAK,0BAA0B,8BAEpC;IACD,MAAM,KAAK,YAAY,8BAEtB;IAED,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,eAAe,EAAE,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;gBAG3B,aAAa,EAAE,OAAO,EACtB,YAAY,EAAE,eAAe,EAAE,EAC/B,YAAY,EAAE,OAAO;IAOzB,SAAS,CAAC,KAAK,EAAE,yBAAyB;CAO7C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandTriggerCheckResult = void 0;
|
|
4
|
+
class CommandTriggerCheckResult {
|
|
5
|
+
static get DontTriggerAndSkipCooldown() {
|
|
6
|
+
return new CommandTriggerCheckResult(false, [], true);
|
|
7
|
+
}
|
|
8
|
+
static get DoNotTrigger() {
|
|
9
|
+
return new CommandTriggerCheckResult(false, [], false);
|
|
10
|
+
}
|
|
11
|
+
constructor(shouldExecute, matchResults, skipCooldown) {
|
|
12
|
+
this.shouldExecute = shouldExecute;
|
|
13
|
+
this.matchResults = matchResults;
|
|
14
|
+
this.skipCooldown = skipCooldown;
|
|
15
|
+
}
|
|
16
|
+
mergeWith(other) {
|
|
17
|
+
return new CommandTriggerCheckResult(this.shouldExecute || other.shouldExecute, this.matchResults.concat(other.matchResults), this.skipCooldown || other.skipCooldown);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.CommandTriggerCheckResult = CommandTriggerCheckResult;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Message, Update, User } from 'telegraf/types';
|
|
2
|
+
import { MessageTypeValue } from '../types/messageTypes';
|
|
3
|
+
import { ChatInfo } from './chatInfo';
|
|
4
|
+
export declare class IncomingMessage {
|
|
5
|
+
readonly message_id: number;
|
|
6
|
+
readonly chatInfo: ChatInfo;
|
|
7
|
+
readonly from: User | undefined;
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly type: MessageTypeValue;
|
|
10
|
+
readonly traceId: number;
|
|
11
|
+
private detectMessageType;
|
|
12
|
+
constructor(ctxMessage: Update.New & (Update.NonChannel & Message));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=incomingMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incomingMessage.d.ts","sourceRoot":"","sources":["../../dtos/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,qBAAa,eAAe;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,OAAO,SAA2B;IAE3C,OAAO,CAAC,iBAAiB;gBAkBb,UAAU,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;CAYrE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IncomingMessage = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const messageTypes_1 = require("../types/messageTypes");
|
|
6
|
+
const chatInfo_1 = require("./chatInfo");
|
|
7
|
+
class IncomingMessage {
|
|
8
|
+
detectMessageType(message) {
|
|
9
|
+
if ('text' in message)
|
|
10
|
+
return messageTypes_1.MessageType.Text;
|
|
11
|
+
if ('photo' in message)
|
|
12
|
+
return messageTypes_1.MessageType.Photo;
|
|
13
|
+
if ('sticker' in message)
|
|
14
|
+
return messageTypes_1.MessageType.Sticker;
|
|
15
|
+
if ('animation' in message)
|
|
16
|
+
return messageTypes_1.MessageType.Animation;
|
|
17
|
+
if ('voice' in message)
|
|
18
|
+
return messageTypes_1.MessageType.Voice;
|
|
19
|
+
if ('audio' in message)
|
|
20
|
+
return messageTypes_1.MessageType.Audio;
|
|
21
|
+
if ('document' in message)
|
|
22
|
+
return messageTypes_1.MessageType.Document;
|
|
23
|
+
if ('left_chat_member' in message)
|
|
24
|
+
return messageTypes_1.MessageType.LeftChatMember;
|
|
25
|
+
if ('new_chat_member' in message)
|
|
26
|
+
return messageTypes_1.MessageType.NewChatMember;
|
|
27
|
+
if ('poll' in message)
|
|
28
|
+
return messageTypes_1.MessageType.Poll;
|
|
29
|
+
if ('location' in message)
|
|
30
|
+
return messageTypes_1.MessageType.Location;
|
|
31
|
+
return messageTypes_1.MessageType.Unknown;
|
|
32
|
+
}
|
|
33
|
+
constructor(ctxMessage) {
|
|
34
|
+
this.traceId = (0, crypto_1.randomInt)(10000, 99999);
|
|
35
|
+
this.message_id = ctxMessage.message_id;
|
|
36
|
+
this.from = ctxMessage.from;
|
|
37
|
+
this.text = 'text' in ctxMessage ? ctxMessage.text : '';
|
|
38
|
+
this.chatInfo = new chatInfo_1.ChatInfo(ctxMessage.chat.id, 'title' in ctxMessage.chat
|
|
39
|
+
? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
|
|
40
|
+
: 'DM');
|
|
41
|
+
this.type = this.detectMessageType(ctxMessage);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.IncomingMessage = IncomingMessage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IActionState } from '../../types/actionState';
|
|
2
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
3
|
+
import { IChatResponse } from '../../types/response';
|
|
4
|
+
import { Milliseconds } from '../../types/timeValues';
|
|
5
|
+
import { ChatInfo } from '../chatInfo';
|
|
6
|
+
export declare class DelayResponse implements IChatResponse {
|
|
7
|
+
readonly kind: "delay";
|
|
8
|
+
readonly chatInfo: ChatInfo;
|
|
9
|
+
readonly traceId: number | string;
|
|
10
|
+
readonly delay: Milliseconds;
|
|
11
|
+
readonly action: IActionWithState<IActionState>;
|
|
12
|
+
constructor(delay: Milliseconds, chatInfo: ChatInfo, traceId: number | string, action: IActionWithState<IActionState>);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=delay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../../dtos/responses/delay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,qBAAa,aAAc,YAAW,aAAa;IAC/C,QAAQ,CAAC,IAAI,UAA0B;IAEvC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG5C,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC;CAO7C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DelayResponse = void 0;
|
|
4
|
+
const response_1 = require("../../types/response");
|
|
5
|
+
class DelayResponse {
|
|
6
|
+
constructor(delay, chatInfo, traceId, action) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.delay;
|
|
8
|
+
this.chatInfo = chatInfo;
|
|
9
|
+
this.delay = delay;
|
|
10
|
+
this.traceId = traceId;
|
|
11
|
+
this.action = action;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.DelayResponse = DelayResponse;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InputFile } from 'telegraf/types';
|
|
2
|
+
import { IReplyMessage } from '../../types/response';
|
|
3
|
+
import { MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
5
|
+
import { IActionState } from '../../types/actionState';
|
|
6
|
+
import { ChatInfo } from '../chatInfo';
|
|
7
|
+
export declare class ImageMessage implements IReplyMessage<InputFile> {
|
|
8
|
+
readonly kind: "image";
|
|
9
|
+
readonly content: InputFile;
|
|
10
|
+
readonly chatInfo: ChatInfo;
|
|
11
|
+
readonly replyId: number | undefined;
|
|
12
|
+
readonly traceId: string | number;
|
|
13
|
+
readonly disableWebPreview = false;
|
|
14
|
+
readonly shouldPin: boolean;
|
|
15
|
+
readonly action: IActionWithState<IActionState>;
|
|
16
|
+
constructor(image: InputFile, chatInfo: ChatInfo, replyId: number | undefined, traceId: number | string, action: IActionWithState<IActionState>, options?: MessageSendingOptions);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=imageMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageMessage.d.ts","sourceRoot":"","sources":["../../../dtos/responses/imageMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,qBAAa,YAAa,YAAW,aAAa,CAAC,SAAS,CAAC;IACzD,QAAQ,CAAC,IAAI,UAA0B;IAEvC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,iBAAiB,SAAS;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG5C,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,OAAO,CAAC,EAAE,qBAAqB;CAStC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImageMessage = void 0;
|
|
4
|
+
const response_1 = require("../../types/response");
|
|
5
|
+
class ImageMessage {
|
|
6
|
+
constructor(image, chatInfo, replyId, traceId, action, options) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.image;
|
|
8
|
+
this.disableWebPreview = false;
|
|
9
|
+
this.content = image;
|
|
10
|
+
this.chatInfo = chatInfo;
|
|
11
|
+
this.replyId = replyId;
|
|
12
|
+
this.traceId = traceId;
|
|
13
|
+
this.shouldPin = options?.pin ?? false;
|
|
14
|
+
this.action = action;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ImageMessage = ImageMessage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TelegramEmoji } from 'telegraf/types';
|
|
2
|
+
import { IChatResponse } from '../../types/response';
|
|
3
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
4
|
+
import { IActionState } from '../../types/actionState';
|
|
5
|
+
import { ChatInfo } from '../chatInfo';
|
|
6
|
+
export declare class Reaction implements IChatResponse {
|
|
7
|
+
readonly kind: "react";
|
|
8
|
+
readonly chatInfo: ChatInfo;
|
|
9
|
+
readonly messageId: number;
|
|
10
|
+
readonly traceId: number | string;
|
|
11
|
+
readonly emoji: TelegramEmoji;
|
|
12
|
+
readonly action: IActionWithState<IActionState>;
|
|
13
|
+
constructor(traceId: number | string, chatInfo: ChatInfo, messageId: number, emoji: TelegramEmoji, action: IActionWithState<IActionState>);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=reaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reaction.d.ts","sourceRoot":"","sources":["../../../dtos/responses/reaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,qBAAa,QAAS,YAAW,aAAa;IAC1C,QAAQ,CAAC,IAAI,UAA0B;IAEvC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG5C,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC;CAQ7C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Reaction = void 0;
|
|
4
|
+
const response_1 = require("../../types/response");
|
|
5
|
+
class Reaction {
|
|
6
|
+
constructor(traceId, chatInfo, messageId, emoji, action) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.react;
|
|
8
|
+
this.chatInfo = chatInfo;
|
|
9
|
+
this.messageId = messageId;
|
|
10
|
+
this.emoji = emoji;
|
|
11
|
+
this.traceId = traceId;
|
|
12
|
+
this.action = action;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Reaction = Reaction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
2
|
+
import { IReplyMessage } from '../../types/response';
|
|
3
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
4
|
+
import { IActionState } from '../../types/actionState';
|
|
5
|
+
import { ChatInfo } from '../chatInfo';
|
|
6
|
+
export declare class TextMessage implements IReplyMessage<string> {
|
|
7
|
+
readonly kind: "text";
|
|
8
|
+
readonly content: string;
|
|
9
|
+
readonly chatInfo: ChatInfo;
|
|
10
|
+
readonly replyId: number | undefined;
|
|
11
|
+
readonly traceId: string | number;
|
|
12
|
+
readonly disableWebPreview: boolean;
|
|
13
|
+
readonly shouldPin: boolean;
|
|
14
|
+
readonly action: IActionWithState<IActionState>;
|
|
15
|
+
constructor(text: string, chatInfo: ChatInfo, replyId: number | undefined, traceId: string | number, action: IActionWithState<IActionState>, options?: TextMessageSendingOptions);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=textMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,qBAAa,WAAY,YAAW,aAAa,CAAC,MAAM,CAAC;IACrD,QAAQ,CAAC,IAAI,SAAyB;IAEtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG5C,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,OAAO,CAAC,EAAE,yBAAyB;CAU1C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
constructor(text, chatInfo, replyId, traceId, action, options) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.text;
|
|
8
|
+
this.content = text;
|
|
9
|
+
this.chatInfo = chatInfo;
|
|
10
|
+
this.replyId = replyId;
|
|
11
|
+
this.traceId = traceId;
|
|
12
|
+
this.disableWebPreview = options?.disableWebPreview ?? false;
|
|
13
|
+
this.shouldPin = options?.pin ?? false;
|
|
14
|
+
this.action = action;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.TextMessage = TextMessage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IChatResponse } from '../../types/response';
|
|
2
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
3
|
+
import { IActionState } from '../../types/actionState';
|
|
4
|
+
import { ChatInfo } from '../chatInfo';
|
|
5
|
+
export declare class UnpinResponse implements IChatResponse {
|
|
6
|
+
readonly kind: "unpin";
|
|
7
|
+
readonly messageId: number;
|
|
8
|
+
readonly chatInfo: ChatInfo;
|
|
9
|
+
readonly traceId: number | string;
|
|
10
|
+
readonly action: IActionWithState<IActionState>;
|
|
11
|
+
constructor(messageId: number, chatInfo: ChatInfo, traceId: number | string, action: IActionWithState<IActionState>);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=unpin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,qBAAa,aAAc,YAAW,aAAa;IAC/C,QAAQ,CAAC,IAAI,UAA0B;IAEvC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG5C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC;CAO7C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
constructor(messageId, chatInfo, traceId, action) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.unpin;
|
|
8
|
+
this.messageId = messageId;
|
|
9
|
+
this.chatInfo = chatInfo;
|
|
10
|
+
this.traceId = traceId;
|
|
11
|
+
this.action = action;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.UnpinResponse = UnpinResponse;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InputFile } from 'telegraf/types';
|
|
2
|
+
import { IReplyMessage } from '../../types/response';
|
|
3
|
+
import { MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
5
|
+
import { IActionState } from '../../types/actionState';
|
|
6
|
+
import { ChatInfo } from '../chatInfo';
|
|
7
|
+
export declare class VideoMessage implements IReplyMessage<InputFile> {
|
|
8
|
+
readonly kind: "video";
|
|
9
|
+
readonly content: InputFile;
|
|
10
|
+
readonly chatInfo: ChatInfo;
|
|
11
|
+
readonly replyId: number | undefined;
|
|
12
|
+
readonly traceId: string | number;
|
|
13
|
+
readonly disableWebPreview = false;
|
|
14
|
+
readonly shouldPin: boolean;
|
|
15
|
+
readonly action: IActionWithState<IActionState>;
|
|
16
|
+
constructor(video: InputFile, chatInfo: ChatInfo, replyId: number | undefined, traceId: number | string, action: IActionWithState<IActionState>, options?: MessageSendingOptions);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=videoMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"videoMessage.d.ts","sourceRoot":"","sources":["../../../dtos/responses/videoMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,qBAAa,YAAa,YAAW,aAAa,CAAC,SAAS,CAAC;IACzD,QAAQ,CAAC,IAAI,UAA0B;IAEvC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,iBAAiB,SAAS;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG5C,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,OAAO,CAAC,EAAE,qBAAqB;CAStC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
constructor(video, chatInfo, replyId, traceId, action, options) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.video;
|
|
8
|
+
this.disableWebPreview = false;
|
|
9
|
+
this.content = video;
|
|
10
|
+
this.chatInfo = chatInfo;
|
|
11
|
+
this.replyId = replyId;
|
|
12
|
+
this.traceId = traceId;
|
|
13
|
+
this.shouldPin = options?.pin ?? false;
|
|
14
|
+
this.action = action;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.VideoMessage = VideoMessage;
|
|
@@ -6,18 +6,19 @@ import { IActionWithState, ActionKey } from '../../types/actionWithState';
|
|
|
6
6
|
import { MessageContext } from '../context/messageContext';
|
|
7
7
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
8
8
|
export declare class CommandAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
|
|
9
|
-
triggers: CommandTrigger[];
|
|
10
|
-
handler: CommandHandler<TActionState>;
|
|
11
|
-
name: string;
|
|
12
|
-
cooldownInSeconds: Seconds;
|
|
13
|
-
active: boolean;
|
|
14
|
-
chatsBlacklist: number[];
|
|
15
|
-
allowedUsers: number[];
|
|
16
|
-
condition: CommandCondition<TActionState>;
|
|
17
|
-
stateConstructor: () => TActionState;
|
|
18
|
-
key: ActionKey;
|
|
9
|
+
readonly triggers: CommandTrigger[];
|
|
10
|
+
readonly handler: CommandHandler<TActionState>;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly cooldownInSeconds: Seconds;
|
|
13
|
+
readonly active: boolean;
|
|
14
|
+
readonly chatsBlacklist: number[];
|
|
15
|
+
readonly allowedUsers: number[];
|
|
16
|
+
readonly condition: CommandCondition<TActionState>;
|
|
17
|
+
readonly stateConstructor: () => TActionState;
|
|
18
|
+
readonly key: ActionKey;
|
|
19
19
|
constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState);
|
|
20
20
|
exec(ctx: MessageContext<TActionState>): Promise<import("../../types/response").BotResponse[]>;
|
|
21
|
+
private checkIfShouldBeExecuted;
|
|
21
22
|
private checkTrigger;
|
|
22
23
|
}
|
|
23
24
|
//# sourceMappingURL=commandAction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
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;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;gBAGpB,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,EAC1C,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO,EACjB,cAAc,EAAE,MAAM,EAAE,EACxB,YAAY,EAAE,MAAM,EAAE,EACtB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY;IAelC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC;IAkD5C,OAAO,CAAC,uBAAuB;IAqC/B,OAAO,CAAC,YAAY;CAmCvB"}
|
|
@@ -7,9 +7,8 @@ exports.CommandAction = void 0;
|
|
|
7
7
|
const moment_1 = __importDefault(require("moment"));
|
|
8
8
|
const timeConvertions_1 = require("../../helpers/timeConvertions");
|
|
9
9
|
const toArray_1 = require("../../helpers/toArray");
|
|
10
|
-
const commandTriggerCheckResult_1 = require("
|
|
11
|
-
const
|
|
12
|
-
const actionExecutionResult_1 = require("../actionExecutionResult");
|
|
10
|
+
const commandTriggerCheckResult_1 = require("../../dtos/commandTriggerCheckResult");
|
|
11
|
+
const noop_1 = require("../../helpers/noop");
|
|
13
12
|
class CommandAction {
|
|
14
13
|
constructor(trigger, handler, name, active, cooldown, chatsBlacklist, allowedUsers, condition, stateConstructor) {
|
|
15
14
|
this.triggers = (0, toArray_1.toArray)(trigger);
|
|
@@ -26,18 +25,15 @@ class CommandAction {
|
|
|
26
25
|
async exec(ctx) {
|
|
27
26
|
if (!ctx.isInitialized)
|
|
28
27
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
29
|
-
if (!this.active || this.chatsBlacklist.includes(ctx.
|
|
30
|
-
return
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const state = await ctx.storage.getActionState(this, ctx.chatId);
|
|
35
|
-
const { shouldTrigger, matchResults, skipCooldown } = this.triggers
|
|
36
|
-
.map((x) => this.checkTrigger(ctx, x, state))
|
|
28
|
+
if (!this.active || this.chatsBlacklist.includes(ctx.chatInfo.id))
|
|
29
|
+
return noop_1.Noop.NoResponse;
|
|
30
|
+
const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
|
|
31
|
+
const { shouldExecute, matchResults, skipCooldown } = this.triggers
|
|
32
|
+
.map((x) => this.checkIfShouldBeExecuted(ctx, x, state))
|
|
37
33
|
.reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger);
|
|
38
|
-
if (!
|
|
39
|
-
return
|
|
40
|
-
|
|
34
|
+
if (!shouldExecute)
|
|
35
|
+
return noop_1.Noop.NoResponse;
|
|
36
|
+
ctx.logger.logWithTraceId(ctx.botName, ctx.traceId, ctx.chatInfo.name, ` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
|
|
41
37
|
ctx.matchResults = matchResults;
|
|
42
38
|
await this.handler(ctx, state);
|
|
43
39
|
if (skipCooldown) {
|
|
@@ -46,14 +42,10 @@ class CommandAction {
|
|
|
46
42
|
if (ctx.startCooldown) {
|
|
47
43
|
state.lastExecutedDate = (0, moment_1.default)().valueOf();
|
|
48
44
|
}
|
|
49
|
-
ctx.
|
|
50
|
-
await ctx.storage.saveActionExecutionResult(this, ctx.chatId, new actionExecutionResult_1.ActionExecutionResult(state, ctx.startCooldown && shouldTrigger));
|
|
51
|
-
ctx.isInitialized = false;
|
|
45
|
+
await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
|
|
52
46
|
return ctx.responses;
|
|
53
47
|
}
|
|
54
|
-
|
|
55
|
-
let shouldTrigger = false;
|
|
56
|
-
const matchResults = [];
|
|
48
|
+
checkIfShouldBeExecuted(ctx, trigger, state) {
|
|
57
49
|
if (!ctx.fromUserId)
|
|
58
50
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
|
|
59
51
|
const isUserAllowed = this.allowedUsers.length == 0 ||
|
|
@@ -65,29 +57,38 @@ class CommandAction {
|
|
|
65
57
|
const onCooldown = (0, moment_1.default)().diff(lastExecutedDate) < cooldownInMilliseconds;
|
|
66
58
|
if (onCooldown)
|
|
67
59
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
60
|
+
const isCustomConditionMet = this.condition(ctx);
|
|
61
|
+
if (!isCustomConditionMet)
|
|
62
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
|
|
63
|
+
const { shouldTrigger, matchResults } = this.checkTrigger(ctx, trigger);
|
|
64
|
+
return new commandTriggerCheckResult_1.CommandTriggerCheckResult(shouldTrigger, matchResults, false);
|
|
65
|
+
}
|
|
66
|
+
checkTrigger(ctx, trigger) {
|
|
67
|
+
if (trigger == ctx.messageType)
|
|
68
|
+
return { shouldTrigger: true, matchResults: [] };
|
|
69
|
+
if (typeof trigger == 'string')
|
|
70
|
+
return {
|
|
71
|
+
shouldTrigger: ctx.messageText.toLowerCase() == trigger,
|
|
72
|
+
matchResults: []
|
|
73
|
+
};
|
|
74
|
+
const matchResults = [];
|
|
75
|
+
trigger.lastIndex = 0;
|
|
76
|
+
const execResult = trigger.exec(ctx.messageText);
|
|
77
|
+
if (execResult != null) {
|
|
78
|
+
matchResults.push(execResult);
|
|
79
|
+
if (trigger.global) {
|
|
80
|
+
while (true) {
|
|
81
|
+
const nextResult = trigger.exec(ctx.messageText);
|
|
82
|
+
if (nextResult == null)
|
|
83
|
+
break;
|
|
84
|
+
matchResults.push(nextResult);
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
|
-
shouldTrigger = matchResults.length > 0;
|
|
89
87
|
}
|
|
90
|
-
return
|
|
88
|
+
return {
|
|
89
|
+
shouldTrigger: matchResults.length > 0,
|
|
90
|
+
matchResults
|
|
91
|
+
};
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
exports.CommandAction = CommandAction;
|
|
@@ -6,19 +6,19 @@ import { IActionWithState, ActionKey } from '../../types/actionWithState';
|
|
|
6
6
|
import { CachedStateFactory } from '../cachedStateFactory';
|
|
7
7
|
import { ChatContext } from '../context/chatContext';
|
|
8
8
|
export declare class ScheduledAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
|
|
9
|
-
static locks: Map<string, Semaphore>;
|
|
10
|
-
name: string;
|
|
11
|
-
timeinHours: HoursOfDay;
|
|
12
|
-
active: boolean;
|
|
13
|
-
chatsWhitelist: number[];
|
|
14
|
-
key: ActionKey;
|
|
15
|
-
cachedState: Map<string, unknown>;
|
|
16
|
-
stateConstructor: () => TActionState;
|
|
17
|
-
cachedStateFactories: Map<string, CachedStateFactory>;
|
|
18
|
-
handler: ScheduledHandler<TActionState>;
|
|
9
|
+
static readonly locks: Map<string, Semaphore>;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly timeinHours: HoursOfDay;
|
|
12
|
+
readonly active: boolean;
|
|
13
|
+
readonly chatsWhitelist: number[];
|
|
14
|
+
readonly key: ActionKey;
|
|
15
|
+
readonly cachedState: Map<string, unknown>;
|
|
16
|
+
readonly stateConstructor: () => TActionState;
|
|
17
|
+
readonly cachedStateFactories: Map<string, CachedStateFactory>;
|
|
18
|
+
readonly handler: ScheduledHandler<TActionState>;
|
|
19
19
|
constructor(name: string, handler: ScheduledHandler<TActionState>, timeinHours: HoursOfDay, active: boolean, whitelist: number[], cachedStateFactories: Map<string, CachedStateFactory>, stateConstructor: () => TActionState);
|
|
20
20
|
exec(ctx: ChatContext<TActionState>): Promise<import("../../types/response").BotResponse[]>;
|
|
21
21
|
private getCachedValue;
|
|
22
|
-
private
|
|
22
|
+
private checkIfShouldBeExecuted;
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=scheduledAction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduledAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/scheduledAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduledAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/scheduledAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAIrD,qBAAa,eAAe,CAAC,YAAY,SAAS,YAAY,CAC1D,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,MAAM,CAAC,QAAQ,CAAC,KAAK,yBAAgC;IAErD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IAExB,QAAQ,CAAC,WAAW,uBAA8B;IAClD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG7C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACvC,WAAW,EAAE,UAAU,EACvB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EAAE,EACnB,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EACrD,gBAAgB,EAAE,MAAM,YAAY;IAYlC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC;YA0C3B,cAAc;IA+C5B,OAAO,CAAC,uBAAuB;CAalC"}
|