chz-telegram-bot 0.3.22 → 0.3.23
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/replyCaptureAction.d.ts +2 -2
- package/dist/entities/actions/replyCaptureAction.d.ts.map +1 -1
- package/dist/entities/context/replyContext.d.ts +9 -6
- package/dist/entities/context/replyContext.d.ts.map +1 -1
- package/dist/entities/context/replyContext.js +21 -6
- package/dist/types/capture.d.ts +2 -2
- package/dist/types/capture.d.ts.map +1 -1
- package/entities/actions/replyCaptureAction.ts +2 -2
- package/entities/context/replyContext.ts +36 -6
- package/package.json +1 -1
- package/types/capture.ts +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IActionState } from '../../types/actionState';
|
|
2
2
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
3
|
-
import { ActionKey, IAction
|
|
3
|
+
import { ActionKey, IAction } from '../../types/action';
|
|
4
4
|
import { ReplyContextInternal } from '../context/replyContext';
|
|
5
5
|
export declare class ReplyCaptureAction<TParentActionState extends IActionState> implements IAction {
|
|
6
6
|
readonly parentMessageId: number;
|
|
@@ -8,7 +8,7 @@ export declare class ReplyCaptureAction<TParentActionState extends IActionState>
|
|
|
8
8
|
readonly handler: (replyContext: ReplyContextInternal<TParentActionState>) => Promise<void>;
|
|
9
9
|
readonly triggers: CommandTrigger[];
|
|
10
10
|
readonly abortController: AbortController;
|
|
11
|
-
constructor(parentMessageId: number, parentAction:
|
|
11
|
+
constructor(parentMessageId: number, parentAction: IAction, handler: (replyContext: ReplyContextInternal<TParentActionState>) => Promise<void>, triggers: CommandTrigger[], abortController: AbortController);
|
|
12
12
|
exec(ctx: ReplyContextInternal<TParentActionState>): Promise<import("../../types/response").BotResponse[]>;
|
|
13
13
|
private checkIfShouldBeExecuted;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replyCaptureAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/replyCaptureAction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"replyCaptureAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/replyCaptureAction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,qBAAa,kBAAkB,CAAC,kBAAkB,SAAS,YAAY,CACnE,YAAW,OAAO;IAElB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,CACd,YAAY,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,KACrD,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;gBAGtC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,OAAO,EACrB,OAAO,EAAE,CACL,YAAY,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,KACrD,OAAO,CAAC,IAAI,CAAC,EAClB,QAAQ,EAAE,cAAc,EAAE,EAC1B,eAAe,EAAE,eAAe;IAY9B,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,kBAAkB,CAAC;IAyBxD,OAAO,CAAC,uBAAuB;CA4ClC"}
|
|
@@ -5,8 +5,11 @@ import { ReplyCaptureAction } from '../actions/replyCaptureAction';
|
|
|
5
5
|
import { BaseContextInternal, BaseContextPropertiesToOmit } from './baseContext';
|
|
6
6
|
import { UserInfo } from '../../dtos/userInfo';
|
|
7
7
|
import { MessageInfo } from '../../dtos/messageInfo';
|
|
8
|
+
import { ICaptureController } from '../../types/capture';
|
|
9
|
+
import { IReplyResponse } from '../../types/response';
|
|
8
10
|
export type ReplyContext<TActionState extends IActionState> = Omit<ReplyContextInternal<TActionState>, BaseContextPropertiesToOmit | 'messageId' | 'startCooldown' | 'customCooldown'>;
|
|
9
11
|
export declare class ReplyContextInternal<TParentActionState extends IActionState> extends BaseContextInternal<ReplyCaptureAction<TParentActionState>> {
|
|
12
|
+
protected createCaptureController(response: IReplyResponse): ICaptureController;
|
|
10
13
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
11
14
|
matchResults: RegExpExecArray[];
|
|
12
15
|
/** Id of a message that triggered this action. */
|
|
@@ -41,21 +44,21 @@ export declare class ReplyContextInternal<TParentActionState extends IActionStat
|
|
|
41
44
|
* @param text Message contents.
|
|
42
45
|
* @param options Message sending option.
|
|
43
46
|
*/
|
|
44
|
-
withText: (text: string, quote?: string, options?: TextMessageSendingOptions) =>
|
|
47
|
+
withText: (text: string, quote?: string, options?: TextMessageSendingOptions) => ICaptureController;
|
|
45
48
|
/**
|
|
46
49
|
* Reply with image message to message that triggered this action after action execution is finished.
|
|
47
50
|
* If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
|
|
48
51
|
* @param text Message contents.
|
|
49
52
|
* @param options Message sending option.
|
|
50
53
|
*/
|
|
51
|
-
withImage: (name: string, quote?: string, options?: MessageSendingOptions) =>
|
|
54
|
+
withImage: (name: string, quote?: string, options?: MessageSendingOptions) => ICaptureController;
|
|
52
55
|
/**
|
|
53
56
|
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
54
57
|
* If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
|
|
55
58
|
* @param text Message contents.
|
|
56
59
|
* @param options Message sending option.
|
|
57
60
|
*/
|
|
58
|
-
withVideo: (name: string, quote?: string, options?: MessageSendingOptions) =>
|
|
61
|
+
withVideo: (name: string, quote?: string, options?: MessageSendingOptions) => ICaptureController;
|
|
59
62
|
};
|
|
60
63
|
/**
|
|
61
64
|
* Reply with text message to message that triggered this action after action execution is finished.
|
|
@@ -63,21 +66,21 @@ export declare class ReplyContextInternal<TParentActionState extends IActionStat
|
|
|
63
66
|
* @param text Message contents.
|
|
64
67
|
* @param options Message sending option.
|
|
65
68
|
*/
|
|
66
|
-
withText: (text: string, options?: TextMessageSendingOptions) =>
|
|
69
|
+
withText: (text: string, options?: TextMessageSendingOptions) => ICaptureController;
|
|
67
70
|
/**
|
|
68
71
|
* Reply with image message to message that triggered this action after action execution is finished.
|
|
69
72
|
* If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
|
|
70
73
|
* @param text Message contents.
|
|
71
74
|
* @param options Message sending option.
|
|
72
75
|
*/
|
|
73
|
-
withImage: (name: string, options?: MessageSendingOptions) =>
|
|
76
|
+
withImage: (name: string, options?: MessageSendingOptions) => ICaptureController;
|
|
74
77
|
/**
|
|
75
78
|
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
76
79
|
* If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
|
|
77
80
|
* @param text Message contents.
|
|
78
81
|
* @param options Message sending option.
|
|
79
82
|
*/
|
|
80
|
-
withVideo: (name: string, options?: MessageSendingOptions) =>
|
|
83
|
+
withVideo: (name: string, options?: MessageSendingOptions) => ICaptureController;
|
|
81
84
|
/**
|
|
82
85
|
* React to the message that triggered this action after action execution is finished.
|
|
83
86
|
* If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../entities/context/replyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACH,yBAAyB,EACzB,qBAAqB,EACxB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EACH,mBAAmB,EACnB,2BAA2B,EAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../entities/context/replyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACH,yBAAyB,EACzB,qBAAqB,EACxB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EACH,mBAAmB,EACnB,2BAA2B,EAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,MAAM,YAAY,CAAC,YAAY,SAAS,YAAY,IAAI,IAAI,CAC9D,oBAAoB,CAAC,YAAY,CAAC,EAChC,2BAA2B,GAC3B,WAAW,GACX,eAAe,GACf,gBAAgB,CACrB,CAAC;AAEF,qBAAa,oBAAoB,CAC7B,kBAAkB,SAAS,YAAY,CACzC,SAAQ,mBAAmB,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IACjE,SAAS,CAAC,uBAAuB,CAC7B,QAAQ,EAAE,cAAc,GACzB,kBAAkB;IAmBrB,4HAA4H;IAC5H,YAAY,EAAG,eAAe,EAAE,CAAC;IACjC,kDAAkD;IAClD,cAAc,EAAG,MAAM,GAAG,SAAS,CAAC;IACpC,4DAA4D;IAC5D,QAAQ,EAAG,QAAQ,CAAC;IACpB,+DAA+D;IAC/D,WAAW,EAAG,WAAW,CAAC;IAC1B,6BAA6B;IAC7B,OAAO,EAAG,aAAa,CAAC;IAExB,aAAa,UAAS;IAEtB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,cAAc;IAqBtB;;OAEG;IACH,WAAW;IAIX;;OAEG;IACH,KAAK;QACD;;;WAGG;;YAEC;;;;;eAKG;6BAEO,MAAM,UACJ,MAAM,YACJ,yBAAyB;YAIvC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;YAKnC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;;QAMvC;;;;;WAKG;yBACc,MAAM,YAAY,yBAAyB;QAG5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAIzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAIzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
|
|
@@ -9,6 +9,18 @@ const videoMessage_1 = require("../../dtos/responses/videoMessage");
|
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const baseContext_1 = require("./baseContext");
|
|
11
11
|
class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
12
|
+
createCaptureController(response) {
|
|
13
|
+
return {
|
|
14
|
+
captureReplies: (trigger, handler, abortController) => {
|
|
15
|
+
response.captures.push({
|
|
16
|
+
trigger,
|
|
17
|
+
handler,
|
|
18
|
+
abortController,
|
|
19
|
+
action: this.action
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
12
24
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
13
25
|
matchResults;
|
|
14
26
|
/** Id of a message that triggered this action. */
|
|
@@ -31,16 +43,19 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
31
43
|
const quotedPart = this.getQuotePart(quote);
|
|
32
44
|
const response = new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
33
45
|
this.responses.push(response);
|
|
46
|
+
return this.createCaptureController(response);
|
|
34
47
|
}
|
|
35
48
|
replyWithImage(name, quote, options) {
|
|
36
49
|
const quotedPart = this.getQuotePart(quote);
|
|
37
50
|
const response = new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
38
51
|
this.responses.push(response);
|
|
52
|
+
return this.createCaptureController(response);
|
|
39
53
|
}
|
|
40
54
|
replyWithVideo(name, quote, options) {
|
|
41
55
|
const quotedPart = this.getQuotePart(quote);
|
|
42
56
|
const response = new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
43
57
|
this.responses.push(response);
|
|
58
|
+
return this.createCaptureController(response);
|
|
44
59
|
}
|
|
45
60
|
/**
|
|
46
61
|
* Stops capturing replies and removes this action
|
|
@@ -64,7 +79,7 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
64
79
|
* @param options Message sending option.
|
|
65
80
|
*/
|
|
66
81
|
withText: (text, quote, options) => {
|
|
67
|
-
this.replyWithText(text, quote ?? true, options);
|
|
82
|
+
return this.replyWithText(text, quote ?? true, options);
|
|
68
83
|
},
|
|
69
84
|
/**
|
|
70
85
|
* Reply with image message to message that triggered this action after action execution is finished.
|
|
@@ -73,7 +88,7 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
73
88
|
* @param options Message sending option.
|
|
74
89
|
*/
|
|
75
90
|
withImage: (name, quote, options) => {
|
|
76
|
-
this.replyWithImage(name, quote ?? true, options);
|
|
91
|
+
return this.replyWithImage(name, quote ?? true, options);
|
|
77
92
|
},
|
|
78
93
|
/**
|
|
79
94
|
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
@@ -82,7 +97,7 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
82
97
|
* @param options Message sending option.
|
|
83
98
|
*/
|
|
84
99
|
withVideo: (name, quote, options) => {
|
|
85
|
-
this.replyWithVideo(name, quote ?? true, options);
|
|
100
|
+
return this.replyWithVideo(name, quote ?? true, options);
|
|
86
101
|
}
|
|
87
102
|
},
|
|
88
103
|
/**
|
|
@@ -92,7 +107,7 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
92
107
|
* @param options Message sending option.
|
|
93
108
|
*/
|
|
94
109
|
withText: (text, options) => {
|
|
95
|
-
this.replyWithText(text, false, options);
|
|
110
|
+
return this.replyWithText(text, false, options);
|
|
96
111
|
},
|
|
97
112
|
/**
|
|
98
113
|
* Reply with image message to message that triggered this action after action execution is finished.
|
|
@@ -101,7 +116,7 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
101
116
|
* @param options Message sending option.
|
|
102
117
|
*/
|
|
103
118
|
withImage: (name, options) => {
|
|
104
|
-
this.replyWithImage(name, false, options);
|
|
119
|
+
return this.replyWithImage(name, false, options);
|
|
105
120
|
},
|
|
106
121
|
/**
|
|
107
122
|
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
@@ -110,7 +125,7 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
|
110
125
|
* @param options Message sending option.
|
|
111
126
|
*/
|
|
112
127
|
withVideo: (name, options) => {
|
|
113
|
-
this.replyWithVideo(name, false, options);
|
|
128
|
+
return this.replyWithVideo(name, false, options);
|
|
114
129
|
},
|
|
115
130
|
/**
|
|
116
131
|
* React to the message that triggered this action after action execution is finished.
|
package/dist/types/capture.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReplyContext, ReplyContextInternal } from '../entities/context/replyContext';
|
|
2
2
|
import { IActionState } from './actionState';
|
|
3
3
|
import { CommandTrigger } from './commandTrigger';
|
|
4
|
-
import {
|
|
4
|
+
import { IAction } from './action';
|
|
5
5
|
export interface ICaptureController {
|
|
6
6
|
captureReplies: <TParentActionState extends IActionState>(
|
|
7
7
|
/**
|
|
@@ -19,6 +19,6 @@ export interface IReplyCapture {
|
|
|
19
19
|
trigger: CommandTrigger[];
|
|
20
20
|
handler: (replyContext: ReplyContextInternal<IActionState>) => Promise<void>;
|
|
21
21
|
abortController: AbortController;
|
|
22
|
-
action:
|
|
22
|
+
action: IAction;
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=capture.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../types/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,oBAAoB,EACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../types/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,oBAAoB,EACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,MAAM,WAAW,kBAAkB;IAC/B,cAAc,EAAE,CAAC,kBAAkB,SAAS,YAAY;IACpD;;;;OAIG;IACH,OAAO,EAAE,cAAc,EAAE;IACzB,8CAA8C;IAC9C,OAAO,EAAE,CACL,YAAY,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAC7C,OAAO,CAAC,IAAI,CAAC;IAClB,mDAAmD;IACnD,eAAe,EAAE,eAAe,KAC/B,IAAI,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,OAAO,EAAE,CACL,YAAY,EAAE,oBAAoB,CAAC,YAAY,CAAC,KAC/C,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,MAAM,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -2,7 +2,7 @@ import { CommandTriggerCheckResult } from '../../dtos/commandTriggerCheckResult'
|
|
|
2
2
|
import { Noop } from '../../helpers/noop';
|
|
3
3
|
import { IActionState } from '../../types/actionState';
|
|
4
4
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
5
|
-
import { ActionKey, IAction
|
|
5
|
+
import { ActionKey, IAction } from '../../types/action';
|
|
6
6
|
import { ReplyContextInternal } from '../context/replyContext';
|
|
7
7
|
|
|
8
8
|
export class ReplyCaptureAction<TParentActionState extends IActionState>
|
|
@@ -18,7 +18,7 @@ export class ReplyCaptureAction<TParentActionState extends IActionState>
|
|
|
18
18
|
|
|
19
19
|
constructor(
|
|
20
20
|
parentMessageId: number,
|
|
21
|
-
parentAction:
|
|
21
|
+
parentAction: IAction,
|
|
22
22
|
handler: (
|
|
23
23
|
replyContext: ReplyContextInternal<TParentActionState>
|
|
24
24
|
) => Promise<void>,
|
|
@@ -17,6 +17,9 @@ import {
|
|
|
17
17
|
} from './baseContext';
|
|
18
18
|
import { UserInfo } from '../../dtos/userInfo';
|
|
19
19
|
import { MessageInfo } from '../../dtos/messageInfo';
|
|
20
|
+
import { ICaptureController } from '../../types/capture';
|
|
21
|
+
import { CommandTrigger } from '../../types/commandTrigger';
|
|
22
|
+
import { IReplyResponse } from '../../types/response';
|
|
20
23
|
|
|
21
24
|
export type ReplyContext<TActionState extends IActionState> = Omit<
|
|
22
25
|
ReplyContextInternal<TActionState>,
|
|
@@ -29,6 +32,27 @@ export type ReplyContext<TActionState extends IActionState> = Omit<
|
|
|
29
32
|
export class ReplyContextInternal<
|
|
30
33
|
TParentActionState extends IActionState
|
|
31
34
|
> extends BaseContextInternal<ReplyCaptureAction<TParentActionState>> {
|
|
35
|
+
protected createCaptureController(
|
|
36
|
+
response: IReplyResponse
|
|
37
|
+
): ICaptureController {
|
|
38
|
+
return {
|
|
39
|
+
captureReplies: (
|
|
40
|
+
trigger: CommandTrigger[],
|
|
41
|
+
handler: (
|
|
42
|
+
replyContext: ReplyContext<TParentActionState>
|
|
43
|
+
) => Promise<void>,
|
|
44
|
+
abortController: AbortController
|
|
45
|
+
) => {
|
|
46
|
+
response.captures.push({
|
|
47
|
+
trigger,
|
|
48
|
+
handler,
|
|
49
|
+
abortController,
|
|
50
|
+
action: this.action
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
32
56
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
33
57
|
matchResults!: RegExpExecArray[];
|
|
34
58
|
/** Id of a message that triggered this action. */
|
|
@@ -67,6 +91,8 @@ export class ReplyContextInternal<
|
|
|
67
91
|
);
|
|
68
92
|
|
|
69
93
|
this.responses.push(response);
|
|
94
|
+
|
|
95
|
+
return this.createCaptureController(response);
|
|
70
96
|
}
|
|
71
97
|
|
|
72
98
|
private replyWithImage(
|
|
@@ -86,6 +112,8 @@ export class ReplyContextInternal<
|
|
|
86
112
|
);
|
|
87
113
|
|
|
88
114
|
this.responses.push(response);
|
|
115
|
+
|
|
116
|
+
return this.createCaptureController(response);
|
|
89
117
|
}
|
|
90
118
|
|
|
91
119
|
private replyWithVideo(
|
|
@@ -105,6 +133,8 @@ export class ReplyContextInternal<
|
|
|
105
133
|
);
|
|
106
134
|
|
|
107
135
|
this.responses.push(response);
|
|
136
|
+
|
|
137
|
+
return this.createCaptureController(response);
|
|
108
138
|
}
|
|
109
139
|
|
|
110
140
|
/**
|
|
@@ -134,7 +164,7 @@ export class ReplyContextInternal<
|
|
|
134
164
|
quote?: string,
|
|
135
165
|
options?: TextMessageSendingOptions
|
|
136
166
|
) => {
|
|
137
|
-
this.replyWithText(text, quote ?? true, options);
|
|
167
|
+
return this.replyWithText(text, quote ?? true, options);
|
|
138
168
|
},
|
|
139
169
|
/**
|
|
140
170
|
* Reply with image message to message that triggered this action after action execution is finished.
|
|
@@ -147,7 +177,7 @@ export class ReplyContextInternal<
|
|
|
147
177
|
quote?: string,
|
|
148
178
|
options?: MessageSendingOptions
|
|
149
179
|
) => {
|
|
150
|
-
this.replyWithImage(name, quote ?? true, options);
|
|
180
|
+
return this.replyWithImage(name, quote ?? true, options);
|
|
151
181
|
},
|
|
152
182
|
|
|
153
183
|
/**
|
|
@@ -161,7 +191,7 @@ export class ReplyContextInternal<
|
|
|
161
191
|
quote?: string,
|
|
162
192
|
options?: MessageSendingOptions
|
|
163
193
|
) => {
|
|
164
|
-
this.replyWithVideo(name, quote ?? true, options);
|
|
194
|
+
return this.replyWithVideo(name, quote ?? true, options);
|
|
165
195
|
}
|
|
166
196
|
},
|
|
167
197
|
|
|
@@ -172,7 +202,7 @@ export class ReplyContextInternal<
|
|
|
172
202
|
* @param options Message sending option.
|
|
173
203
|
*/
|
|
174
204
|
withText: (text: string, options?: TextMessageSendingOptions) => {
|
|
175
|
-
this.replyWithText(text, false, options);
|
|
205
|
+
return this.replyWithText(text, false, options);
|
|
176
206
|
},
|
|
177
207
|
/**
|
|
178
208
|
* Reply with image message to message that triggered this action after action execution is finished.
|
|
@@ -181,7 +211,7 @@ export class ReplyContextInternal<
|
|
|
181
211
|
* @param options Message sending option.
|
|
182
212
|
*/
|
|
183
213
|
withImage: (name: string, options?: MessageSendingOptions) => {
|
|
184
|
-
this.replyWithImage(name, false, options);
|
|
214
|
+
return this.replyWithImage(name, false, options);
|
|
185
215
|
},
|
|
186
216
|
|
|
187
217
|
/**
|
|
@@ -191,7 +221,7 @@ export class ReplyContextInternal<
|
|
|
191
221
|
* @param options Message sending option.
|
|
192
222
|
*/
|
|
193
223
|
withVideo: (name: string, options?: MessageSendingOptions) => {
|
|
194
|
-
this.replyWithVideo(name, false, options);
|
|
224
|
+
return this.replyWithVideo(name, false, options);
|
|
195
225
|
},
|
|
196
226
|
|
|
197
227
|
/**
|
package/package.json
CHANGED
package/types/capture.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from '../entities/context/replyContext';
|
|
5
5
|
import { IActionState } from './actionState';
|
|
6
6
|
import { CommandTrigger } from './commandTrigger';
|
|
7
|
-
import {
|
|
7
|
+
import { IAction } from './action';
|
|
8
8
|
|
|
9
9
|
export interface ICaptureController {
|
|
10
10
|
captureReplies: <TParentActionState extends IActionState>(
|
|
@@ -29,5 +29,5 @@ export interface IReplyCapture {
|
|
|
29
29
|
replyContext: ReplyContextInternal<IActionState>
|
|
30
30
|
) => Promise<void>;
|
|
31
31
|
abortController: AbortController;
|
|
32
|
-
action:
|
|
32
|
+
action: IAction;
|
|
33
33
|
}
|