chz-telegram-bot 0.5.0 → 0.5.2
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/builtin/helpAction.js +3 -6
- package/dist/dtos/chatHistoryMessage.js +1 -5
- package/dist/dtos/chatInfo.js +1 -5
- package/dist/dtos/commandTriggerCheckResult.js +1 -5
- package/dist/dtos/cooldownInfo.js +1 -5
- package/dist/dtos/incomingMessage.js +21 -25
- package/dist/dtos/incomingQuery.js +1 -5
- package/dist/dtos/messageInfo.js +1 -5
- package/dist/dtos/propertyProviderSets.js +1 -2
- package/dist/dtos/replyInfo.js +1 -5
- package/dist/dtos/responses/delay.js +3 -7
- package/dist/dtos/responses/imageMessage.js +3 -7
- package/dist/dtos/responses/inlineQueryResponse.js +3 -7
- package/dist/dtos/responses/reaction.js +3 -7
- package/dist/dtos/responses/textMessage.d.ts +2 -0
- package/dist/dtos/responses/textMessage.d.ts.map +1 -1
- package/dist/dtos/responses/textMessage.js +5 -7
- package/dist/dtos/responses/unpin.js +3 -7
- package/dist/dtos/responses/videoMessage.js +3 -7
- package/dist/dtos/userInfo.js +1 -5
- package/dist/entities/actions/commandAction.js +32 -39
- package/dist/entities/actions/inlineQueryAction.js +4 -8
- package/dist/entities/actions/replyCaptureAction.js +10 -14
- package/dist/entities/actions/scheduledAction.js +16 -23
- package/dist/entities/botInstance.js +13 -17
- package/dist/entities/cachedStateFactory.js +1 -5
- package/dist/entities/context/baseContext.d.ts +1 -1
- package/dist/entities/context/baseContext.d.ts.map +1 -1
- package/dist/entities/context/baseContext.js +1 -5
- package/dist/entities/context/chatContext.js +13 -17
- package/dist/entities/context/inlineQueryContext.js +4 -8
- package/dist/entities/context/messageContext.js +15 -19
- package/dist/entities/context/replyContext.js +15 -19
- package/dist/entities/states/actionStateBase.js +1 -5
- package/dist/entities/taskRecord.js +1 -5
- package/dist/eslint.config.d.ts +3 -0
- package/dist/eslint.config.d.ts.map +1 -0
- package/dist/eslint.config.js +51 -0
- package/dist/helpers/builders/commandActionBuilder.js +15 -20
- package/dist/helpers/builders/inlineQueryActionBuilder.js +5 -9
- package/dist/helpers/builders/scheduledActionBuilder.js +10 -15
- package/dist/helpers/mapUtils.js +2 -6
- package/dist/helpers/noop.js +1 -5
- package/dist/helpers/objectFromEntries.js +1 -5
- package/dist/helpers/timeConvertions.js +3 -8
- package/dist/helpers/toArray.js +1 -4
- package/dist/helpers/traceFactory.js +1 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -41
- package/dist/main.js +5 -8
- package/dist/services/actionProcessingService.js +15 -19
- package/dist/services/actionProcessors/baseProcessor.js +1 -5
- package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/commandActionProcessor.js +35 -38
- package/dist/services/actionProcessors/inlineQueryActionProcessor.js +7 -11
- package/dist/services/actionProcessors/scheduledActionProcessor.js +12 -19
- package/dist/services/jsonFileStorage.js +15 -19
- package/dist/services/jsonLogger.js +1 -5
- package/dist/services/nodeTimeoutScheduler.js +9 -13
- package/dist/services/responseProcessingQueue.js +3 -7
- package/dist/services/telegramApi.d.ts +1 -0
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +27 -27
- package/dist/types/action.js +1 -2
- package/dist/types/actionState.js +1 -2
- package/dist/types/cachedValueAccessor.js +1 -2
- package/dist/types/capture.js +1 -2
- package/dist/types/commandCondition.js +1 -2
- package/dist/types/commandTrigger.js +1 -2
- package/dist/types/externalAliases.d.ts +3 -3
- package/dist/types/externalAliases.d.ts.map +1 -1
- package/dist/types/externalAliases.js +1 -2
- package/dist/types/handlers.js +1 -2
- package/dist/types/inputFile.js +1 -2
- package/dist/types/logger.js +1 -2
- package/dist/types/messageSendingOptions.d.ts +2 -0
- package/dist/types/messageSendingOptions.d.ts.map +1 -1
- package/dist/types/messageSendingOptions.js +1 -2
- package/dist/types/messageTypes.js +17 -20
- package/dist/types/propertyProvider.js +1 -2
- package/dist/types/response.js +1 -4
- package/dist/types/scheduler.js +1 -2
- package/dist/types/storage.js +1 -2
- package/dist/types/timeValues.js +1 -2
- package/dist/types/trace.js +1 -2
- package/dtos/responses/textMessage.ts +3 -0
- package/entities/botInstance.ts +1 -1
- package/entities/context/messageContext.ts +3 -3
- package/entities/context/replyContext.ts +3 -3
- package/{eslint.config.js → eslint.config.ts} +9 -5
- package/index.ts +3 -0
- package/package.json +2 -1
- package/services/actionProcessors/commandActionProcessor.ts +5 -6
- package/services/jsonFileStorage.ts +1 -1
- package/services/nodeTimeoutScheduler.ts +2 -2
- package/services/telegramApi.ts +34 -25
- package/tsconfig.json +2 -2
- package/types/externalAliases.ts +5 -4
- package/types/messageSendingOptions.ts +3 -0
- package/bun.lock +0 -301
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const commandActionBuilder_1 = require("../helpers/builders/commandActionBuilder");
|
|
5
|
-
function buildHelpCommand(readmes, botUsername) {
|
|
6
|
-
const helpCommandBuilder = new commandActionBuilder_1.CommandActionBuilder('Reaction.Help')
|
|
1
|
+
import { CommandActionBuilder } from '../helpers/builders/commandActionBuilder';
|
|
2
|
+
export function buildHelpCommand(readmes, botUsername) {
|
|
3
|
+
const helpCommandBuilder = new CommandActionBuilder('Reaction.Help')
|
|
7
4
|
.on(['/help', `/help@${botUsername}`])
|
|
8
5
|
.do((ctx) => {
|
|
9
6
|
ctx.reply.withText(readmes.join('\n\n'));
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChatHistoryMessage = void 0;
|
|
4
|
-
class ChatHistoryMessage {
|
|
1
|
+
export class ChatHistoryMessage {
|
|
5
2
|
id;
|
|
6
3
|
from;
|
|
7
4
|
text;
|
|
@@ -17,4 +14,3 @@ class ChatHistoryMessage {
|
|
|
17
14
|
this.replyToId = replyToId;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.ChatHistoryMessage = ChatHistoryMessage;
|
package/dist/dtos/chatInfo.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChatInfo = void 0;
|
|
4
|
-
class ChatInfo {
|
|
1
|
+
export class ChatInfo {
|
|
5
2
|
id;
|
|
6
3
|
name;
|
|
7
4
|
messageHistory;
|
|
@@ -17,4 +14,3 @@ class ChatInfo {
|
|
|
17
14
|
this.messageHistory = messageHistory;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.ChatInfo = ChatInfo;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandTriggerCheckResult = void 0;
|
|
4
1
|
const _SkipTriggerReasonsObject = {
|
|
5
2
|
UserIdMissing: 'UserIdMissing',
|
|
6
3
|
UserForbidden: 'UserForbidden',
|
|
@@ -11,7 +8,7 @@ const _SkipTriggerReasonsObject = {
|
|
|
11
8
|
ActionDisabled: 'ActionDisabled',
|
|
12
9
|
ChatForbidden: 'ChatForbidden'
|
|
13
10
|
};
|
|
14
|
-
class CommandTriggerCheckResult {
|
|
11
|
+
export class CommandTriggerCheckResult {
|
|
15
12
|
shouldExecute;
|
|
16
13
|
matchResults;
|
|
17
14
|
skipCooldown;
|
|
@@ -35,4 +32,3 @@ class CommandTriggerCheckResult {
|
|
|
35
32
|
return new CommandTriggerCheckResult(this.shouldExecute || other.shouldExecute, this.matchResults.concat(other.matchResults), this.skipCooldown || other.skipCooldown, other.reason);
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
exports.CommandTriggerCheckResult = CommandTriggerCheckResult;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CooldownInfo = void 0;
|
|
4
|
-
class CooldownInfo {
|
|
1
|
+
export class CooldownInfo {
|
|
5
2
|
cooldown;
|
|
6
3
|
message;
|
|
7
4
|
constructor(
|
|
@@ -13,4 +10,3 @@ class CooldownInfo {
|
|
|
13
10
|
this.message = message;
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
exports.CooldownInfo = CooldownInfo;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const chatInfo_1 = require("./chatInfo");
|
|
7
|
-
const traceFactory_1 = require("../helpers/traceFactory");
|
|
8
|
-
class IncomingMessage {
|
|
1
|
+
import { randomInt } from 'crypto';
|
|
2
|
+
import { MessageType } from '../types/messageTypes';
|
|
3
|
+
import { ChatInfo } from './chatInfo';
|
|
4
|
+
import { createTrace } from '../helpers/traceFactory';
|
|
5
|
+
export class IncomingMessage {
|
|
9
6
|
messageId;
|
|
10
7
|
chatInfo;
|
|
11
8
|
from;
|
|
@@ -16,35 +13,35 @@ class IncomingMessage {
|
|
|
16
13
|
updateObject;
|
|
17
14
|
detectMessageType(message) {
|
|
18
15
|
if ('forward_origin' in message)
|
|
19
|
-
return
|
|
16
|
+
return MessageType.Forward;
|
|
20
17
|
if ('text' in message)
|
|
21
|
-
return
|
|
18
|
+
return MessageType.Text;
|
|
22
19
|
if ('video' in message)
|
|
23
|
-
return
|
|
20
|
+
return MessageType.Video;
|
|
24
21
|
if ('photo' in message)
|
|
25
|
-
return
|
|
22
|
+
return MessageType.Photo;
|
|
26
23
|
if ('sticker' in message)
|
|
27
|
-
return
|
|
24
|
+
return MessageType.Sticker;
|
|
28
25
|
if ('animation' in message)
|
|
29
|
-
return
|
|
26
|
+
return MessageType.Animation;
|
|
30
27
|
if ('voice' in message)
|
|
31
|
-
return
|
|
28
|
+
return MessageType.Voice;
|
|
32
29
|
if ('audio' in message)
|
|
33
|
-
return
|
|
30
|
+
return MessageType.Audio;
|
|
34
31
|
if ('document' in message)
|
|
35
|
-
return
|
|
32
|
+
return MessageType.Document;
|
|
36
33
|
if ('left_chat_member' in message)
|
|
37
|
-
return
|
|
34
|
+
return MessageType.LeftChatMember;
|
|
38
35
|
if ('new_chat_member' in message)
|
|
39
|
-
return
|
|
36
|
+
return MessageType.NewChatMember;
|
|
40
37
|
if ('poll' in message)
|
|
41
|
-
return
|
|
38
|
+
return MessageType.Poll;
|
|
42
39
|
if ('location' in message)
|
|
43
|
-
return
|
|
44
|
-
return
|
|
40
|
+
return MessageType.Location;
|
|
41
|
+
return MessageType.Unknown;
|
|
45
42
|
}
|
|
46
43
|
constructor(ctxMessage, botName, history) {
|
|
47
|
-
this.traceId =
|
|
44
|
+
this.traceId = createTrace(this, botName, randomInt(10000, 99999).toString());
|
|
48
45
|
this.messageId = ctxMessage.message_id;
|
|
49
46
|
this.replyToMessageId =
|
|
50
47
|
'reply_to_message' in ctxMessage
|
|
@@ -52,7 +49,7 @@ class IncomingMessage {
|
|
|
52
49
|
: undefined;
|
|
53
50
|
this.from = ctxMessage.from;
|
|
54
51
|
this.text = this.getMessageText(ctxMessage);
|
|
55
|
-
this.chatInfo = new
|
|
52
|
+
this.chatInfo = new ChatInfo(ctxMessage.chat.id, 'title' in ctxMessage.chat
|
|
56
53
|
? `${ctxMessage.chat.title} ${ctxMessage.chat.id}`
|
|
57
54
|
: 'DM', history);
|
|
58
55
|
this.type = this.detectMessageType(ctxMessage);
|
|
@@ -64,4 +61,3 @@ class IncomingMessage {
|
|
|
64
61
|
return 'caption' in ctxMessage ? ctxMessage.caption ?? '' : '';
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
|
-
exports.IncomingMessage = IncomingMessage;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IncomingInlineQuery = void 0;
|
|
4
|
-
class IncomingInlineQuery {
|
|
1
|
+
export class IncomingInlineQuery {
|
|
5
2
|
queryId;
|
|
6
3
|
query;
|
|
7
4
|
userId;
|
|
@@ -15,4 +12,3 @@ class IncomingInlineQuery {
|
|
|
15
12
|
this.abortController = new AbortController();
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
exports.IncomingInlineQuery = IncomingInlineQuery;
|
package/dist/dtos/messageInfo.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageInfo = void 0;
|
|
4
|
-
class MessageInfo {
|
|
1
|
+
export class MessageInfo {
|
|
5
2
|
id;
|
|
6
3
|
text;
|
|
7
4
|
type;
|
|
@@ -21,4 +18,3 @@ class MessageInfo {
|
|
|
21
18
|
this.telegramUpdateObject = telegramUpdateObject;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
exports.MessageInfo = MessageInfo;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/dtos/replyInfo.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReplyInfo = void 0;
|
|
4
|
-
class ReplyInfo {
|
|
1
|
+
export class ReplyInfo {
|
|
5
2
|
id;
|
|
6
3
|
quote;
|
|
7
4
|
constructor(id, quote) {
|
|
@@ -9,4 +6,3 @@ class ReplyInfo {
|
|
|
9
6
|
this.quote = quote;
|
|
10
7
|
}
|
|
11
8
|
}
|
|
12
|
-
exports.ReplyInfo = ReplyInfo;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class DelayResponse {
|
|
6
|
-
kind = response_1.BotResponseTypes.delay;
|
|
1
|
+
import { BotResponseTypes } from '../../types/response';
|
|
2
|
+
export class DelayResponse {
|
|
3
|
+
kind = BotResponseTypes.delay;
|
|
7
4
|
createdAt = Date.now();
|
|
8
5
|
chatInfo;
|
|
9
6
|
traceId;
|
|
@@ -16,4 +13,3 @@ class DelayResponse {
|
|
|
16
13
|
this.action = action;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.DelayResponse = DelayResponse;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class ImageMessage {
|
|
6
|
-
kind = response_1.BotResponseTypes.image;
|
|
1
|
+
import { BotResponseTypes } from '../../types/response';
|
|
2
|
+
export class ImageMessage {
|
|
3
|
+
kind = BotResponseTypes.image;
|
|
7
4
|
createdAt = Date.now();
|
|
8
5
|
captures = [];
|
|
9
6
|
content;
|
|
@@ -22,4 +19,3 @@ class ImageMessage {
|
|
|
22
19
|
this.action = action;
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.ImageMessage = ImageMessage;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class InlineQueryResponse {
|
|
6
|
-
kind = response_1.BotResponseTypes.inlineQuery;
|
|
1
|
+
import { BotResponseTypes } from '../../types/response';
|
|
2
|
+
export class InlineQueryResponse {
|
|
3
|
+
kind = BotResponseTypes.inlineQuery;
|
|
7
4
|
createdAt = Date.now();
|
|
8
5
|
queryId;
|
|
9
6
|
traceId;
|
|
@@ -16,4 +13,3 @@ class InlineQueryResponse {
|
|
|
16
13
|
this.action = action;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.InlineQueryResponse = InlineQueryResponse;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class Reaction {
|
|
6
|
-
kind = response_1.BotResponseTypes.react;
|
|
1
|
+
import { BotResponseTypes } from '../../types/response';
|
|
2
|
+
export class Reaction {
|
|
3
|
+
kind = BotResponseTypes.react;
|
|
7
4
|
createdAt = Date.now();
|
|
8
5
|
chatInfo;
|
|
9
6
|
messageId;
|
|
@@ -18,4 +15,3 @@ class Reaction {
|
|
|
18
15
|
this.action = action;
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
exports.Reaction = Reaction;
|
|
@@ -5,6 +5,7 @@ import { ChatInfo } from '../chatInfo';
|
|
|
5
5
|
import { TraceId } from '../../types/trace';
|
|
6
6
|
import { ReplyInfo } from '../replyInfo';
|
|
7
7
|
import { IReplyCapture } from '../../types/capture';
|
|
8
|
+
import { TelegramInlineKeyboardButton } from '../../types/externalAliases';
|
|
8
9
|
export declare class TextMessage implements IReplyResponseWithContent<string> {
|
|
9
10
|
readonly kind: "text";
|
|
10
11
|
readonly createdAt: number;
|
|
@@ -16,6 +17,7 @@ export declare class TextMessage implements IReplyResponseWithContent<string> {
|
|
|
16
17
|
readonly disableWebPreview: boolean;
|
|
17
18
|
readonly shouldPin: boolean;
|
|
18
19
|
readonly action: IAction;
|
|
20
|
+
readonly keyboard?: TelegramInlineKeyboardButton[][];
|
|
19
21
|
constructor(text: string, chatInfo: ChatInfo, traceId: TraceId, action: IAction, replyInfo?: ReplyInfo, options?: TextMessageSendingOptions);
|
|
20
22
|
}
|
|
21
23
|
//# sourceMappingURL=textMessage.d.ts.map
|
|
@@ -1 +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,EAEH,yBAAyB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"textMessage.d.ts","sourceRoot":"","sources":["../../../dtos/responses/textMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAEH,yBAAyB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAE3E,qBAAa,WAAY,YAAW,yBAAyB,CAAC,MAAM,CAAC;IACjE,QAAQ,CAAC,IAAI,SAAyB;IACtC,QAAQ,CAAC,SAAS,SAAc;IAChC,QAAQ,CAAC,QAAQ,EAAE,aAAa,EAAE,CAAM;IAExC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,4BAA4B,EAAE,EAAE,CAAC;gBAGjD,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,OAAO,EACf,SAAS,CAAC,EAAE,SAAS,EACrB,OAAO,CAAC,EAAE,yBAAyB;CAW1C"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class TextMessage {
|
|
6
|
-
kind = response_1.BotResponseTypes.text;
|
|
1
|
+
import { BotResponseTypes } from '../../types/response';
|
|
2
|
+
export class TextMessage {
|
|
3
|
+
kind = BotResponseTypes.text;
|
|
7
4
|
createdAt = Date.now();
|
|
8
5
|
captures = [];
|
|
9
6
|
content;
|
|
@@ -13,6 +10,7 @@ class TextMessage {
|
|
|
13
10
|
disableWebPreview;
|
|
14
11
|
shouldPin;
|
|
15
12
|
action;
|
|
13
|
+
keyboard;
|
|
16
14
|
constructor(text, chatInfo, traceId, action, replyInfo, options) {
|
|
17
15
|
this.content = text;
|
|
18
16
|
this.chatInfo = chatInfo;
|
|
@@ -21,6 +19,6 @@ class TextMessage {
|
|
|
21
19
|
this.disableWebPreview = options?.disableWebPreview ?? false;
|
|
22
20
|
this.shouldPin = options?.pin ?? false;
|
|
23
21
|
this.action = action;
|
|
22
|
+
this.keyboard = options?.keyboard;
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
exports.TextMessage = TextMessage;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class UnpinResponse {
|
|
6
|
-
kind = response_1.BotResponseTypes.unpin;
|
|
1
|
+
import { BotResponseTypes } from '../../types/response';
|
|
2
|
+
export class UnpinResponse {
|
|
3
|
+
kind = BotResponseTypes.unpin;
|
|
7
4
|
createdAt = Date.now();
|
|
8
5
|
messageId;
|
|
9
6
|
chatInfo;
|
|
@@ -16,4 +13,3 @@ class UnpinResponse {
|
|
|
16
13
|
this.action = action;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.UnpinResponse = UnpinResponse;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class VideoMessage {
|
|
6
|
-
kind = response_1.BotResponseTypes.video;
|
|
1
|
+
import { BotResponseTypes } from '../../types/response';
|
|
2
|
+
export class VideoMessage {
|
|
3
|
+
kind = BotResponseTypes.video;
|
|
7
4
|
createdAt = Date.now();
|
|
8
5
|
captures = [];
|
|
9
6
|
content;
|
|
@@ -22,4 +19,3 @@ class VideoMessage {
|
|
|
22
19
|
this.action = action;
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.VideoMessage = VideoMessage;
|
package/dist/dtos/userInfo.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserInfo = void 0;
|
|
4
|
-
class UserInfo {
|
|
1
|
+
export class UserInfo {
|
|
5
2
|
id;
|
|
6
3
|
name;
|
|
7
4
|
constructor(
|
|
@@ -13,4 +10,3 @@ class UserInfo {
|
|
|
13
10
|
this.name = name;
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
exports.UserInfo = UserInfo;
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const messageTypes_1 = require("../../types/messageTypes");
|
|
13
|
-
const async_sema_1 = require("async-sema");
|
|
14
|
-
const mapUtils_1 = require("../../helpers/mapUtils");
|
|
15
|
-
const textMessage_1 = require("../../dtos/responses/textMessage");
|
|
16
|
-
const replyInfo_1 = require("../../dtos/replyInfo");
|
|
17
|
-
class CommandAction {
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import { secondsToMilliseconds } from '../../helpers/timeConvertions';
|
|
3
|
+
import { toArray } from '../../helpers/toArray';
|
|
4
|
+
import { CommandTriggerCheckResult } from '../../dtos/commandTriggerCheckResult';
|
|
5
|
+
import { Noop } from '../../helpers/noop';
|
|
6
|
+
import { MessageType } from '../../types/messageTypes';
|
|
7
|
+
import { Sema as Semaphore } from 'async-sema';
|
|
8
|
+
import { getOrSetIfNotExists } from '../../helpers/mapUtils';
|
|
9
|
+
import { TextMessage } from '../../dtos/responses/textMessage';
|
|
10
|
+
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
11
|
+
export class CommandAction {
|
|
18
12
|
cooldownInfoProvider;
|
|
19
13
|
isActiveProvider;
|
|
20
14
|
chatsBlacklistProvider;
|
|
@@ -31,7 +25,7 @@ class CommandAction {
|
|
|
31
25
|
readmeFactory;
|
|
32
26
|
lastCustomCooldown;
|
|
33
27
|
constructor(trigger, handler, name, providers, maxAllowedSimultaniousExecutions, condition, stateConstructor, readmeFactory) {
|
|
34
|
-
this.triggers =
|
|
28
|
+
this.triggers = toArray(trigger);
|
|
35
29
|
this.name = name;
|
|
36
30
|
this.cooldownInfoProvider = providers.cooldownProvider;
|
|
37
31
|
this.isActiveProvider = providers.isActiveProvider;
|
|
@@ -51,24 +45,24 @@ class CommandAction {
|
|
|
51
45
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
52
46
|
let lock;
|
|
53
47
|
if (this.maxAllowedSimultaniousExecutions != 0) {
|
|
54
|
-
lock =
|
|
48
|
+
lock = getOrSetIfNotExists(this.ratelimitSemaphores, ctx.chatInfo.id, new Semaphore(this.maxAllowedSimultaniousExecutions));
|
|
55
49
|
await lock.acquire();
|
|
56
50
|
}
|
|
57
51
|
try {
|
|
58
52
|
const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
|
|
59
53
|
const { shouldExecute, matchResults, skipCooldown, reason } = this.triggers
|
|
60
54
|
.map((x) => this.checkIfShouldBeExecuted(ctx, x, state))
|
|
61
|
-
.reduce((acc, curr) => acc.mergeWith(curr),
|
|
55
|
+
.reduce((acc, curr) => acc.mergeWith(curr), CommandTriggerCheckResult.DoNotTrigger('Other'));
|
|
62
56
|
if (!shouldExecute) {
|
|
63
57
|
if (reason == 'OnCooldown') {
|
|
64
58
|
const cooldownMessage = this.cooldownInfoProvider(ctx).message;
|
|
65
59
|
return cooldownMessage
|
|
66
60
|
? [
|
|
67
|
-
new
|
|
61
|
+
new TextMessage(cooldownMessage, ctx.chatInfo, ctx.traceId, this, new ReplyInfo(ctx.messageInfo.id))
|
|
68
62
|
]
|
|
69
|
-
:
|
|
63
|
+
: Noop.NoResponse;
|
|
70
64
|
}
|
|
71
|
-
return
|
|
65
|
+
return Noop.NoResponse;
|
|
72
66
|
}
|
|
73
67
|
ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
|
|
74
68
|
ctx.matchResults = matchResults;
|
|
@@ -78,7 +72,7 @@ class CommandAction {
|
|
|
78
72
|
}
|
|
79
73
|
if (ctx.startCooldown) {
|
|
80
74
|
this.lastCustomCooldown = ctx.customCooldown;
|
|
81
|
-
state.lastExecutedDate = (
|
|
75
|
+
state.lastExecutedDate = moment().valueOf();
|
|
82
76
|
}
|
|
83
77
|
await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
|
|
84
78
|
return ctx.responses;
|
|
@@ -89,41 +83,41 @@ class CommandAction {
|
|
|
89
83
|
}
|
|
90
84
|
checkIfShouldBeExecuted(ctx, trigger, state) {
|
|
91
85
|
if (!this.isActiveProvider(ctx))
|
|
92
|
-
return
|
|
86
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ActionDisabled');
|
|
93
87
|
const chatsBlacklist = this.chatsBlacklistProvider(ctx);
|
|
94
88
|
const chatsWhitelist = this.chatsWhitelistProvider(ctx);
|
|
95
89
|
const isChatInBlacklist = chatsBlacklist.includes(ctx.chatInfo.id);
|
|
96
90
|
const isChatInWhitelist = chatsWhitelist.length == 0 ||
|
|
97
91
|
chatsWhitelist.includes(ctx.chatInfo.id);
|
|
98
92
|
if (isChatInBlacklist || !isChatInWhitelist)
|
|
99
|
-
return
|
|
93
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ChatForbidden');
|
|
100
94
|
const triggerCheckResult = this.checkTrigger(ctx, trigger);
|
|
101
95
|
if (!triggerCheckResult.shouldExecute)
|
|
102
96
|
return triggerCheckResult;
|
|
103
97
|
if (!ctx.userInfo.id)
|
|
104
|
-
return
|
|
98
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserIdMissing');
|
|
105
99
|
const usersWhitelist = this.usersWhitelistProvider(ctx);
|
|
106
100
|
const isUserAllowed = usersWhitelist.length == 0 ||
|
|
107
101
|
usersWhitelist.includes(ctx.userInfo.id);
|
|
108
102
|
if (!isUserAllowed)
|
|
109
|
-
return
|
|
110
|
-
const lastExecutedDate = (
|
|
111
|
-
const cooldownInMilliseconds =
|
|
112
|
-
const onCooldown = (
|
|
103
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserForbidden');
|
|
104
|
+
const lastExecutedDate = moment(state.lastExecutedDate);
|
|
105
|
+
const cooldownInMilliseconds = secondsToMilliseconds(this.lastCustomCooldown ?? this.cooldownInfoProvider(ctx).cooldown);
|
|
106
|
+
const onCooldown = moment().diff(lastExecutedDate) < cooldownInMilliseconds;
|
|
113
107
|
if (onCooldown)
|
|
114
|
-
return
|
|
108
|
+
return CommandTriggerCheckResult.DoNotTrigger('OnCooldown');
|
|
115
109
|
const isCustomConditionMet = this.condition(ctx, state);
|
|
116
110
|
if (!isCustomConditionMet)
|
|
117
|
-
return
|
|
111
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown('CustomConditionNotMet');
|
|
118
112
|
return triggerCheckResult;
|
|
119
113
|
}
|
|
120
114
|
checkTrigger(ctx, trigger) {
|
|
121
|
-
if (trigger ==
|
|
122
|
-
return
|
|
115
|
+
if (trigger == MessageType.Any || trigger == ctx.messageInfo.type)
|
|
116
|
+
return CommandTriggerCheckResult.Trigger();
|
|
123
117
|
if (typeof trigger == 'string')
|
|
124
118
|
return ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase()
|
|
125
|
-
?
|
|
126
|
-
:
|
|
119
|
+
? CommandTriggerCheckResult.Trigger()
|
|
120
|
+
: CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
127
121
|
const matchResults = [];
|
|
128
122
|
trigger.lastIndex = 0;
|
|
129
123
|
const execResult = trigger.exec(ctx.messageInfo.text);
|
|
@@ -140,7 +134,6 @@ class CommandAction {
|
|
|
140
134
|
}
|
|
141
135
|
}
|
|
142
136
|
}
|
|
143
|
-
return new
|
|
137
|
+
return new CommandTriggerCheckResult(matchResults.length > 0, matchResults, false);
|
|
144
138
|
}
|
|
145
139
|
}
|
|
146
|
-
exports.CommandAction = CommandAction;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.InlineQueryAction = void 0;
|
|
4
|
-
const noop_1 = require("../../helpers/noop");
|
|
5
|
-
class InlineQueryAction {
|
|
1
|
+
import { Noop } from '../../helpers/noop';
|
|
2
|
+
export class InlineQueryAction {
|
|
6
3
|
key;
|
|
7
4
|
isActiveProvider;
|
|
8
5
|
handler;
|
|
@@ -19,7 +16,7 @@ class InlineQueryAction {
|
|
|
19
16
|
if (!ctx.isInitialized)
|
|
20
17
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
21
18
|
if (!this.isActiveProvider(ctx))
|
|
22
|
-
return
|
|
19
|
+
return Noop.NoResponse;
|
|
23
20
|
const matchResults = [];
|
|
24
21
|
this.pattern.lastIndex = 0;
|
|
25
22
|
const execResult = this.pattern.exec(ctx.queryText);
|
|
@@ -37,11 +34,10 @@ class InlineQueryAction {
|
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
36
|
if (matchResults.length == 0)
|
|
40
|
-
return
|
|
37
|
+
return Noop.NoResponse;
|
|
41
38
|
ctx.matchResults = matchResults;
|
|
42
39
|
ctx.logger.logWithTraceId(` - Executing [${this.name}]`);
|
|
43
40
|
await this.handler(ctx);
|
|
44
41
|
return ctx.responses;
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
|
-
exports.InlineQueryAction = InlineQueryAction;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const commandTriggerCheckResult_1 = require("../../dtos/commandTriggerCheckResult");
|
|
5
|
-
const noop_1 = require("../../helpers/noop");
|
|
6
|
-
class ReplyCaptureAction {
|
|
1
|
+
import { CommandTriggerCheckResult } from '../../dtos/commandTriggerCheckResult';
|
|
2
|
+
import { Noop } from '../../helpers/noop';
|
|
3
|
+
export class ReplyCaptureAction {
|
|
7
4
|
parentMessageId;
|
|
8
5
|
key;
|
|
9
6
|
handler;
|
|
@@ -23,9 +20,9 @@ class ReplyCaptureAction {
|
|
|
23
20
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
24
21
|
const { shouldExecute, matchResults } = this.triggers
|
|
25
22
|
.map((x) => this.checkIfShouldBeExecuted(ctx, x))
|
|
26
|
-
.reduce((acc, curr) => acc.mergeWith(curr),
|
|
23
|
+
.reduce((acc, curr) => acc.mergeWith(curr), CommandTriggerCheckResult.DoNotTrigger('Other'));
|
|
27
24
|
if (!shouldExecute)
|
|
28
|
-
return
|
|
25
|
+
return Noop.NoResponse;
|
|
29
26
|
ctx.logger.logWithTraceId(` - Executing [${this.key}] in ${ctx.chatInfo.id}`);
|
|
30
27
|
ctx.matchResults = matchResults;
|
|
31
28
|
await this.handler(ctx);
|
|
@@ -33,13 +30,13 @@ class ReplyCaptureAction {
|
|
|
33
30
|
}
|
|
34
31
|
checkIfShouldBeExecuted(ctx, trigger) {
|
|
35
32
|
if (ctx.replyMessageId != this.parentMessageId)
|
|
36
|
-
return
|
|
33
|
+
return CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
37
34
|
if (trigger == ctx.messageInfo.type)
|
|
38
|
-
return
|
|
35
|
+
return CommandTriggerCheckResult.Trigger();
|
|
39
36
|
if (typeof trigger == 'string')
|
|
40
37
|
return ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase()
|
|
41
|
-
?
|
|
42
|
-
:
|
|
38
|
+
? CommandTriggerCheckResult.Trigger()
|
|
39
|
+
: CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
43
40
|
const matchResults = [];
|
|
44
41
|
trigger.lastIndex = 0;
|
|
45
42
|
const execResult = trigger.exec(ctx.messageInfo.text);
|
|
@@ -56,7 +53,6 @@ class ReplyCaptureAction {
|
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
return new
|
|
56
|
+
return new CommandTriggerCheckResult(matchResults.length > 0, matchResults, false);
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
|
-
exports.ReplyCaptureAction = ReplyCaptureAction;
|