chz-telegram-bot 0.0.25 → 0.0.27
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/actions/commandAction.d.ts +3 -3
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +12 -7
- package/dist/entities/actions/scheduledAction.d.ts +2 -2
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
- package/dist/entities/botInstance.d.ts.map +1 -1
- package/dist/entities/botInstance.js +3 -2
- package/dist/entities/context/chatContext.d.ts +3 -2
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +6 -6
- package/dist/entities/context/messageContext.d.ts +3 -1
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +19 -11
- package/dist/entities/responses/imageMessage.d.ts +3 -2
- package/dist/entities/responses/imageMessage.d.ts.map +1 -1
- package/dist/entities/responses/imageMessage.js +2 -2
- package/dist/entities/responses/reaction.d.ts +3 -2
- package/dist/entities/responses/reaction.d.ts.map +1 -1
- package/dist/entities/responses/reaction.js +2 -2
- package/dist/entities/responses/textMessage.d.ts +3 -2
- package/dist/entities/responses/textMessage.d.ts.map +1 -1
- package/dist/entities/responses/textMessage.js +2 -2
- package/dist/entities/responses/unpin.d.ts +3 -2
- package/dist/entities/responses/unpin.d.ts.map +1 -1
- package/dist/entities/responses/unpin.js +2 -2
- package/dist/entities/responses/videoMessage.d.ts +3 -2
- package/dist/entities/responses/videoMessage.d.ts.map +1 -1
- package/dist/entities/responses/videoMessage.js +2 -2
- package/dist/helpers/builders/commandActionBuilder.d.ts +3 -3
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/services/jsonFileStorage.d.ts +6 -7
- package/dist/services/jsonFileStorage.d.ts.map +1 -1
- package/dist/services/jsonFileStorage.js +29 -23
- package/dist/services/logger.d.ts.map +1 -1
- package/dist/services/logger.js +2 -8
- package/dist/services/taskScheduler.d.ts.map +1 -1
- package/dist/services/taskScheduler.js +0 -1
- package/dist/services/telegramApi.d.ts +1 -1
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +6 -9
- package/dist/types/actionWithState.d.ts +4 -1
- package/dist/types/actionWithState.d.ts.map +1 -1
- package/dist/types/response.d.ts +2 -1
- package/dist/types/response.d.ts.map +1 -1
- package/dist/types/storage.d.ts +4 -4
- package/dist/types/storage.d.ts.map +1 -1
- package/entities/actions/commandAction.ts +20 -12
- package/entities/actions/scheduledAction.ts +3 -3
- package/entities/botInstance.ts +4 -5
- package/entities/context/chatContext.ts +9 -15
- package/entities/context/messageContext.ts +30 -27
- package/entities/responses/imageMessage.ts +4 -3
- package/entities/responses/reaction.ts +4 -3
- package/entities/responses/textMessage.ts +4 -3
- package/entities/responses/unpin.ts +4 -3
- package/entities/responses/videoMessage.ts +4 -3
- package/helpers/builders/commandActionBuilder.ts +3 -3
- package/package.json +1 -1
- package/services/jsonFileStorage.ts +41 -27
- package/services/logger.ts +6 -8
- package/services/taskScheduler.ts +0 -1
- package/services/telegramApi.ts +9 -18
- package/types/actionWithState.ts +3 -1
- package/types/response.ts +3 -1
- package/types/storage.ts +4 -4
|
@@ -2,7 +2,7 @@ import { CommandHandler } from '../../types/handlers';
|
|
|
2
2
|
import { CommandCondition } from '../../types/commandCondition';
|
|
3
3
|
import { Seconds } from '../../types/timeValues';
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
|
-
import { IActionWithState } from '../../types/actionWithState';
|
|
5
|
+
import { IActionWithState, ActionKey } from '../../types/actionWithState';
|
|
6
6
|
import { MessageContext } from '../context/messageContext';
|
|
7
7
|
export declare class CommandAction<TActionState extends IActionState> implements IActionWithState {
|
|
8
8
|
triggers: (string | RegExp)[];
|
|
@@ -14,8 +14,8 @@ export declare class CommandAction<TActionState extends IActionState> implements
|
|
|
14
14
|
allowedUsers: number[];
|
|
15
15
|
condition: CommandCondition<TActionState>;
|
|
16
16
|
stateConstructor: () => TActionState;
|
|
17
|
-
key:
|
|
18
|
-
constructor(trigger: string | RegExp |
|
|
17
|
+
key: ActionKey;
|
|
18
|
+
constructor(trigger: string | RegExp | string[] | RegExp[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState);
|
|
19
19
|
exec(ctx: MessageContext<TActionState>): Promise<void>;
|
|
20
20
|
private checkTrigger;
|
|
21
21
|
}
|
|
@@ -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,MAAM,6BAA6B,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;AAI3D,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB;IAE3B,QAAQ,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC9B,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,OAAO,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC1C,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,GAAG,EAAE,SAAS,CAAC;gBAGX,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAC9C,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;IAgD5C,OAAO,CAAC,YAAY;CAkDvB"}
|
|
@@ -62,15 +62,20 @@ class CommandAction {
|
|
|
62
62
|
shouldTrigger = ctx.messageText.toLowerCase() == trigger;
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
trigger.lastIndex = 0;
|
|
66
|
+
const execResult = trigger.exec(ctx.messageText);
|
|
67
|
+
if (execResult != null) {
|
|
68
|
+
matchResults.push(execResult);
|
|
69
|
+
if (trigger.global) {
|
|
70
|
+
while (true) {
|
|
71
|
+
const nextResult = trigger.exec(ctx.messageText);
|
|
72
|
+
if (nextResult == null)
|
|
73
|
+
break;
|
|
74
|
+
matchResults.push(nextResult);
|
|
75
|
+
}
|
|
71
76
|
}
|
|
72
|
-
shouldTrigger = true;
|
|
73
77
|
}
|
|
78
|
+
shouldTrigger = matchResults.length > 0;
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
return new commandTriggerCheckResult_1.CommandTriggerCheckResult(shouldTrigger, matchResults, !isUserAllowed);
|
|
@@ -2,7 +2,7 @@ import { Sema as Semaphore } from 'async-sema';
|
|
|
2
2
|
import { ScheduledHandler } from '../../types/handlers';
|
|
3
3
|
import { HoursOfDay } from '../../types/timeValues';
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
|
-
import { IActionWithState } from '../../types/actionWithState';
|
|
5
|
+
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 {
|
|
@@ -11,7 +11,7 @@ export declare class ScheduledAction<TActionState extends IActionState> implemen
|
|
|
11
11
|
timeinHours: HoursOfDay;
|
|
12
12
|
active: boolean;
|
|
13
13
|
chatsWhitelist: number[];
|
|
14
|
-
key:
|
|
14
|
+
key: ActionKey;
|
|
15
15
|
cachedState: Map<string, unknown>;
|
|
16
16
|
stateConstructor: () => TActionState;
|
|
17
17
|
cachedStateFactories: Map<string, CachedStateFactory>;
|
|
@@ -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,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3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|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D,qBAAa,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,EAAE,cAAc,CAAC;gBAEZ,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,aAAa,CAAC,EAAE,cAAc,CAAC;QAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;KACxB;
|
|
1
|
+
{"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D,qBAAa,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,EAAE,cAAc,CAAC;gBAEZ,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,aAAa,CAAC,EAAE,cAAc,CAAC;QAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;KACxB;IAiCD,OAAO,CAAC,6BAA6B;IA6CrC,OAAO,CAAC,2BAA2B;IAsB7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAYT,YAAY;YAyBZ,cAAc;CAmB/B"}
|
|
@@ -18,15 +18,16 @@ class BotInstance {
|
|
|
18
18
|
this.commands = options.commands;
|
|
19
19
|
this.scheduled = options.scheduled;
|
|
20
20
|
this.chats = options.chats;
|
|
21
|
+
const actions = [...this.commands, ...this.scheduled];
|
|
21
22
|
logger_1.Logger.logWithTraceId(this.name, `System:Bot-${this.name}-Start`, 'System', 'Starting bot...');
|
|
22
23
|
this.telegraf = new telegraf_1.Telegraf(options.token);
|
|
23
24
|
this.storage =
|
|
24
25
|
options.storageClient ??
|
|
25
|
-
new jsonFileStorage_1.JsonFileStorage(options.name, options.storagePath);
|
|
26
|
+
new jsonFileStorage_1.JsonFileStorage(options.name, actions, options.storagePath);
|
|
26
27
|
this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage, this.chats);
|
|
27
28
|
this.initializeMessageProcessing();
|
|
28
29
|
this.initializeScheduledProcessing();
|
|
29
|
-
this.storage.saveMetadata(
|
|
30
|
+
this.storage.saveMetadata(actions, this.name);
|
|
30
31
|
this.telegraf.launch();
|
|
31
32
|
}
|
|
32
33
|
initializeScheduledProcessing() {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { IBotApiInteractions } from '../../services/telegramApi';
|
|
2
2
|
import { IStorageClient } from '../../types/storage';
|
|
3
3
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
4
5
|
/**
|
|
5
6
|
* Context of action executed in chat.
|
|
6
7
|
*/
|
|
7
8
|
export declare class ChatContext<TActionState> {
|
|
8
|
-
protected
|
|
9
|
+
protected action: IActionWithState;
|
|
9
10
|
protected interactions: IBotApiInteractions;
|
|
10
11
|
updateActions: Array<(state: TActionState) => void>;
|
|
11
12
|
/** Trace id of a action execution. */
|
|
@@ -18,7 +19,7 @@ export declare class ChatContext<TActionState> {
|
|
|
18
19
|
chatName: string;
|
|
19
20
|
/** Storage client instance for this bot. */
|
|
20
21
|
storage: IStorageClient;
|
|
21
|
-
constructor(botName: string,
|
|
22
|
+
constructor(botName: string, action: IActionWithState, interactions: IBotApiInteractions, chatId: number, chatName: string, traceId: number | string, storage: IStorageClient);
|
|
22
23
|
/**
|
|
23
24
|
* Manually update the state of an action.
|
|
24
25
|
* @param stateUpdateAction Function that will modify state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4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10 @@ const unpin_1 = require("../responses/unpin");
|
|
|
10
10
|
* Context of action executed in chat.
|
|
11
11
|
*/
|
|
12
12
|
class ChatContext {
|
|
13
|
-
constructor(botName,
|
|
13
|
+
constructor(botName, action, interactions, chatId, chatName, traceId, storage) {
|
|
14
14
|
this.updateActions = [];
|
|
15
15
|
this.botName = botName;
|
|
16
|
-
this.
|
|
16
|
+
this.action = action;
|
|
17
17
|
this.interactions = interactions;
|
|
18
18
|
this.chatId = chatId;
|
|
19
19
|
this.chatName = chatName;
|
|
@@ -33,7 +33,7 @@ class ChatContext {
|
|
|
33
33
|
* @param options Message sending option.
|
|
34
34
|
*/
|
|
35
35
|
sendTextToChat(text, options) {
|
|
36
|
-
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, undefined, this.traceId, this.
|
|
36
|
+
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, undefined, this.traceId, this.action, options));
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Sends image message to chat.
|
|
@@ -42,7 +42,7 @@ class ChatContext {
|
|
|
42
42
|
*/
|
|
43
43
|
sendImageToChat(name, options) {
|
|
44
44
|
const filePath = `./content/${name}.png`;
|
|
45
|
-
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.
|
|
45
|
+
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.action, options));
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Sends video/gif message to chat.
|
|
@@ -51,14 +51,14 @@ class ChatContext {
|
|
|
51
51
|
*/
|
|
52
52
|
sendVideoToChat(name, options) {
|
|
53
53
|
const filePath = `./content/${name}.mp4`;
|
|
54
|
-
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.
|
|
54
|
+
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.action, options));
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Unpins message.
|
|
58
58
|
* @param messageId Message id.
|
|
59
59
|
*/
|
|
60
60
|
unpinMessage(messageId) {
|
|
61
|
-
this.interactions.unpin(new unpin_1.UnpinResponse(messageId, this.chatId, this.traceId, this.
|
|
61
|
+
this.interactions.unpin(new unpin_1.UnpinResponse(messageId, this.chatId, this.traceId, this.action));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
exports.ChatContext = ChatContext;
|
|
@@ -3,7 +3,9 @@ import { TelegramEmoji } from 'telegraf/types';
|
|
|
3
3
|
import { IStorageClient } from '../../types/storage';
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
5
|
import { ChatContext } from './chatContext';
|
|
6
|
+
import { IncomingMessage } from '../incomingMessage';
|
|
6
7
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
8
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
7
9
|
/**
|
|
8
10
|
* Context of action executed in chat, in response to a message
|
|
9
11
|
*/
|
|
@@ -20,7 +22,7 @@ export declare class MessageContext<TActionState extends IActionState> extends C
|
|
|
20
22
|
startCooldown: boolean;
|
|
21
23
|
/** Name of a user that sent a message that triggered this action. */
|
|
22
24
|
fromUserName: string;
|
|
23
|
-
constructor(botName: string,
|
|
25
|
+
constructor(botName: string, action: IActionWithState, interactions: IBotApiInteractions, message: IncomingMessage, storage: IStorageClient);
|
|
24
26
|
/**
|
|
25
27
|
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
26
28
|
* @param commandName Name of an action to load state of.
|
|
@@ -1 +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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,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,cAAc;IAoB3B;;;;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"}
|
|
@@ -12,16 +12,18 @@ const chatContext_1 = require("./chatContext");
|
|
|
12
12
|
* Context of action executed in chat, in response to a message
|
|
13
13
|
*/
|
|
14
14
|
class MessageContext extends chatContext_1.ChatContext {
|
|
15
|
-
constructor(botName,
|
|
16
|
-
super(botName,
|
|
15
|
+
constructor(botName, action, interactions, message, storage) {
|
|
16
|
+
super(botName, action, interactions, message.chat.id, message.chatName, message.traceId, storage);
|
|
17
17
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
18
18
|
this.matchResults = [];
|
|
19
19
|
/** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
|
|
20
20
|
this.startCooldown = true;
|
|
21
|
-
this.messageId =
|
|
22
|
-
this.messageText =
|
|
23
|
-
this.fromUserId =
|
|
24
|
-
this.fromUserName =
|
|
21
|
+
this.messageId = message.message_id;
|
|
22
|
+
this.messageText = message.text ?? '';
|
|
23
|
+
this.fromUserId = message.from?.id;
|
|
24
|
+
this.fromUserName =
|
|
25
|
+
(message.from?.first_name ?? 'Unknown user') +
|
|
26
|
+
(message.from?.last_name ? ` ${message.from.last_name}` : '');
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
@@ -29,7 +31,13 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
29
31
|
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
30
32
|
*/
|
|
31
33
|
async loadStateOf(commandName) {
|
|
32
|
-
|
|
34
|
+
const storageKey = `command:${commandName.replace('.', '-')}`;
|
|
35
|
+
const allStates = await this.storage.load(storageKey);
|
|
36
|
+
const stateForChat = allStates[this.chatId];
|
|
37
|
+
if (!stateForChat) {
|
|
38
|
+
return new actionStateBase_1.ActionStateBase();
|
|
39
|
+
}
|
|
40
|
+
return stateForChat;
|
|
33
41
|
}
|
|
34
42
|
/**
|
|
35
43
|
* Reply with text message to message that triggered this action.
|
|
@@ -37,7 +45,7 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
37
45
|
* @param options Message sending option.
|
|
38
46
|
*/
|
|
39
47
|
replyWithText(text, options) {
|
|
40
|
-
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, this.messageId, this.traceId, this.
|
|
48
|
+
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, this.messageId, this.traceId, this.action, options));
|
|
41
49
|
}
|
|
42
50
|
/**
|
|
43
51
|
* Reply with image message to message that triggered this action.
|
|
@@ -46,7 +54,7 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
46
54
|
*/
|
|
47
55
|
replyWithImage(name, options) {
|
|
48
56
|
const filePath = `./content/${name}.png`;
|
|
49
|
-
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.
|
|
57
|
+
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.action, options));
|
|
50
58
|
}
|
|
51
59
|
/**
|
|
52
60
|
* Reply with video/gif message to message that triggered this action.
|
|
@@ -55,14 +63,14 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
55
63
|
*/
|
|
56
64
|
replyWithVideo(name, options) {
|
|
57
65
|
const filePath = `./content/${name}.mp4`;
|
|
58
|
-
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.
|
|
66
|
+
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.action, options));
|
|
59
67
|
}
|
|
60
68
|
/**
|
|
61
69
|
* React to the message that triggered this action.
|
|
62
70
|
* @param emoji Telegram emoji to react with.
|
|
63
71
|
*/
|
|
64
72
|
react(emoji) {
|
|
65
|
-
this.interactions.react(new reaction_1.Reaction(this.traceId, this.chatId, this.messageId, emoji, this.
|
|
73
|
+
this.interactions.react(new reaction_1.Reaction(this.traceId, this.chatId, this.messageId, emoji, this.action));
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
exports.MessageContext = MessageContext;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InputFile } from 'telegraf/types';
|
|
2
2
|
import { IReplyMessage } from '../../types/response';
|
|
3
3
|
import { MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
4
5
|
export declare class ImageMessage implements IReplyMessage<InputFile> {
|
|
5
6
|
kind: "image";
|
|
6
7
|
content: InputFile;
|
|
@@ -9,7 +10,7 @@ export declare class ImageMessage implements IReplyMessage<InputFile> {
|
|
|
9
10
|
traceId: string | number;
|
|
10
11
|
disableWebPreview: boolean;
|
|
11
12
|
shouldPin: boolean;
|
|
12
|
-
|
|
13
|
-
constructor(image: InputFile, chatId: number, replyId: number | undefined, traceId: number | string,
|
|
13
|
+
action: IActionWithState;
|
|
14
|
+
constructor(image: InputFile, chatId: number, replyId: number | undefined, traceId: number | string, action: IActionWithState, options?: MessageSendingOptions);
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=imageMessage.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ImageMessage = void 0;
|
|
4
4
|
const response_1 = require("../../types/response");
|
|
5
5
|
class ImageMessage {
|
|
6
|
-
constructor(image, chatId, replyId, traceId,
|
|
6
|
+
constructor(image, chatId, replyId, traceId, action, options) {
|
|
7
7
|
this.kind = response_1.BotResponseTypes.image;
|
|
8
8
|
this.disableWebPreview = false;
|
|
9
9
|
this.content = image;
|
|
@@ -11,7 +11,7 @@ class ImageMessage {
|
|
|
11
11
|
this.replyId = replyId;
|
|
12
12
|
this.traceId = traceId;
|
|
13
13
|
this.shouldPin = options?.pin ?? false;
|
|
14
|
-
this.
|
|
14
|
+
this.action = action;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.ImageMessage = ImageMessage;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { TelegramEmoji } from 'telegraf/types';
|
|
2
2
|
import { IChatResponse } from '../../types/response';
|
|
3
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
3
4
|
export declare class Reaction implements IChatResponse {
|
|
4
5
|
kind: "react";
|
|
5
6
|
chatId: number;
|
|
6
7
|
messageId: number;
|
|
7
8
|
traceId: number | string;
|
|
8
9
|
emoji: TelegramEmoji;
|
|
9
|
-
|
|
10
|
-
constructor(traceId: number | string, chatId: number, messageId: number, emoji: TelegramEmoji,
|
|
10
|
+
action: IActionWithState;
|
|
11
|
+
constructor(traceId: number | string, chatId: number, messageId: number, emoji: TelegramEmoji, action: IActionWithState);
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=reaction.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Reaction = void 0;
|
|
4
4
|
const response_1 = require("../../types/response");
|
|
5
5
|
class Reaction {
|
|
6
|
-
constructor(traceId, chatId, messageId, emoji,
|
|
6
|
+
constructor(traceId, chatId, messageId, emoji, action) {
|
|
7
7
|
this.kind = response_1.BotResponseTypes.react;
|
|
8
8
|
this.chatId = chatId;
|
|
9
9
|
this.messageId = messageId;
|
|
10
10
|
this.emoji = emoji;
|
|
11
11
|
this.traceId = traceId;
|
|
12
|
-
this.
|
|
12
|
+
this.action = action;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
exports.Reaction = Reaction;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
2
2
|
import { IReplyMessage } from '../../types/response';
|
|
3
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
3
4
|
export declare class TextMessage implements IReplyMessage<string> {
|
|
4
5
|
kind: "text";
|
|
5
6
|
content: string;
|
|
@@ -8,7 +9,7 @@ export declare class TextMessage implements IReplyMessage<string> {
|
|
|
8
9
|
traceId: string | number;
|
|
9
10
|
disableWebPreview: boolean;
|
|
10
11
|
shouldPin: boolean;
|
|
11
|
-
|
|
12
|
-
constructor(text: string, chatId: number, replyId: number | undefined, traceId: string | number,
|
|
12
|
+
action: IActionWithState;
|
|
13
|
+
constructor(text: string, chatId: number, replyId: number | undefined, traceId: string | number, action: IActionWithState, options?: TextMessageSendingOptions);
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=textMessage.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TextMessage = void 0;
|
|
4
4
|
const response_1 = require("../../types/response");
|
|
5
5
|
class TextMessage {
|
|
6
|
-
constructor(text, chatId, replyId, traceId,
|
|
6
|
+
constructor(text, chatId, replyId, traceId, action, options) {
|
|
7
7
|
this.kind = response_1.BotResponseTypes.text;
|
|
8
8
|
this.content = text;
|
|
9
9
|
this.chatId = chatId;
|
|
@@ -11,7 +11,7 @@ class TextMessage {
|
|
|
11
11
|
this.traceId = traceId;
|
|
12
12
|
this.disableWebPreview = options?.disableWebPreview ?? false;
|
|
13
13
|
this.shouldPin = options?.pin ?? false;
|
|
14
|
-
this.
|
|
14
|
+
this.action = action;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.TextMessage = TextMessage;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { IChatResponse } from '../../types/response';
|
|
2
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
2
3
|
export declare class UnpinResponse implements IChatResponse {
|
|
3
4
|
kind: "unpin";
|
|
4
5
|
messageId: number;
|
|
5
6
|
chatId: number;
|
|
6
7
|
traceId: number | string;
|
|
7
|
-
|
|
8
|
-
constructor(messageId: number, chatId: number, traceId: number | string,
|
|
8
|
+
action: IActionWithState;
|
|
9
|
+
constructor(messageId: number, chatId: number, traceId: number | string, action: IActionWithState);
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=unpin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unpin.d.ts","sourceRoot":"","sources":["../../../entities/responses/unpin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
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"}
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.UnpinResponse = void 0;
|
|
4
4
|
const response_1 = require("../../types/response");
|
|
5
5
|
class UnpinResponse {
|
|
6
|
-
constructor(messageId, chatId, traceId,
|
|
6
|
+
constructor(messageId, chatId, traceId, action) {
|
|
7
7
|
this.kind = response_1.BotResponseTypes.unpin;
|
|
8
8
|
this.messageId = messageId;
|
|
9
9
|
this.chatId = chatId;
|
|
10
10
|
this.traceId = traceId;
|
|
11
|
-
this.
|
|
11
|
+
this.action = action;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.UnpinResponse = UnpinResponse;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InputFile } from 'telegraf/types';
|
|
2
2
|
import { IReplyMessage } from '../../types/response';
|
|
3
3
|
import { MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
4
5
|
export declare class VideoMessage implements IReplyMessage<InputFile> {
|
|
5
6
|
kind: "video";
|
|
6
7
|
content: InputFile;
|
|
@@ -9,7 +10,7 @@ export declare class VideoMessage implements IReplyMessage<InputFile> {
|
|
|
9
10
|
traceId: string | number;
|
|
10
11
|
disableWebPreview: boolean;
|
|
11
12
|
shouldPin: boolean;
|
|
12
|
-
|
|
13
|
-
constructor(video: InputFile, chatId: number, replyId: number | undefined, traceId: number | string,
|
|
13
|
+
action: IActionWithState;
|
|
14
|
+
constructor(video: InputFile, chatId: number, replyId: number | undefined, traceId: number | string, action: IActionWithState, options?: MessageSendingOptions);
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=videoMessage.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VideoMessage = void 0;
|
|
4
4
|
const response_1 = require("../../types/response");
|
|
5
5
|
class VideoMessage {
|
|
6
|
-
constructor(video, chatId, replyId, traceId,
|
|
6
|
+
constructor(video, chatId, replyId, traceId, action, options) {
|
|
7
7
|
this.kind = response_1.BotResponseTypes.video;
|
|
8
8
|
this.disableWebPreview = false;
|
|
9
9
|
this.content = video;
|
|
@@ -11,7 +11,7 @@ class VideoMessage {
|
|
|
11
11
|
this.replyId = replyId;
|
|
12
12
|
this.traceId = traceId;
|
|
13
13
|
this.shouldPin = options?.pin ?? false;
|
|
14
|
-
this.
|
|
14
|
+
this.action = action;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.VideoMessage = VideoMessage;
|
|
@@ -9,7 +9,7 @@ import { IActionState } from '../../types/actionState';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
11
11
|
name: string;
|
|
12
|
-
trigger: string | RegExp |
|
|
12
|
+
trigger: string | RegExp | string[] | RegExp[];
|
|
13
13
|
active: boolean;
|
|
14
14
|
cooldownSeconds: Seconds;
|
|
15
15
|
blacklist: number[];
|
|
@@ -29,11 +29,11 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
29
29
|
*
|
|
30
30
|
* If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
|
|
31
31
|
*/
|
|
32
|
-
on(trigger: string | RegExp |
|
|
32
|
+
on(trigger: string | RegExp | string[] | RegExp[]): this;
|
|
33
33
|
/** Defines id (or ids) of users that are allowed to trigger this action.
|
|
34
34
|
* @param id User id or ids
|
|
35
35
|
*/
|
|
36
|
-
from(id: number |
|
|
36
|
+
from(id: number | number[]): this;
|
|
37
37
|
/** Defines action logic itself, will be executed on trigger.
|
|
38
38
|
* @param handler Callback that will be called on trigger
|
|
39
39
|
*/
|
|
@@ -1 +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;AAIvD;;GAEG;AACH,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,
|
|
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;AAIvD;;GAEG;AACH,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAAM;IAEpD,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,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE;IAMjD;;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"}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { Sema as Semaphore } from 'async-sema';
|
|
2
1
|
import { IStorageClient } from '../types/storage';
|
|
3
2
|
import { ActionExecutionResult } from '../entities/actionExecutionResult';
|
|
4
3
|
import { IActionState } from '../types/actionState';
|
|
5
|
-
import { IActionWithState } from '../types/actionWithState';
|
|
4
|
+
import { IActionWithState, ActionKey } from '../types/actionWithState';
|
|
6
5
|
export declare class JsonFileStorage implements IStorageClient {
|
|
7
|
-
|
|
6
|
+
private locks;
|
|
8
7
|
private cache;
|
|
9
8
|
private storagePath;
|
|
10
9
|
private botName;
|
|
11
|
-
constructor(botName: string, path?: string);
|
|
10
|
+
constructor(botName: string, actions: IActionWithState[], path?: string);
|
|
12
11
|
private lock;
|
|
13
12
|
private loadInternal;
|
|
14
13
|
private save;
|
|
15
14
|
private buidPathFromKey;
|
|
16
|
-
load<TActionState extends IActionState>(key:
|
|
15
|
+
load<TActionState extends IActionState>(key: ActionKey): Promise<Record<number, TActionState>>;
|
|
17
16
|
saveMetadata(actions: IActionWithState[], botName: string): Promise<void>;
|
|
18
|
-
getActionState<TActionState extends IActionState>(
|
|
17
|
+
getActionState<TActionState extends IActionState>(action: IActionWithState, chatId: number): Promise<TActionState>;
|
|
19
18
|
saveActionExecutionResult(action: IActionWithState, chatId: number, transactionResult: ActionExecutionResult): Promise<void>;
|
|
20
19
|
close(): Promise<void>;
|
|
21
|
-
updateStateFor<TActionState extends IActionState>(
|
|
20
|
+
updateStateFor<TActionState extends IActionState>(action: IActionWithState, chatId: number, update: (state: TActionState) => Promise<void>): Promise<void>;
|
|
22
21
|
}
|
|
23
22
|
//# sourceMappingURL=jsonFileStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAEvE,qBAAa,eAAgB,YAAW,cAAc;IAClD,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,KAAK,CAA4C;IACzD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM;YAgBzD,IAAI;YAgBJ,YAAY;YAqBZ,IAAI;IAalB,OAAO,CAAC,eAAe;IAOjB,IAAI,CAAC,YAAY,SAAS,YAAY,EAAE,GAAG,EAAE,SAAS;IAMtD,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,MAAM;IAUzD,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM;IAYZ,yBAAyB,CAC3B,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,qBAAqB;IAYtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC;CAcrD"}
|