chz-telegram-bot 0.0.45 → 0.0.46
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/entities/actionExecutionResult.d.ts +7 -0
- package/dist/entities/actionExecutionResult.d.ts.map +1 -0
- package/dist/entities/actionExecutionResult.js +10 -0
- package/dist/entities/actions/commandAction.d.ts +23 -0
- package/dist/entities/actions/commandAction.d.ts.map +1 -0
- package/dist/entities/actions/commandAction.js +91 -0
- package/dist/entities/actions/scheduledAction.d.ts +24 -0
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -0
- package/dist/entities/actions/scheduledAction.js +81 -0
- package/dist/entities/botInstance.d.ts +31 -0
- package/dist/entities/botInstance.d.ts.map +1 -0
- package/dist/entities/botInstance.js +107 -0
- package/dist/entities/cachedStateFactory.d.ts +7 -0
- package/dist/entities/cachedStateFactory.d.ts.map +1 -0
- package/dist/entities/cachedStateFactory.js +10 -0
- package/dist/entities/commandTriggerCheckResult.d.ts +10 -0
- package/dist/entities/commandTriggerCheckResult.d.ts.map +1 -0
- package/dist/entities/commandTriggerCheckResult.js +23 -0
- package/dist/entities/context/chatContext.d.ts +54 -0
- package/dist/entities/context/chatContext.d.ts.map +1 -0
- package/dist/entities/context/chatContext.js +70 -0
- package/dist/entities/context/messageContext.d.ts +60 -0
- package/dist/entities/context/messageContext.d.ts.map +1 -0
- package/dist/entities/context/messageContext.js +82 -0
- package/dist/entities/incomingMessage.d.ts +14 -0
- package/dist/entities/incomingMessage.d.ts.map +1 -0
- package/dist/entities/incomingMessage.js +45 -0
- package/dist/entities/responses/imageMessage.d.ts +16 -0
- package/dist/entities/responses/imageMessage.d.ts.map +1 -0
- package/dist/entities/responses/imageMessage.js +17 -0
- package/dist/entities/responses/reaction.d.ts +13 -0
- package/dist/entities/responses/reaction.d.ts.map +1 -0
- package/dist/entities/responses/reaction.js +15 -0
- package/dist/entities/responses/textMessage.d.ts +15 -0
- package/dist/entities/responses/textMessage.d.ts.map +1 -0
- package/dist/entities/responses/textMessage.js +17 -0
- package/dist/entities/responses/unpin.d.ts +11 -0
- package/dist/entities/responses/unpin.d.ts.map +1 -0
- package/dist/entities/responses/unpin.js +14 -0
- package/dist/entities/responses/videoMessage.d.ts +16 -0
- package/dist/entities/responses/videoMessage.d.ts.map +1 -0
- package/dist/entities/responses/videoMessage.js +17 -0
- package/dist/entities/states/actionStateBase.d.ts +6 -0
- package/dist/entities/states/actionStateBase.d.ts.map +1 -0
- package/dist/entities/states/actionStateBase.js +10 -0
- package/dist/entities/taskRecord.d.ts +8 -0
- package/dist/entities/taskRecord.d.ts.map +1 -0
- package/dist/entities/taskRecord.js +11 -0
- package/dist/helpers/builders/commandActionBuilder.d.ts +69 -0
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -0
- package/dist/helpers/builders/commandActionBuilder.js +96 -0
- package/dist/helpers/builders/scheduledActionBuilder.d.ts +60 -0
- package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -0
- package/dist/helpers/builders/scheduledActionBuilder.js +82 -0
- package/dist/helpers/inverseRecord.d.ts +2 -0
- package/dist/helpers/inverseRecord.d.ts.map +1 -0
- package/dist/helpers/inverseRecord.js +6 -0
- package/dist/helpers/noop.d.ts +6 -0
- package/dist/helpers/noop.d.ts.map +1 -0
- package/dist/helpers/noop.js +14 -0
- package/dist/helpers/reverseMap.d.ts +2 -0
- package/dist/helpers/reverseMap.d.ts.map +1 -0
- package/dist/helpers/reverseMap.js +6 -0
- package/dist/helpers/reverseRecord.d.ts +2 -0
- package/dist/helpers/reverseRecord.d.ts.map +1 -0
- package/dist/helpers/reverseRecord.js +6 -0
- package/dist/helpers/timeConvertions.d.ts +5 -0
- package/dist/helpers/timeConvertions.d.ts.map +1 -0
- package/dist/helpers/timeConvertions.js +14 -0
- package/dist/helpers/toArray.d.ts +2 -0
- package/dist/helpers/toArray.d.ts.map +1 -0
- package/dist/helpers/toArray.js +6 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/main.d.ts +35 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +43 -0
- package/dist/services/jsonFileStorage.d.ts +22 -0
- package/dist/services/jsonFileStorage.d.ts.map +1 -0
- package/dist/services/jsonFileStorage.js +102 -0
- package/dist/services/logger.d.ts +9 -0
- package/dist/services/logger.d.ts.map +1 -0
- package/dist/services/logger.js +28 -0
- package/dist/services/taskScheduler.d.ts +11 -0
- package/dist/services/taskScheduler.d.ts.map +1 -0
- package/dist/services/taskScheduler.js +33 -0
- package/dist/services/telegramApi.d.ts +36 -0
- package/dist/services/telegramApi.d.ts.map +1 -0
- package/dist/services/telegramApi.js +100 -0
- package/dist/types/actionState.d.ts +5 -0
- package/dist/types/actionState.d.ts.map +1 -0
- package/dist/types/actionState.js +2 -0
- package/dist/types/actionWithState.d.ts +9 -0
- package/dist/types/actionWithState.d.ts.map +1 -0
- package/dist/types/actionWithState.js +2 -0
- package/dist/types/cachedValueAccessor.d.ts +2 -0
- package/dist/types/cachedValueAccessor.d.ts.map +1 -0
- package/dist/types/cachedValueAccessor.js +2 -0
- package/dist/types/commandCondition.d.ts +4 -0
- package/dist/types/commandCondition.d.ts.map +1 -0
- package/dist/types/commandCondition.js +2 -0
- package/dist/types/commandTrigger.d.ts +3 -0
- package/dist/types/commandTrigger.d.ts.map +1 -0
- package/dist/types/commandTrigger.js +2 -0
- package/dist/types/daysOfTheWeek.d.ts +10 -0
- package/dist/types/daysOfTheWeek.d.ts.map +1 -0
- package/dist/types/daysOfTheWeek.js +13 -0
- package/dist/types/handlers.d.ts +17 -0
- package/dist/types/handlers.d.ts.map +1 -0
- package/dist/types/handlers.js +2 -0
- package/dist/types/messageSendingOptions.d.ts +7 -0
- package/dist/types/messageSendingOptions.d.ts.map +1 -0
- package/dist/types/messageSendingOptions.js +2 -0
- package/dist/types/messageTypes.d.ts +16 -0
- package/dist/types/messageTypes.d.ts.map +1 -0
- package/dist/types/messageTypes.js +17 -0
- package/dist/types/replyMessage.d.ts +8 -0
- package/dist/types/replyMessage.d.ts.map +1 -0
- package/dist/types/replyMessage.js +2 -0
- package/dist/types/response.d.ts +27 -0
- package/dist/types/response.d.ts.map +1 -0
- package/dist/types/response.js +10 -0
- package/dist/types/storage.d.ts +12 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/storage.js +2 -0
- package/dist/types/timeValues.d.ts +11 -0
- package/dist/types/timeValues.d.ts.map +1 -0
- package/dist/types/timeValues.js +2 -0
- package/package.json +29 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAa,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAG,MAAM,CAAC;IACnB,oDAAoD;IACpD,WAAW,EAAG,MAAM,CAAC;IACrB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAG,MAAM,CAAC;IACtB,qCAAqC;IACrC,WAAW,EAAG,gBAAgB,CAAC;;IAM/B,wBAAwB,CACpB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,cAAc;IAwB3B;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAe/B;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa/D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageContext = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const imageMessage_1 = require("../responses/imageMessage");
|
|
6
|
+
const reaction_1 = require("../responses/reaction");
|
|
7
|
+
const textMessage_1 = require("../responses/textMessage");
|
|
8
|
+
const videoMessage_1 = require("../responses/videoMessage");
|
|
9
|
+
const actionStateBase_1 = require("../states/actionStateBase");
|
|
10
|
+
const chatContext_1 = require("./chatContext");
|
|
11
|
+
/**
|
|
12
|
+
* Context of action executed in chat, in response to a message
|
|
13
|
+
*/
|
|
14
|
+
class MessageContext extends chatContext_1.ChatContext {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
18
|
+
this.matchResults = [];
|
|
19
|
+
/** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
|
|
20
|
+
this.startCooldown = true;
|
|
21
|
+
}
|
|
22
|
+
initializeMessageContext(botName, action, interactions, message, storage) {
|
|
23
|
+
this.messageId = message.message_id;
|
|
24
|
+
this.messageText = message.text ?? '';
|
|
25
|
+
this.messageType = message.type;
|
|
26
|
+
this.fromUserId = message.from?.id;
|
|
27
|
+
this.fromUserName =
|
|
28
|
+
(message.from?.first_name ?? 'Unknown user') +
|
|
29
|
+
(message.from?.last_name ? ` ${message.from.last_name}` : '');
|
|
30
|
+
this.matchResults = [];
|
|
31
|
+
this.startCooldown = true;
|
|
32
|
+
return this.initializeChatContext(botName, action, interactions, message.chat.id, message.chatName, message.traceId, storage);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
36
|
+
* @param commandName Name of an action to load state of.
|
|
37
|
+
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
38
|
+
*/
|
|
39
|
+
async loadStateOf(commandName) {
|
|
40
|
+
const storageKey = `command:${commandName.replace('.', '-')}`;
|
|
41
|
+
const allStates = await this.storage.load(storageKey);
|
|
42
|
+
const stateForChat = allStates[this.chatId];
|
|
43
|
+
if (!stateForChat) {
|
|
44
|
+
return new actionStateBase_1.ActionStateBase();
|
|
45
|
+
}
|
|
46
|
+
return stateForChat;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Reply with text message to message that triggered this action.
|
|
50
|
+
* @param text Message contents.
|
|
51
|
+
* @param options Message sending option.
|
|
52
|
+
*/
|
|
53
|
+
replyWithText(text, options) {
|
|
54
|
+
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, this.messageId, this.traceId, this.action, options));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reply with image message to message that triggered this action.
|
|
58
|
+
* @param text Message contents.
|
|
59
|
+
* @param options Message sending option.
|
|
60
|
+
*/
|
|
61
|
+
replyWithImage(name, options) {
|
|
62
|
+
const filePath = `./content/${name}.png`;
|
|
63
|
+
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.action, options));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reply with video/gif message to message that triggered this action.
|
|
67
|
+
* @param text Message contents.
|
|
68
|
+
* @param options Message sending option.
|
|
69
|
+
*/
|
|
70
|
+
replyWithVideo(name, options) {
|
|
71
|
+
const filePath = `./content/${name}.mp4`;
|
|
72
|
+
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.action, options));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* React to the message that triggered this action.
|
|
76
|
+
* @param emoji Telegram emoji to react with.
|
|
77
|
+
*/
|
|
78
|
+
react(emoji) {
|
|
79
|
+
this.interactions.react(new reaction_1.Reaction(this.traceId, this.chatId, this.messageId, emoji, this.action));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.MessageContext = MessageContext;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Chat, Message, Update, User } from 'telegraf/types';
|
|
2
|
+
import { MessageTypeValue } from '../types/messageTypes';
|
|
3
|
+
export declare class IncomingMessage {
|
|
4
|
+
message_id: number;
|
|
5
|
+
chat: Chat;
|
|
6
|
+
from: User | undefined;
|
|
7
|
+
text: string;
|
|
8
|
+
chatName: string;
|
|
9
|
+
type: MessageTypeValue;
|
|
10
|
+
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":["../../entities/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,qBAAa,eAAe;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,SAA2B;IAElC,OAAO,CAAC,iBAAiB;gBAkBb,UAAU,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;CAWrE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
class IncomingMessage {
|
|
7
|
+
detectMessageType(message) {
|
|
8
|
+
if ('text' in message)
|
|
9
|
+
return messageTypes_1.MessageType.Text;
|
|
10
|
+
if ('photo' in message)
|
|
11
|
+
return messageTypes_1.MessageType.Photo;
|
|
12
|
+
if ('sticker' in message)
|
|
13
|
+
return messageTypes_1.MessageType.Sticker;
|
|
14
|
+
if ('animation' in message)
|
|
15
|
+
return messageTypes_1.MessageType.Animation;
|
|
16
|
+
if ('voice' in message)
|
|
17
|
+
return messageTypes_1.MessageType.Voice;
|
|
18
|
+
if ('audio' in message)
|
|
19
|
+
return messageTypes_1.MessageType.Audio;
|
|
20
|
+
if ('document' in message)
|
|
21
|
+
return messageTypes_1.MessageType.Document;
|
|
22
|
+
if ('left_chat_member' in message)
|
|
23
|
+
return messageTypes_1.MessageType.LeftChatMember;
|
|
24
|
+
if ('new_chat_member' in message)
|
|
25
|
+
return messageTypes_1.MessageType.NewChatMember;
|
|
26
|
+
if ('poll' in message)
|
|
27
|
+
return messageTypes_1.MessageType.Poll;
|
|
28
|
+
if ('location' in message)
|
|
29
|
+
return messageTypes_1.MessageType.Location;
|
|
30
|
+
return messageTypes_1.MessageType.Unknown;
|
|
31
|
+
}
|
|
32
|
+
constructor(ctxMessage) {
|
|
33
|
+
this.traceId = (0, crypto_1.randomInt)(10000, 99999);
|
|
34
|
+
this.message_id = ctxMessage.message_id;
|
|
35
|
+
this.chat = ctxMessage.chat;
|
|
36
|
+
this.from = ctxMessage.from;
|
|
37
|
+
this.text = 'text' in ctxMessage ? ctxMessage.text : '';
|
|
38
|
+
this.type = this.detectMessageType(ctxMessage);
|
|
39
|
+
this.chatName =
|
|
40
|
+
'title' in ctxMessage.chat
|
|
41
|
+
? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
|
|
42
|
+
: 'DM';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.IncomingMessage = IncomingMessage;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export declare class ImageMessage implements IReplyMessage<InputFile> {
|
|
6
|
+
kind: "image";
|
|
7
|
+
content: InputFile;
|
|
8
|
+
chatId: number;
|
|
9
|
+
replyId: number | undefined;
|
|
10
|
+
traceId: string | number;
|
|
11
|
+
disableWebPreview: boolean;
|
|
12
|
+
shouldPin: boolean;
|
|
13
|
+
action: IActionWithState;
|
|
14
|
+
constructor(image: InputFile, chatId: number, replyId: number | undefined, traceId: number | string, action: IActionWithState, options?: MessageSendingOptions);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=imageMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageMessage.d.ts","sourceRoot":"","sources":["../../../entities/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;AAE/D,qBAAa,YAAa,YAAW,aAAa,CAAC,SAAS,CAAC;IACzD,IAAI,UAA0B;IAE9B,OAAO,EAAE,SAAS,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,iBAAiB,UAAS;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,gBAAgB,CAAC;gBAGrB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,EACxB,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, chatId, replyId, traceId, action, options) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.image;
|
|
8
|
+
this.disableWebPreview = false;
|
|
9
|
+
this.content = image;
|
|
10
|
+
this.chatId = chatId;
|
|
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,13 @@
|
|
|
1
|
+
import { TelegramEmoji } from 'telegraf/types';
|
|
2
|
+
import { IChatResponse } from '../../types/response';
|
|
3
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
4
|
+
export declare class Reaction implements IChatResponse {
|
|
5
|
+
kind: "react";
|
|
6
|
+
chatId: number;
|
|
7
|
+
messageId: number;
|
|
8
|
+
traceId: number | string;
|
|
9
|
+
emoji: TelegramEmoji;
|
|
10
|
+
action: IActionWithState;
|
|
11
|
+
constructor(traceId: number | string, chatId: number, messageId: number, emoji: TelegramEmoji, action: IActionWithState);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=reaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reaction.d.ts","sourceRoot":"","sources":["../../../entities/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;AAE/D,qBAAa,QAAS,YAAW,aAAa;IAC1C,IAAI,UAA0B;IAE9B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,gBAAgB,CAAC;gBAGrB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,gBAAgB;CAQ/B"}
|
|
@@ -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, chatId, messageId, emoji, action) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.react;
|
|
8
|
+
this.chatId = chatId;
|
|
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,15 @@
|
|
|
1
|
+
import { TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
2
|
+
import { IReplyMessage } from '../../types/response';
|
|
3
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
4
|
+
export declare class TextMessage implements IReplyMessage<string> {
|
|
5
|
+
kind: "text";
|
|
6
|
+
content: string;
|
|
7
|
+
chatId: number;
|
|
8
|
+
replyId: number | undefined;
|
|
9
|
+
traceId: string | number;
|
|
10
|
+
disableWebPreview: boolean;
|
|
11
|
+
shouldPin: boolean;
|
|
12
|
+
action: IActionWithState;
|
|
13
|
+
constructor(text: string, chatId: number, replyId: number | undefined, traceId: string | number, action: IActionWithState, options?: TextMessageSendingOptions);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=textMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textMessage.d.ts","sourceRoot":"","sources":["../../../entities/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;AAE/D,qBAAa,WAAY,YAAW,aAAa,CAAC,MAAM,CAAC;IACrD,IAAI,SAAyB;IAE7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,gBAAgB,CAAC;gBAGrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,EACxB,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, chatId, replyId, traceId, action, options) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.text;
|
|
8
|
+
this.content = text;
|
|
9
|
+
this.chatId = chatId;
|
|
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,11 @@
|
|
|
1
|
+
import { IChatResponse } from '../../types/response';
|
|
2
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
3
|
+
export declare class UnpinResponse implements IChatResponse {
|
|
4
|
+
kind: "unpin";
|
|
5
|
+
messageId: number;
|
|
6
|
+
chatId: number;
|
|
7
|
+
traceId: number | string;
|
|
8
|
+
action: IActionWithState;
|
|
9
|
+
constructor(messageId: number, chatId: number, traceId: number | string, action: IActionWithState);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=unpin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpin.d.ts","sourceRoot":"","sources":["../../../entities/responses/unpin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,qBAAa,aAAc,YAAW,aAAa;IAC/C,IAAI,UAA0B;IAE9B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,MAAM,EAAE,gBAAgB,CAAC;gBAGrB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB;CAO/B"}
|
|
@@ -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, chatId, traceId, action) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.unpin;
|
|
8
|
+
this.messageId = messageId;
|
|
9
|
+
this.chatId = chatId;
|
|
10
|
+
this.traceId = traceId;
|
|
11
|
+
this.action = action;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.UnpinResponse = UnpinResponse;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export declare class VideoMessage implements IReplyMessage<InputFile> {
|
|
6
|
+
kind: "video";
|
|
7
|
+
content: InputFile;
|
|
8
|
+
chatId: number;
|
|
9
|
+
replyId: number | undefined;
|
|
10
|
+
traceId: string | number;
|
|
11
|
+
disableWebPreview: boolean;
|
|
12
|
+
shouldPin: boolean;
|
|
13
|
+
action: IActionWithState;
|
|
14
|
+
constructor(video: InputFile, chatId: number, replyId: number | undefined, traceId: number | string, action: IActionWithState, options?: MessageSendingOptions);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=videoMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"videoMessage.d.ts","sourceRoot":"","sources":["../../../entities/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;AAE/D,qBAAa,YAAa,YAAW,aAAa,CAAC,SAAS,CAAC;IACzD,IAAI,UAA0B;IAE9B,OAAO,EAAE,SAAS,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,iBAAiB,UAAS;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,gBAAgB,CAAC;gBAGrB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,EACxB,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, chatId, replyId, traceId, action, options) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.video;
|
|
8
|
+
this.disableWebPreview = false;
|
|
9
|
+
this.content = video;
|
|
10
|
+
this.chatId = chatId;
|
|
11
|
+
this.replyId = replyId;
|
|
12
|
+
this.traceId = traceId;
|
|
13
|
+
this.shouldPin = options?.pin ?? false;
|
|
14
|
+
this.action = action;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.VideoMessage = VideoMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionStateBase.d.ts","sourceRoot":"","sources":["../../../entities/states/actionStateBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,qBAAa,eAAgB,YAAW,YAAY;IAChD,cAAc,EAAE,MAAM,EAAE,CAAM;IAC9B,gBAAgB,SAAK;CACxB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionStateBase = void 0;
|
|
4
|
+
class ActionStateBase {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.pinnedMessages = [];
|
|
7
|
+
this.lastExecutedDate = 0;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ActionStateBase = ActionStateBase;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Milliseconds } from '../types/timeValues';
|
|
2
|
+
export declare class TaskRecord {
|
|
3
|
+
name: string;
|
|
4
|
+
taskId: NodeJS.Timeout;
|
|
5
|
+
interval: Milliseconds;
|
|
6
|
+
constructor(name: string, taskId: NodeJS.Timeout, interval: Milliseconds);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=taskRecord.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taskRecord.d.ts","sourceRoot":"","sources":["../../entities/taskRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,UAAU;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;IACvB,QAAQ,EAAE,YAAY,CAAC;gBAEX,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY;CAK3E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskRecord = void 0;
|
|
4
|
+
class TaskRecord {
|
|
5
|
+
constructor(name, taskId, interval) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.taskId = taskId;
|
|
8
|
+
this.interval = interval;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.TaskRecord = TaskRecord;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CommandHandler } from '../../types/handlers';
|
|
2
|
+
import { CommandCondition } from '../../types/commandCondition';
|
|
3
|
+
import { Seconds } from '../../types/timeValues';
|
|
4
|
+
import { CommandAction } from '../../entities/actions/commandAction';
|
|
5
|
+
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
6
|
+
import { IActionState } from '../../types/actionState';
|
|
7
|
+
import { CommandTrigger } from '../../types/commandTrigger';
|
|
8
|
+
/**
|
|
9
|
+
* Builder for `CommandAction` with state represented by `TActionState`
|
|
10
|
+
*/
|
|
11
|
+
export declare class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
12
|
+
name: string;
|
|
13
|
+
trigger: CommandTrigger | CommandTrigger[];
|
|
14
|
+
active: boolean;
|
|
15
|
+
cooldownSeconds: Seconds;
|
|
16
|
+
blacklist: number[];
|
|
17
|
+
allowedUsers: number[];
|
|
18
|
+
stateConstructor: () => TActionState;
|
|
19
|
+
handler: CommandHandler<TActionState>;
|
|
20
|
+
condition: CommandCondition<TActionState>;
|
|
21
|
+
/**
|
|
22
|
+
* Builder for `CommandAction` with state represented by `TActionState`
|
|
23
|
+
* @param name Action name, will be used for logging and storage
|
|
24
|
+
* @param stateConstructor Function that creates default state object
|
|
25
|
+
*/
|
|
26
|
+
constructor(name: string, stateConstructor: () => TActionState);
|
|
27
|
+
/**
|
|
28
|
+
* Defines action trigger
|
|
29
|
+
* @param trigger If `string` or `string[]` is provided, will be triggered only on exact message match.
|
|
30
|
+
*
|
|
31
|
+
* If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
|
|
32
|
+
*/
|
|
33
|
+
on(trigger: CommandTrigger | CommandTrigger[]): this;
|
|
34
|
+
/** Defines id (or ids) of users that are allowed to trigger this action.
|
|
35
|
+
* @param id User id or ids
|
|
36
|
+
*/
|
|
37
|
+
from(id: number | number[]): this;
|
|
38
|
+
/** Defines action logic itself, will be executed on trigger.
|
|
39
|
+
* @param handler Callback that will be called on trigger
|
|
40
|
+
*/
|
|
41
|
+
do(handler: CommandHandler<TActionState>): this;
|
|
42
|
+
/** Defines condition that will be checked before trigger match check is executed.
|
|
43
|
+
* @param condition Condition check predicate
|
|
44
|
+
*/
|
|
45
|
+
when(condition: CommandCondition<TActionState>): this;
|
|
46
|
+
/** If called during building, action is marked as disabled and never checked. */
|
|
47
|
+
disabled(): this;
|
|
48
|
+
/** Sets action cooldown.
|
|
49
|
+
* @param seconds Cooldown in seconds.
|
|
50
|
+
*/
|
|
51
|
+
cooldown(seconds: Seconds): this;
|
|
52
|
+
/**
|
|
53
|
+
* Adds a chat to ignore list for this action.
|
|
54
|
+
* @param chatId Chat id to ignore.
|
|
55
|
+
*/
|
|
56
|
+
ignoreChat(chatId: number): this;
|
|
57
|
+
/** Builds action */
|
|
58
|
+
build(): CommandAction<TActionState>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
62
|
+
*/
|
|
63
|
+
export declare class CommandActionBuilder extends CommandActionBuilderWithState<ActionStateBase> {
|
|
64
|
+
/**
|
|
65
|
+
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
66
|
+
*/
|
|
67
|
+
constructor(name: string);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=commandActionBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/commandActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D;;GAEG;AACH,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,CAAM;IAEhD,MAAM,UAAQ;IACd,eAAe,EAAE,OAAO,CAAgB;IACxC,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,YAAY,EAAE,MAAM,EAAE,CAAM;IAC5B,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAa;IAClD,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAa;IAEtD;;;;OAIG;gBACS,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,YAAY;IAK9D;;;;;OAKG;IACH,EAAE,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE;IAM7C;;OAEG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;IAM1B;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC;IAMxC;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAM9C,iFAAiF;IACjF,QAAQ;IAMR;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO;IAMzB;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM;IAMzB,oBAAoB;IACpB,KAAK;CAaR;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,6BAA6B,CAAC,eAAe,CAAC;IACpF;;OAEG;gBACS,IAAI,EAAE,MAAM;CAG3B"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandActionBuilder = exports.CommandActionBuilderWithState = void 0;
|
|
4
|
+
const commandAction_1 = require("../../entities/actions/commandAction");
|
|
5
|
+
const actionStateBase_1 = require("../../entities/states/actionStateBase");
|
|
6
|
+
const toArray_1 = require("../toArray");
|
|
7
|
+
const noop_1 = require("../noop");
|
|
8
|
+
/**
|
|
9
|
+
* Builder for `CommandAction` with state represented by `TActionState`
|
|
10
|
+
*/
|
|
11
|
+
class CommandActionBuilderWithState {
|
|
12
|
+
/**
|
|
13
|
+
* Builder for `CommandAction` with state represented by `TActionState`
|
|
14
|
+
* @param name Action name, will be used for logging and storage
|
|
15
|
+
* @param stateConstructor Function that creates default state object
|
|
16
|
+
*/
|
|
17
|
+
constructor(name, stateConstructor) {
|
|
18
|
+
this.trigger = [];
|
|
19
|
+
this.active = true;
|
|
20
|
+
this.cooldownSeconds = 0;
|
|
21
|
+
this.blacklist = [];
|
|
22
|
+
this.allowedUsers = [];
|
|
23
|
+
this.handler = noop_1.Noop.call;
|
|
24
|
+
this.condition = noop_1.Noop.true;
|
|
25
|
+
this.name = name;
|
|
26
|
+
this.stateConstructor = stateConstructor;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Defines action trigger
|
|
30
|
+
* @param trigger If `string` or `string[]` is provided, will be triggered only on exact message match.
|
|
31
|
+
*
|
|
32
|
+
* If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
|
|
33
|
+
*/
|
|
34
|
+
on(trigger) {
|
|
35
|
+
this.trigger = trigger;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/** Defines id (or ids) of users that are allowed to trigger this action.
|
|
39
|
+
* @param id User id or ids
|
|
40
|
+
*/
|
|
41
|
+
from(id) {
|
|
42
|
+
this.allowedUsers = (0, toArray_1.toArray)(id);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/** Defines action logic itself, will be executed on trigger.
|
|
46
|
+
* @param handler Callback that will be called on trigger
|
|
47
|
+
*/
|
|
48
|
+
do(handler) {
|
|
49
|
+
this.handler = handler;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/** Defines condition that will be checked before trigger match check is executed.
|
|
53
|
+
* @param condition Condition check predicate
|
|
54
|
+
*/
|
|
55
|
+
when(condition) {
|
|
56
|
+
this.condition = condition;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/** If called during building, action is marked as disabled and never checked. */
|
|
60
|
+
disabled() {
|
|
61
|
+
this.active = false;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/** Sets action cooldown.
|
|
65
|
+
* @param seconds Cooldown in seconds.
|
|
66
|
+
*/
|
|
67
|
+
cooldown(seconds) {
|
|
68
|
+
this.cooldownSeconds = seconds;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Adds a chat to ignore list for this action.
|
|
73
|
+
* @param chatId Chat id to ignore.
|
|
74
|
+
*/
|
|
75
|
+
ignoreChat(chatId) {
|
|
76
|
+
this.blacklist.push(chatId);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
/** Builds action */
|
|
80
|
+
build() {
|
|
81
|
+
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, this.cooldownSeconds, this.blacklist, this.allowedUsers, this.condition, this.stateConstructor);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
|
|
85
|
+
/**
|
|
86
|
+
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
87
|
+
*/
|
|
88
|
+
class CommandActionBuilder extends CommandActionBuilderWithState {
|
|
89
|
+
/**
|
|
90
|
+
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
91
|
+
*/
|
|
92
|
+
constructor(name) {
|
|
93
|
+
super(name, () => new actionStateBase_1.ActionStateBase());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.CommandActionBuilder = CommandActionBuilder;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ScheduledAction } from '../../entities/actions/scheduledAction';
|
|
2
|
+
import { CachedStateFactory } from '../../entities/cachedStateFactory';
|
|
3
|
+
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
4
|
+
import { IActionState } from '../../types/actionState';
|
|
5
|
+
import { ScheduledHandler } from '../../types/handlers';
|
|
6
|
+
import { Hours, HoursOfDay } from '../../types/timeValues';
|
|
7
|
+
/**
|
|
8
|
+
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
9
|
+
*/
|
|
10
|
+
export declare class ScheduledActionBuilderWithState<TActionState extends IActionState> {
|
|
11
|
+
active: boolean;
|
|
12
|
+
time: HoursOfDay;
|
|
13
|
+
cachedStateFactories: Map<string, CachedStateFactory>;
|
|
14
|
+
whitelist: number[];
|
|
15
|
+
stateConstructor: () => TActionState;
|
|
16
|
+
handler: ScheduledHandler<TActionState>;
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
20
|
+
* @param name Action name, will be used for logging and storage
|
|
21
|
+
* @param stateConstructor Function that creates default state object
|
|
22
|
+
*/
|
|
23
|
+
constructor(name: string, stateConstructor: () => TActionState);
|
|
24
|
+
/**
|
|
25
|
+
* Adds a chat to whitelist for this action.
|
|
26
|
+
* @param chatId Chat id to execute in.
|
|
27
|
+
*/
|
|
28
|
+
allowIn(chatId: number): this;
|
|
29
|
+
/**
|
|
30
|
+
* Defines time for scheduled item execution.
|
|
31
|
+
* @param time Time of day (0 - 23) to execute action.
|
|
32
|
+
*/
|
|
33
|
+
runAt(time: HoursOfDay): this;
|
|
34
|
+
/** Defines action logic itself, will be executed on timer.
|
|
35
|
+
* @param handler Callback that will be called on timer.
|
|
36
|
+
*/
|
|
37
|
+
do(handler: ScheduledHandler<TActionState>): this;
|
|
38
|
+
/**
|
|
39
|
+
* Defines process-wide cache, that is shared by all actions of this type (even in different bot instances).
|
|
40
|
+
* Can be used for fetch request de-duping, etc.
|
|
41
|
+
* @param key Key that will be used to retrieve value from cache.
|
|
42
|
+
* @param itemFactory Callback that will be executed once to create cached value.
|
|
43
|
+
* @param invalidationTimeoutInHours Timeout for cache invalidation.
|
|
44
|
+
*/
|
|
45
|
+
withSharedCache(key: string, itemFactory: () => Promise<unknown>, invalidationTimeoutInHours?: Hours): this;
|
|
46
|
+
/** If called during building, action is marked as disabled and never checked. */
|
|
47
|
+
disabled(): this;
|
|
48
|
+
/** Builds action */
|
|
49
|
+
build(): ScheduledAction<TActionState>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Builder for `ScheduledAction` with state represented by default state (containing only last execution date).
|
|
53
|
+
*/
|
|
54
|
+
export declare class ScheduledActionBuilder extends ScheduledActionBuilderWithState<ActionStateBase> {
|
|
55
|
+
/**
|
|
56
|
+
* Builder for `ScheduledAction` with state represented by default state (containing only last execution date).
|
|
57
|
+
*/
|
|
58
|
+
constructor(name: string);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=scheduledActionBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduledActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/scheduledActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAG3D;;GAEG;AACH,qBAAa,+BAA+B,CACxC,YAAY,SAAS,YAAY;IAEjC,MAAM,UAAQ;IACd,IAAI,EAAE,UAAU,CAAK;IACrB,oBAAoB,kCAAyC;IAC7D,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAa;IAEpD,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;gBACS,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,YAAY;IAK9D;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM;IAMtB;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU;IAMtB;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAM1C;;;;;;OAMG;IACH,eAAe,CACX,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EACnC,0BAA0B,GAAE,KAAmB;IAUnD,iFAAiF;IACjF,QAAQ;IAMR,oBAAoB;IACpB,KAAK;CAWR;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,+BAA+B,CAAC,eAAe,CAAC;IACxF;;OAEG;gBACS,IAAI,EAAE,MAAM;CAG3B"}
|