chz-telegram-bot 0.3.12 → 0.3.14
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/README.md +92 -73
- package/chz-telegram-bot-0.3.14.tgz +0 -0
- package/dist/dtos/commandTriggerCheckResult.d.ts +15 -4
- package/dist/dtos/commandTriggerCheckResult.d.ts.map +1 -1
- package/dist/dtos/commandTriggerCheckResult.js +17 -7
- package/dist/dtos/cooldownInfo.d.ts +7 -0
- package/dist/dtos/cooldownInfo.d.ts.map +1 -0
- package/dist/dtos/cooldownInfo.js +12 -0
- package/dist/entities/actions/commandAction.d.ts +5 -3
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +27 -15
- package/dist/entities/actions/replyCaptureAction.d.ts.map +1 -1
- package/dist/entities/actions/replyCaptureAction.js +5 -5
- package/dist/entities/context/messageContext.d.ts +6 -1
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +7 -0
- package/dist/entities/context/replyContext.d.ts +3 -1
- package/dist/entities/context/replyContext.d.ts.map +1 -1
- package/dist/entities/context/replyContext.js +2 -0
- package/dist/helpers/builders/commandActionBuilder.d.ts +5 -0
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/commandActionBuilder.js +10 -1
- package/dist/services/actionProcessingService.d.ts.map +1 -1
- package/dist/services/actionProcessingService.js +1 -1
- package/dist/services/actionProcessors/commandActionProcessor.d.ts +3 -1
- package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/commandActionProcessor.js +6 -1
- package/dtos/commandTriggerCheckResult.ts +22 -7
- package/dtos/cooldownInfo.ts +5 -0
- package/entities/actions/commandAction.ts +53 -21
- package/entities/actions/replyCaptureAction.ts +10 -5
- package/entities/context/messageContext.ts +11 -1
- package/entities/context/replyContext.ts +3 -1
- package/helpers/builders/commandActionBuilder.ts +12 -1
- package/package.json +1 -1
- package/services/actionProcessingService.ts +2 -1
- package/services/actionProcessors/commandActionProcessor.ts +8 -1
package/README.md
CHANGED
|
@@ -26,13 +26,13 @@ botFramework is a TypeScript library that provides a structured approach to buil
|
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
# Using npm
|
|
29
|
-
npm install chz-bot
|
|
29
|
+
npm install chz-telegram-bot
|
|
30
30
|
|
|
31
31
|
# Using yarn
|
|
32
|
-
yarn add chz-bot
|
|
32
|
+
yarn add chz-telegram-bot
|
|
33
33
|
|
|
34
34
|
# Using bun
|
|
35
|
-
bun add chz-bot
|
|
35
|
+
bun add chz-telegram-bot
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
## Quick Start
|
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
startBot,
|
|
60
60
|
stopBots,
|
|
61
61
|
CommandActionBuilder,
|
|
62
|
+
MessageType,
|
|
62
63
|
Seconds
|
|
63
64
|
} from 'chz-telegram-bot';
|
|
64
65
|
|
|
@@ -66,31 +67,52 @@ import {
|
|
|
66
67
|
const commands = [
|
|
67
68
|
new CommandActionBuilder('HelloWorld')
|
|
68
69
|
.on('/hello')
|
|
69
|
-
.do(
|
|
70
|
-
ctx.
|
|
70
|
+
.do((ctx) => {
|
|
71
|
+
ctx.reply.withText('Hello, world!');
|
|
72
|
+
})
|
|
73
|
+
.build(),
|
|
74
|
+
|
|
75
|
+
new CommandActionBuilder('Welcome')
|
|
76
|
+
.on(MessageType.NewChatMember)
|
|
77
|
+
.do((ctx) => {
|
|
78
|
+
ctx.reply, withText('Welcome to the group!');
|
|
71
79
|
})
|
|
72
80
|
.build()
|
|
73
81
|
];
|
|
74
82
|
|
|
75
|
-
// Define scheduled actions (if needed)
|
|
76
|
-
const scheduled = [];
|
|
77
|
-
|
|
78
83
|
async function main() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
try {
|
|
85
|
+
// Start the bot
|
|
86
|
+
const bot = await startBot({
|
|
87
|
+
name: 'MyFirstBot',
|
|
88
|
+
tokenFilePath: './token.txt',
|
|
89
|
+
commands,
|
|
90
|
+
scheduled: [], // Add scheduled actions if needed
|
|
91
|
+
chats: {
|
|
92
|
+
MyChat: -1001234567890 // Replace with your chat ID
|
|
93
|
+
},
|
|
94
|
+
scheduledPeriod: (60 * 5) as Seconds,
|
|
95
|
+
// Optional settings
|
|
96
|
+
storagePath: './data',
|
|
97
|
+
verboseLoggingForIncomingMessage: false
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Proper cleanup on shutdown
|
|
101
|
+
const cleanup = async (signal: string) => {
|
|
102
|
+
console.log(`Received ${signal}, cleaning up...`);
|
|
103
|
+
await stopBots(signal);
|
|
104
|
+
process.exit(0);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
process.on('SIGINT', () => cleanup('SIGINT'));
|
|
108
|
+
process.on('SIGTERM', () => cleanup('SIGTERM'));
|
|
109
|
+
|
|
110
|
+
console.log('Bot started successfully!');
|
|
111
|
+
return bot;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('Failed to start bot:', error);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
94
116
|
}
|
|
95
117
|
|
|
96
118
|
main().catch(console.error);
|
|
@@ -113,21 +135,21 @@ import { CommandActionBuilder } from 'chz-telegram-bot';
|
|
|
113
135
|
|
|
114
136
|
const myCommand = new CommandActionBuilder('StartCommand')
|
|
115
137
|
.on('/start')
|
|
116
|
-
.do(
|
|
117
|
-
ctx.
|
|
138
|
+
.do((ctx) => {
|
|
139
|
+
ctx.reply.withText('Welcome to my bot!');
|
|
118
140
|
})
|
|
119
141
|
.build();
|
|
120
142
|
```
|
|
121
143
|
|
|
122
|
-
Message types
|
|
144
|
+
Message types can also trigger commands:
|
|
123
145
|
|
|
124
146
|
```typescript
|
|
125
147
|
import { CommandActionBuilder, MessageType } from 'chz-telegram-bot';
|
|
126
148
|
|
|
127
149
|
const myCommand = new CommandActionBuilder('WelcomeMessage')
|
|
128
150
|
.on(MessageType.NewChatMember)
|
|
129
|
-
.do(
|
|
130
|
-
ctx.
|
|
151
|
+
.do((ctx) => {
|
|
152
|
+
ctx.reply.withText('Welcome to my group chat!');
|
|
131
153
|
})
|
|
132
154
|
.build();
|
|
133
155
|
```
|
|
@@ -141,38 +163,38 @@ import { ScheduledActionBuilder, Hours } from 'chz-telegram-bot';
|
|
|
141
163
|
|
|
142
164
|
const dailyNotification = new ScheduledActionBuilder('GM')
|
|
143
165
|
.runAt(9 as Hours) // Run at 9 AM
|
|
144
|
-
.do(
|
|
145
|
-
ctx.
|
|
166
|
+
.do((ctx) => {
|
|
167
|
+
ctx.send.text('Good morning!');
|
|
146
168
|
})
|
|
147
169
|
.build();
|
|
148
170
|
```
|
|
149
171
|
|
|
150
172
|
### Replies and message sending
|
|
151
173
|
|
|
152
|
-
Depending on
|
|
174
|
+
Depending on the type of action, you will have access to the following interaction options:
|
|
153
175
|
|
|
154
|
-
| Method
|
|
155
|
-
|
|
|
156
|
-
| `
|
|
157
|
-
| `
|
|
158
|
-
| `
|
|
159
|
-
| `unpinMessage`
|
|
160
|
-
| `wait`
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
164
|
-
| `
|
|
176
|
+
| Method | Action type | Description |
|
|
177
|
+
| -------------------- | ----------- | ------------------------------------------------------------ |
|
|
178
|
+
| `send.text` | Both | Send text to chat as a standalone message |
|
|
179
|
+
| `send.image` | Both | Send image to chat as a standalone message |
|
|
180
|
+
| `send.video` | Both | Send video/gif to chat as a standalone message |
|
|
181
|
+
| `unpinMessage` | Both | Unpins message by its ID |
|
|
182
|
+
| `wait` | Both | Delays next replies from this action by given amount of ms |
|
|
183
|
+
| `reply.withText` | Command | Replies with text to a message that triggered an action |
|
|
184
|
+
| `reply.withImage` | Command | Replies with image to a message that triggered an action |
|
|
185
|
+
| `reply.withVideo` | Command | Replies with video/gif to a message that triggered an action |
|
|
186
|
+
| `reply.withReaction` | Command | Sets an emoji reaction to a message that triggered an action |
|
|
165
187
|
|
|
166
|
-
Keep in mind that reply sending is deferred until action execution
|
|
167
|
-
|
|
188
|
+
Keep in mind that reply sending is deferred until action execution finishes and will be done in order of calling in the action handler.
|
|
189
|
+
Example:
|
|
168
190
|
|
|
169
191
|
```typescript
|
|
170
|
-
ctx.
|
|
192
|
+
ctx.send.text('Message 1');
|
|
171
193
|
ctx.wait(5000 as Millisecond);
|
|
172
|
-
ctx.
|
|
194
|
+
ctx.send.text('Message 2');
|
|
173
195
|
```
|
|
174
196
|
|
|
175
|
-
This will result in `Message 1`
|
|
197
|
+
This will result in `Message 1` being sent, followed by `Message 2` after a 5 second delay.
|
|
176
198
|
|
|
177
199
|
## Configuration Options
|
|
178
200
|
|
|
@@ -182,27 +204,19 @@ When starting a bot, you can provide the following configuration:
|
|
|
182
204
|
| ----------------- | ------------------------ | --------------------------- | ----------------------------------------------------------------------------------------- |
|
|
183
205
|
| `name` | `string` | Yes | Bot name used in logging |
|
|
184
206
|
| `tokenFilePath` | `string` | Yes | Path to file containing Telegram Bot token |
|
|
185
|
-
| `
|
|
207
|
+
| `commands` | `CommandAction[] ` | Yes (can be empty) | Collection of command actions |
|
|
208
|
+
| `scheduled` | `ScheduledAction[]` | Yes (can be empty) | Collection of scheduled actions |
|
|
186
209
|
| `chats` | `Record<string, number>` | Yes | Object containing chat name-id pairs. Used for logging and execution of scheduled action. |
|
|
187
210
|
| `storagePath` | `string` | No | Custom storage path for default JsonFileStorage client |
|
|
188
211
|
| `scheduledPeriod` | `Seconds` | No (will default to 1 hour) | Period between scheduled action executions |
|
|
189
212
|
| `services` | | No | Custom services to be used instead of default ones |
|
|
190
213
|
|
|
191
|
-
Actions object should have following structure:
|
|
192
|
-
|
|
193
|
-
| Option | Type | Required | Description |
|
|
194
|
-
| --------------- | --------------------- | ------------------ | ---------------------------------- |
|
|
195
|
-
| `commands` | `CommandAction[] ` | Yes (can be empty) | Collection of command actions |
|
|
196
|
-
| `scheduled` | `ScheduledAction[]` | Yes (can be empty) | Collection of scheduled actions |
|
|
197
|
-
| `inlineQueries` | `InlineQueryAction[]` | Yes (can be empty) | Collection of inline query actions |
|
|
198
|
-
|
|
199
214
|
Services object should have following structure:
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
|
203
|
-
| `
|
|
204
|
-
| `
|
|
205
|
-
| `scheduler` | `IScheduler` | No (will default to `NodeTimeoutScheduler`) | Scheduler used to scheduled action |
|
|
215
|
+
| Option | Type | Required | Description |
|
|
216
|
+
|------------------|--------------------------|----------|---------------------------------------------------------------|
|
|
217
|
+
| `storageClient` | `IStorageClient` | No (will default to `JsonFileStorage`) | Persistance state provide |
|
|
218
|
+
| `logger` | `ILogger` | No (will default to `JsonLogger`) | Logger service |
|
|
219
|
+
| `scheduler` | `IScheduler` | No (will default to `NodeTimeoutScheduler`) | Scheduler used to scheduled action|
|
|
206
220
|
|
|
207
221
|
## Advanced Usage
|
|
208
222
|
|
|
@@ -224,7 +238,7 @@ const counterCommand = new CommandActionBuilderWithState<MyCustomState>(
|
|
|
224
238
|
.on('/count')
|
|
225
239
|
.do(async (ctx, state) => {
|
|
226
240
|
state.counter++;
|
|
227
|
-
ctx.
|
|
241
|
+
ctx.reply.withText(`Count: ${state.counter}`);
|
|
228
242
|
})
|
|
229
243
|
.build();
|
|
230
244
|
```
|
|
@@ -239,15 +253,20 @@ The framework provides support for handling inline queries with type-safe builde
|
|
|
239
253
|
import { InlineQueryActionBuilder } from 'chz-telegram-bot';
|
|
240
254
|
|
|
241
255
|
const searchCommand = new InlineQueryActionBuilder('Search')
|
|
242
|
-
.do(
|
|
256
|
+
.do((ctx) => {
|
|
243
257
|
const query = ctx.queryText;
|
|
244
258
|
// Process the query and return inline results
|
|
245
|
-
ctx.showInlineQueryResult(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
259
|
+
ctx.showInlineQueryResult([
|
|
260
|
+
{
|
|
261
|
+
id: '1',
|
|
262
|
+
type: 'article',
|
|
263
|
+
title: `Search results for: ${query}`,
|
|
264
|
+
description: 'Click to send',
|
|
265
|
+
input_message_content: {
|
|
266
|
+
message_text: `Search result for: ${query}`
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
]);
|
|
251
270
|
})
|
|
252
271
|
.build();
|
|
253
272
|
```
|
|
@@ -257,9 +276,9 @@ const searchCommand = new InlineQueryActionBuilder('Search')
|
|
|
257
276
|
The framework includes a response processing queue that ensures reliable message delivery and proper ordering of responses:
|
|
258
277
|
|
|
259
278
|
```typescript
|
|
260
|
-
ctx.
|
|
261
|
-
ctx.
|
|
262
|
-
ctx.
|
|
279
|
+
await ctx.send.text('First message');
|
|
280
|
+
await ctx.send.image('image');
|
|
281
|
+
await ctx.reply.withReaction('👍');
|
|
263
282
|
```
|
|
264
283
|
|
|
265
284
|
All responses are queued and processed in order, ensuring proper sequencing of messages and reactions.
|
|
Binary file
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
declare const _SkipTriggerReasonsObject: {
|
|
2
|
+
readonly UserIdMissing: "UserIdMissing";
|
|
3
|
+
readonly UserForbidden: "UserForbidden";
|
|
4
|
+
readonly OnCooldown: "OnCooldown";
|
|
5
|
+
readonly CustomConditionNotMet: "CustomConditionNotMet";
|
|
6
|
+
readonly TriggerNotSatisfied: "TriggerNotSatisfied";
|
|
7
|
+
readonly Other: "Other";
|
|
8
|
+
};
|
|
9
|
+
export type SkipTriggerReasons = keyof typeof _SkipTriggerReasonsObject;
|
|
1
10
|
export declare class CommandTriggerCheckResult {
|
|
2
|
-
static
|
|
3
|
-
static
|
|
4
|
-
static
|
|
11
|
+
static DontTriggerAndSkipCooldown(reason: SkipTriggerReasons): CommandTriggerCheckResult;
|
|
12
|
+
static DoNotTrigger(reason: SkipTriggerReasons): CommandTriggerCheckResult;
|
|
13
|
+
static Trigger(): CommandTriggerCheckResult;
|
|
5
14
|
readonly shouldExecute: boolean;
|
|
6
15
|
readonly matchResults: RegExpExecArray[];
|
|
7
16
|
readonly skipCooldown: boolean;
|
|
8
|
-
|
|
17
|
+
readonly reason: SkipTriggerReasons | undefined;
|
|
18
|
+
constructor(shouldExecute: boolean, matchResults: RegExpExecArray[], skipCooldown: boolean, reason?: SkipTriggerReasons);
|
|
9
19
|
mergeWith(other: CommandTriggerCheckResult): CommandTriggerCheckResult;
|
|
10
20
|
}
|
|
21
|
+
export {};
|
|
11
22
|
//# sourceMappingURL=commandTriggerCheckResult.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandTriggerCheckResult.d.ts","sourceRoot":"","sources":["../../dtos/commandTriggerCheckResult.ts"],"names":[],"mappings":"AAAA,qBAAa,yBAAyB;IAClC,MAAM,
|
|
1
|
+
{"version":3,"file":"commandTriggerCheckResult.d.ts","sourceRoot":"","sources":["../../dtos/commandTriggerCheckResult.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,yBAAyB;;;;;;;CAOrB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,yBAAyB,CAAC;AAExE,qBAAa,yBAAyB;IAClC,MAAM,CAAC,0BAA0B,CAAC,MAAM,EAAE,kBAAkB;IAG5D,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,kBAAkB;IAG9C,MAAM,CAAC,OAAO;IAId,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,eAAe,EAAE,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAC;gBAG5C,aAAa,EAAE,OAAO,EACtB,YAAY,EAAE,eAAe,EAAE,EAC/B,YAAY,EAAE,OAAO,EACrB,MAAM,CAAC,EAAE,kBAAkB;IAQ/B,SAAS,CAAC,KAAK,EAAE,yBAAyB;CAQ7C"}
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandTriggerCheckResult = void 0;
|
|
4
|
+
const _SkipTriggerReasonsObject = {
|
|
5
|
+
UserIdMissing: 'UserIdMissing',
|
|
6
|
+
UserForbidden: 'UserForbidden',
|
|
7
|
+
OnCooldown: 'OnCooldown',
|
|
8
|
+
CustomConditionNotMet: 'CustomConditionNotMet',
|
|
9
|
+
TriggerNotSatisfied: 'TriggerNotSatisfied',
|
|
10
|
+
Other: 'Other'
|
|
11
|
+
};
|
|
4
12
|
class CommandTriggerCheckResult {
|
|
5
|
-
static
|
|
6
|
-
return new CommandTriggerCheckResult(false, [], true);
|
|
13
|
+
static DontTriggerAndSkipCooldown(reason) {
|
|
14
|
+
return new CommandTriggerCheckResult(false, [], true, reason);
|
|
7
15
|
}
|
|
8
|
-
static
|
|
9
|
-
return new CommandTriggerCheckResult(false, [], false);
|
|
16
|
+
static DoNotTrigger(reason) {
|
|
17
|
+
return new CommandTriggerCheckResult(false, [], false, reason);
|
|
10
18
|
}
|
|
11
|
-
static
|
|
19
|
+
static Trigger() {
|
|
12
20
|
return new CommandTriggerCheckResult(true, [], false);
|
|
13
21
|
}
|
|
14
22
|
shouldExecute;
|
|
15
23
|
matchResults;
|
|
16
24
|
skipCooldown;
|
|
17
|
-
|
|
25
|
+
reason;
|
|
26
|
+
constructor(shouldExecute, matchResults, skipCooldown, reason) {
|
|
18
27
|
this.shouldExecute = shouldExecute;
|
|
19
28
|
this.matchResults = matchResults;
|
|
20
29
|
this.skipCooldown = skipCooldown;
|
|
30
|
+
this.reason = reason;
|
|
21
31
|
}
|
|
22
32
|
mergeWith(other) {
|
|
23
|
-
return new CommandTriggerCheckResult(this.shouldExecute || other.shouldExecute, this.matchResults.concat(other.matchResults), this.skipCooldown || other.skipCooldown);
|
|
33
|
+
return new CommandTriggerCheckResult(this.shouldExecute || other.shouldExecute, this.matchResults.concat(other.matchResults), this.skipCooldown || other.skipCooldown, other.reason);
|
|
24
34
|
}
|
|
25
35
|
}
|
|
26
36
|
exports.CommandTriggerCheckResult = CommandTriggerCheckResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cooldownInfo.d.ts","sourceRoot":"","sources":["../../dtos/cooldownInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,qBAAa,YAAY;IACF,OAAO,EAAE,OAAO;IAAS,OAAO,EAAE,MAAM,GAAG,SAAS;gBAApD,OAAO,EAAE,OAAO,EAAS,OAAO,EAAE,MAAM,GAAG,SAAS;CAC1E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CooldownInfo = void 0;
|
|
4
|
+
class CooldownInfo {
|
|
5
|
+
seconds;
|
|
6
|
+
message;
|
|
7
|
+
constructor(seconds, message) {
|
|
8
|
+
this.seconds = seconds;
|
|
9
|
+
this.message = message;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.CooldownInfo = CooldownInfo;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { CommandHandler } from '../../types/handlers';
|
|
2
2
|
import { CommandCondition } from '../../types/commandCondition';
|
|
3
|
-
import { Seconds } from '../../types/timeValues';
|
|
4
3
|
import { IActionState } from '../../types/actionState';
|
|
5
4
|
import { IActionWithState, ActionKey } from '../../types/action';
|
|
6
5
|
import { MessageContext } from '../context/messageContext';
|
|
7
6
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
8
7
|
import { Sema as Semaphore } from 'async-sema';
|
|
8
|
+
import { CooldownInfo } from '../../dtos/cooldownInfo';
|
|
9
|
+
import { Seconds } from '../../types/timeValues';
|
|
9
10
|
export declare class CommandAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
|
|
10
11
|
readonly ratelimitSemaphores: Map<number, Semaphore>;
|
|
11
12
|
readonly triggers: CommandTrigger[];
|
|
12
13
|
readonly handler: CommandHandler<TActionState>;
|
|
13
14
|
readonly name: string;
|
|
14
|
-
readonly
|
|
15
|
+
readonly cooldownInfo: CooldownInfo;
|
|
15
16
|
readonly active: boolean;
|
|
16
17
|
readonly chatsBlacklist: number[];
|
|
17
18
|
readonly allowedUsers: number[];
|
|
@@ -20,7 +21,8 @@ export declare class CommandAction<TActionState extends IActionState> implements
|
|
|
20
21
|
readonly key: ActionKey;
|
|
21
22
|
readonly readmeFactory: (botName: string) => string;
|
|
22
23
|
readonly maxAllowedSimultaniousExecutions: number;
|
|
23
|
-
|
|
24
|
+
lastCustomCooldown: Seconds | undefined;
|
|
25
|
+
constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldownInfo: CooldownInfo, chatsBlacklist: number[], allowedUsers: number[], maxAllowedSimultaniousExecutions: number, condition: CommandCondition<TActionState>, stateConstructor: () => TActionState, readmeFactory: (botName: string) => string);
|
|
24
26
|
exec(ctx: MessageContext<TActionState>): Promise<import("../../types/response").BotResponse[]>;
|
|
25
27
|
private checkIfShouldBeExecuted;
|
|
26
28
|
private checkTrigger;
|
|
@@ -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;
|
|
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;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,QAAQ,CAAC,mBAAmB,yBAAgC;IAE5D,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IACpD,QAAQ,CAAC,gCAAgC,EAAE,MAAM,CAAC;IAElD,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAC;gBAGpC,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,EAC1C,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,YAAY,EAAE,YAAY,EAC1B,cAAc,EAAE,MAAM,EAAE,EACxB,YAAY,EAAE,MAAM,EAAE,EACtB,gCAAgC,EAAE,MAAM,EACxC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY,EACpC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM;IAkBxC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC;IA8E5C,OAAO,CAAC,uBAAuB;IA0C/B,OAAO,CAAC,YAAY;CAuCvB"}
|
|
@@ -12,12 +12,14 @@ const noop_1 = require("../../helpers/noop");
|
|
|
12
12
|
const messageTypes_1 = require("../../types/messageTypes");
|
|
13
13
|
const async_sema_1 = require("async-sema");
|
|
14
14
|
const mapUtils_1 = require("../../helpers/mapUtils");
|
|
15
|
+
const textMessage_1 = require("../../dtos/responses/textMessage");
|
|
16
|
+
const replyInfo_1 = require("../../dtos/replyInfo");
|
|
15
17
|
class CommandAction {
|
|
16
18
|
ratelimitSemaphores = new Map();
|
|
17
19
|
triggers;
|
|
18
20
|
handler;
|
|
19
21
|
name;
|
|
20
|
-
|
|
22
|
+
cooldownInfo;
|
|
21
23
|
active;
|
|
22
24
|
chatsBlacklist;
|
|
23
25
|
allowedUsers;
|
|
@@ -26,11 +28,12 @@ class CommandAction {
|
|
|
26
28
|
key;
|
|
27
29
|
readmeFactory;
|
|
28
30
|
maxAllowedSimultaniousExecutions;
|
|
29
|
-
|
|
31
|
+
lastCustomCooldown;
|
|
32
|
+
constructor(trigger, handler, name, active, cooldownInfo, chatsBlacklist, allowedUsers, maxAllowedSimultaniousExecutions, condition, stateConstructor, readmeFactory) {
|
|
30
33
|
this.triggers = (0, toArray_1.toArray)(trigger);
|
|
31
34
|
this.handler = handler;
|
|
32
35
|
this.name = name;
|
|
33
|
-
this.
|
|
36
|
+
this.cooldownInfo = cooldownInfo;
|
|
34
37
|
this.active = active;
|
|
35
38
|
this.chatsBlacklist = chatsBlacklist;
|
|
36
39
|
this.allowedUsers = allowedUsers;
|
|
@@ -53,11 +56,16 @@ class CommandAction {
|
|
|
53
56
|
}
|
|
54
57
|
try {
|
|
55
58
|
const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
|
|
56
|
-
const { shouldExecute, matchResults, skipCooldown } = this.triggers
|
|
59
|
+
const { shouldExecute, matchResults, skipCooldown, reason } = this.triggers
|
|
57
60
|
.map((x) => this.checkIfShouldBeExecuted(ctx, x, state))
|
|
58
|
-
.reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger);
|
|
59
|
-
if (!shouldExecute)
|
|
61
|
+
.reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('Other'));
|
|
62
|
+
if (!shouldExecute) {
|
|
63
|
+
if (reason == 'OnCooldown' && this.cooldownInfo.message)
|
|
64
|
+
return [
|
|
65
|
+
new textMessage_1.TextMessage(this.cooldownInfo.message, ctx.chatInfo, ctx.traceId, this, new replyInfo_1.ReplyInfo(ctx.messageId))
|
|
66
|
+
];
|
|
60
67
|
return noop_1.Noop.NoResponse;
|
|
68
|
+
}
|
|
61
69
|
ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
|
|
62
70
|
ctx.matchResults = matchResults;
|
|
63
71
|
await this.handler(ctx, state);
|
|
@@ -65,6 +73,7 @@ class CommandAction {
|
|
|
65
73
|
ctx.startCooldown = false;
|
|
66
74
|
}
|
|
67
75
|
if (ctx.startCooldown) {
|
|
76
|
+
this.lastCustomCooldown = ctx.customCooldown;
|
|
68
77
|
state.lastExecutedDate = (0, moment_1.default)().valueOf();
|
|
69
78
|
}
|
|
70
79
|
await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
|
|
@@ -75,29 +84,32 @@ class CommandAction {
|
|
|
75
84
|
}
|
|
76
85
|
}
|
|
77
86
|
checkIfShouldBeExecuted(ctx, trigger, state) {
|
|
87
|
+
const triggerCheckResult = this.checkTrigger(ctx, trigger);
|
|
88
|
+
if (!triggerCheckResult.shouldExecute)
|
|
89
|
+
return triggerCheckResult;
|
|
78
90
|
if (!ctx.fromUserId)
|
|
79
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
|
|
91
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserIdMissing');
|
|
80
92
|
const isUserAllowed = this.allowedUsers.length == 0 ||
|
|
81
93
|
this.allowedUsers.includes(ctx.fromUserId);
|
|
82
94
|
if (!isUserAllowed)
|
|
83
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
|
|
95
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserForbidden');
|
|
84
96
|
const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
|
|
85
|
-
const cooldownInMilliseconds = (0, timeConvertions_1.secondsToMilliseconds)(this.
|
|
97
|
+
const cooldownInMilliseconds = (0, timeConvertions_1.secondsToMilliseconds)(this.lastCustomCooldown ?? this.cooldownInfo.seconds);
|
|
86
98
|
const onCooldown = (0, moment_1.default)().diff(lastExecutedDate) < cooldownInMilliseconds;
|
|
87
99
|
if (onCooldown)
|
|
88
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
|
|
100
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('OnCooldown');
|
|
89
101
|
const isCustomConditionMet = this.condition(ctx, state);
|
|
90
102
|
if (!isCustomConditionMet)
|
|
91
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
|
|
92
|
-
return
|
|
103
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('CustomConditionNotMet');
|
|
104
|
+
return triggerCheckResult;
|
|
93
105
|
}
|
|
94
106
|
checkTrigger(ctx, trigger) {
|
|
95
107
|
if (trigger == messageTypes_1.MessageType.Any || trigger == ctx.messageType)
|
|
96
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger;
|
|
108
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger();
|
|
97
109
|
if (typeof trigger == 'string')
|
|
98
110
|
return ctx.messageText.toLowerCase() == trigger.toLowerCase()
|
|
99
|
-
? commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger
|
|
100
|
-
: commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
|
|
111
|
+
? commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger()
|
|
112
|
+
: commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
101
113
|
const matchResults = [];
|
|
102
114
|
trigger.lastIndex = 0;
|
|
103
115
|
const execResult = trigger.exec(ctx.messageText);
|
|
@@ -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,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,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,YAAY,CAAC,kBAAkB,CAAC,KAC7C,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,gBAAgB,CAAC,kBAAkB,CAAC,EAClD,OAAO,EAAE,CACL,YAAY,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAC7C,OAAO,CAAC,IAAI,CAAC,EAClB,QAAQ,EAAE,cAAc,EAAE,EAC1B,eAAe,EAAE,eAAe;IAY9B,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,kBAAkB,CAAC;IAyBhD,OAAO,CAAC,uBAAuB;
|
|
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,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,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,YAAY,CAAC,kBAAkB,CAAC,KAC7C,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,gBAAgB,CAAC,kBAAkB,CAAC,EAClD,OAAO,EAAE,CACL,YAAY,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAC7C,OAAO,CAAC,IAAI,CAAC,EAClB,QAAQ,EAAE,cAAc,EAAE,EAC1B,eAAe,EAAE,eAAe;IAY9B,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,kBAAkB,CAAC;IAyBhD,OAAO,CAAC,uBAAuB;CA+ClC"}
|
|
@@ -23,7 +23,7 @@ class ReplyCaptureAction {
|
|
|
23
23
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
24
24
|
const { shouldExecute, matchResults } = this.triggers
|
|
25
25
|
.map((x) => this.checkIfShouldBeExecuted(ctx, x))
|
|
26
|
-
.reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger);
|
|
26
|
+
.reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('Other'));
|
|
27
27
|
if (!shouldExecute)
|
|
28
28
|
return noop_1.Noop.NoResponse;
|
|
29
29
|
ctx.logger.logWithTraceId(` - Executing [${this.key}] in ${ctx.chatInfo.id}`);
|
|
@@ -33,14 +33,14 @@ class ReplyCaptureAction {
|
|
|
33
33
|
}
|
|
34
34
|
checkIfShouldBeExecuted(ctx, trigger) {
|
|
35
35
|
if (ctx.replyMessageId != this.parentMessageId)
|
|
36
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
|
|
36
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
37
37
|
if (trigger == ctx.messageType)
|
|
38
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger;
|
|
38
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger();
|
|
39
39
|
if (typeof trigger == 'string')
|
|
40
40
|
if (ctx.messageText.toLowerCase() == trigger.toLowerCase())
|
|
41
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger;
|
|
41
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger();
|
|
42
42
|
else
|
|
43
|
-
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
|
|
43
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
44
44
|
const matchResults = [];
|
|
45
45
|
trigger.lastIndex = 0;
|
|
46
46
|
const execResult = trigger.exec(ctx.messageText);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { TelegramEmoji } from 'telegraf/types';
|
|
1
|
+
import { TelegramEmoji, UserFromGetMe } from 'telegraf/types';
|
|
2
2
|
import { IActionState } from '../../types/actionState';
|
|
3
3
|
import { ChatContext } from './chatContext';
|
|
4
4
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
5
5
|
import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
|
|
6
6
|
import { CommandAction } from '../actions/commandAction';
|
|
7
|
+
import { Seconds } from '../../types/timeValues';
|
|
7
8
|
/**
|
|
8
9
|
* Context of action executed in chat, in response to a message
|
|
9
10
|
*/
|
|
@@ -24,10 +25,14 @@ export declare class MessageContext<TActionState extends IActionState> extends C
|
|
|
24
25
|
messageType: MessageTypeValue;
|
|
25
26
|
/** Message object recieved from Telegram */
|
|
26
27
|
messageUpdateObject: TelegrafContextMessage;
|
|
28
|
+
/** Bot info from Telegram */
|
|
29
|
+
botInfo: UserFromGetMe;
|
|
30
|
+
customCooldown: Seconds | undefined;
|
|
27
31
|
private getQuotePart;
|
|
28
32
|
private replyWithText;
|
|
29
33
|
private replyWithImage;
|
|
30
34
|
private replyWithVideo;
|
|
35
|
+
startCustomCooldown(customCooldown: Seconds): void;
|
|
31
36
|
/**
|
|
32
37
|
* Collection of actions that can be done as a reply to a message that triggered this action
|
|
33
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC5D,kDAAkD;IAClD,SAAS,EAAG,MAAM,CAAC;IACnB,oDAAoD;IACpD,WAAW,EAAG,MAAM,CAAC;IACrB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAG,MAAM,CAAC;IACtB,qCAAqC;IACrC,WAAW,EAAG,gBAAgB,CAAC;IAC/B,4CAA4C;IAC5C,mBAAmB,EAAG,sBAAsB,CAAC;IAC7C,6BAA6B;IAC7B,OAAO,EAAG,aAAa,CAAC;IAExB,cAAc,EAAE,OAAO,GAAG,SAAS,CAAC;IAEpC,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,cAAc;IAqBtB,mBAAmB,CAAC,cAAc,EAAE,OAAO;IAK3C;;OAEG;IACH,KAAK;QACD;;;WAGG;;YAEC;;;;;eAKG;6BAEO,MAAM,UACJ,MAAM,YACJ,yBAAyB;YAEvC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;YAGnC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;;QAIvC;;;;;WAKG;yBACc,MAAM,YAAY,yBAAyB;QAE5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
|
|
@@ -28,6 +28,9 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
28
28
|
messageType;
|
|
29
29
|
/** Message object recieved from Telegram */
|
|
30
30
|
messageUpdateObject;
|
|
31
|
+
/** Bot info from Telegram */
|
|
32
|
+
botInfo;
|
|
33
|
+
customCooldown;
|
|
31
34
|
getQuotePart(quote) {
|
|
32
35
|
return typeof quote == 'boolean'
|
|
33
36
|
? this.matchResults.length != 0
|
|
@@ -53,6 +56,10 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
53
56
|
this.responses.push(response);
|
|
54
57
|
return this.createCaptureController(response);
|
|
55
58
|
}
|
|
59
|
+
startCustomCooldown(customCooldown) {
|
|
60
|
+
this.startCooldown = true;
|
|
61
|
+
this.customCooldown = customCooldown;
|
|
62
|
+
}
|
|
56
63
|
/**
|
|
57
64
|
* Collection of actions that can be done as a reply to a message that triggered this action
|
|
58
65
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TelegramEmoji } from 'telegraf/types';
|
|
1
|
+
import { TelegramEmoji, UserFromGetMe } from 'telegraf/types';
|
|
2
2
|
import { IActionState } from '../../types/actionState';
|
|
3
3
|
import { TextMessageSendingOptions, MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
4
|
import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
|
|
@@ -21,6 +21,8 @@ export declare class ReplyContext<TParentActionState extends IActionState> exten
|
|
|
21
21
|
fromUserName: string;
|
|
22
22
|
/** Message object recieved from Telegram */
|
|
23
23
|
messageUpdateObject: TelegrafContextMessage;
|
|
24
|
+
/** Bot info from Telegram */
|
|
25
|
+
botInfo: UserFromGetMe;
|
|
24
26
|
isInitialized: boolean;
|
|
25
27
|
private getQuotePart;
|
|
26
28
|
private replyWithText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../entities/context/replyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,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,EACH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,YAAY,CACrB,kBAAkB,SAAS,YAAY,CACzC,SAAQ,WAAW,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IACzD,4HAA4H;IAC5H,YAAY,EAAG,eAAe,EAAE,CAAC;IACjC,kDAAkD;IAClD,cAAc,EAAG,MAAM,GAAG,SAAS,CAAC;IACpC,kDAAkD;IAClD,SAAS,EAAG,MAAM,CAAC;IACnB,qCAAqC;IACrC,WAAW,EAAG,gBAAgB,CAAC;IAC/B,oDAAoD;IACpD,WAAW,EAAG,MAAM,CAAC;IACrB,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,qEAAqE;IACrE,YAAY,EAAG,MAAM,CAAC;IACtB,4CAA4C;IAC5C,mBAAmB,EAAG,sBAAsB,CAAC;IAC7C,6BAA6B;IAC7B,OAAO,EAAG,aAAa,CAAC;IAExB,aAAa,UAAS;IAEtB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,cAAc;IAmBtB;;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"}
|
|
@@ -25,6 +25,8 @@ class ReplyContext extends baseContext_1.BaseContext {
|
|
|
25
25
|
fromUserName;
|
|
26
26
|
/** Message object recieved from Telegram */
|
|
27
27
|
messageUpdateObject;
|
|
28
|
+
/** Bot info from Telegram */
|
|
29
|
+
botInfo;
|
|
28
30
|
isInitialized = false;
|
|
29
31
|
getQuotePart(quote) {
|
|
30
32
|
return typeof quote == 'boolean'
|
|
@@ -20,6 +20,7 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
20
20
|
handler: CommandHandler<TActionState>;
|
|
21
21
|
condition: CommandCondition<TActionState>;
|
|
22
22
|
maxAllowedSimultaniousExecutions: number;
|
|
23
|
+
cooldownMessage: string | undefined;
|
|
23
24
|
/**
|
|
24
25
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
25
26
|
* @param name Action name, will be used for logging and storage
|
|
@@ -54,6 +55,10 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
54
55
|
* @param seconds Cooldown in seconds.
|
|
55
56
|
*/
|
|
56
57
|
cooldown(seconds: Seconds): this;
|
|
58
|
+
/** Sets action cooldown message.
|
|
59
|
+
* @param message Message that will be sent if action is on cooldown.
|
|
60
|
+
*/
|
|
61
|
+
withCooldownMessage(message: string): this;
|
|
57
62
|
/**
|
|
58
63
|
* Adds a chat to ignore list for this action.
|
|
59
64
|
* @param chatId Chat id to ignore.
|
|
@@ -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;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/commandActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D;;GAEG;AACH,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,CAAM;IAEhD,MAAM,UAAQ;IACd,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAQ;IAC3D,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;IACtD,gCAAgC,EAAE,MAAM,CAAK;IAC7C,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IAEpC;;;;OAIG;gBACS,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,YAAY;IAK9D;;;;;OAKG;IACH,EAAE,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE;IAM7C;;OAEG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;IAM1B;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC;IAMxC;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAM9C,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM;IAMnD,iFAAiF;IACjF,QAAQ;IAMR,qHAAqH;IACrH,SAAS,CAAC,gCAAgC,EAAE,MAAM;IAOlD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO;IAMzB;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM;IAMnC;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM;IAMzB,oBAAoB;IACpB,KAAK;CAeR;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,6BAA6B,CAAC,eAAe,CAAC;IACpF;;OAEG;gBACS,IAAI,EAAE,MAAM;CAG3B"}
|
|
@@ -5,6 +5,7 @@ const commandAction_1 = require("../../entities/actions/commandAction");
|
|
|
5
5
|
const actionStateBase_1 = require("../../entities/states/actionStateBase");
|
|
6
6
|
const toArray_1 = require("../toArray");
|
|
7
7
|
const noop_1 = require("../noop");
|
|
8
|
+
const cooldownInfo_1 = require("../../dtos/cooldownInfo");
|
|
8
9
|
/**
|
|
9
10
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
10
11
|
*/
|
|
@@ -20,6 +21,7 @@ class CommandActionBuilderWithState {
|
|
|
20
21
|
handler = noop_1.Noop.call;
|
|
21
22
|
condition = noop_1.Noop.true;
|
|
22
23
|
maxAllowedSimultaniousExecutions = 0;
|
|
24
|
+
cooldownMessage;
|
|
23
25
|
/**
|
|
24
26
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
25
27
|
* @param name Action name, will be used for logging and storage
|
|
@@ -82,6 +84,13 @@ class CommandActionBuilderWithState {
|
|
|
82
84
|
this.cooldownSeconds = seconds;
|
|
83
85
|
return this;
|
|
84
86
|
}
|
|
87
|
+
/** Sets action cooldown message.
|
|
88
|
+
* @param message Message that will be sent if action is on cooldown.
|
|
89
|
+
*/
|
|
90
|
+
withCooldownMessage(message) {
|
|
91
|
+
this.cooldownMessage = message;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
85
94
|
/**
|
|
86
95
|
* Adds a chat to ignore list for this action.
|
|
87
96
|
* @param chatId Chat id to ignore.
|
|
@@ -92,7 +101,7 @@ class CommandActionBuilderWithState {
|
|
|
92
101
|
}
|
|
93
102
|
/** Builds action */
|
|
94
103
|
build() {
|
|
95
|
-
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, this.cooldownSeconds, this.blacklist, this.allowedUsers, this.maxAllowedSimultaniousExecutions, this.condition, this.stateConstructor, this.readmeFactory != null ? this.readmeFactory : (_) => '');
|
|
104
|
+
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, new cooldownInfo_1.CooldownInfo(this.cooldownSeconds, this.cooldownMessage), this.blacklist, this.allowedUsers, this.maxAllowedSimultaniousExecutions, this.condition, this.stateConstructor, this.readmeFactory != null ? this.readmeFactory : (_) => '');
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
107
|
exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionProcessingService.d.ts","sourceRoot":"","sources":["../../services/actionProcessingService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAuB,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAMtE,qBAAa,uBAAuB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAyB;IAC1D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA2B;IAC9D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA6B;IAElE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,QAAQ,CAAY;gBAGxB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IA4Bb,UAAU,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;KACtC,EACD,eAAe,CAAC,EAAE,OAAO,EACzB,gCAAgC,CAAC,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"actionProcessingService.d.ts","sourceRoot":"","sources":["../../services/actionProcessingService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAuB,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAMtE,qBAAa,uBAAuB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAyB;IAC1D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA2B;IAC9D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA6B;IAElE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,QAAQ,CAAY;gBAGxB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IA4Bb,UAAU,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;KACtC,EACD,eAAe,CAAC,EAAE,OAAO,EACzB,gCAAgC,CAAC,EAAE,OAAO;IA2D9C,IAAI,CAAC,IAAI,EAAE,MAAM;CAGpB"}
|
|
@@ -38,7 +38,7 @@ class ActionProcessingService {
|
|
|
38
38
|
...actions.commands
|
|
39
39
|
]
|
|
40
40
|
: [];
|
|
41
|
-
this.commandProcessor.initialize(api, this.telegraf, commandActions, verboseLoggingForIncomingMessage ?? false);
|
|
41
|
+
this.commandProcessor.initialize(api, this.telegraf, commandActions, verboseLoggingForIncomingMessage ?? false, botInfo);
|
|
42
42
|
this.inlineQueryProcessor.initialize(api, this.telegraf, actions.inlineQueries, 300);
|
|
43
43
|
this.scheduledProcessor.initialize(api, actions.scheduled, scheduledPeriod ?? (0, timeConvertions_1.hoursToSeconds)(1));
|
|
44
44
|
void this.storage.saveMetadata([
|
|
@@ -6,10 +6,12 @@ import { IReplyCapture } from '../../types/capture';
|
|
|
6
6
|
import { TraceId } from '../../types/trace';
|
|
7
7
|
import { ChatInfo } from '../../dtos/chatInfo';
|
|
8
8
|
import { BaseActionProcessor } from './baseProcessor';
|
|
9
|
+
import { UserFromGetMe } from 'telegraf/types';
|
|
9
10
|
export declare class CommandActionProcessor extends BaseActionProcessor {
|
|
10
11
|
private readonly replyCaptures;
|
|
12
|
+
private botInfo;
|
|
11
13
|
private commands;
|
|
12
|
-
initialize(api: TelegramApiService, telegraf: Telegraf, commands: CommandAction<IActionState>[], verboseLoggingForIncomingMessage: boolean): void;
|
|
14
|
+
initialize(api: TelegramApiService, telegraf: Telegraf, commands: CommandAction<IActionState>[], verboseLoggingForIncomingMessage: boolean, botInfo: UserFromGetMe): void;
|
|
13
15
|
captureRegistrationCallback(capture: IReplyCapture, parentMessageId: number, chatInfo: ChatInfo, traceId: TraceId): void;
|
|
14
16
|
private processMessage;
|
|
15
17
|
private initializeReplyCaptureContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/commandActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAIrE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"commandActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/commandActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAIrE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC3D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IACxE,OAAO,CAAC,OAAO,CAAiB;IAEhC,OAAO,CAAC,QAAQ,CAKd;IAEF,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,gCAAgC,EAAE,OAAO,EACzC,OAAO,EAAE,aAAa;IA0D1B,2BAA2B,CACvB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO;YA+BN,cAAc;IAiC5B,OAAO,CAAC,6BAA6B;IA8BrC,OAAO,CAAC,wBAAwB;CAgCnC"}
|
|
@@ -10,11 +10,13 @@ const objectFromEntries_1 = require("../../helpers/objectFromEntries");
|
|
|
10
10
|
const baseProcessor_1 = require("./baseProcessor");
|
|
11
11
|
class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
12
12
|
replyCaptures = [];
|
|
13
|
+
botInfo;
|
|
13
14
|
commands = (0, objectFromEntries_1.typeSafeObjectFromEntries)(Object.values(messageTypes_1.MessageType).map((x) => [
|
|
14
15
|
x,
|
|
15
16
|
[]
|
|
16
17
|
]));
|
|
17
|
-
initialize(api, telegraf, commands, verboseLoggingForIncomingMessage) {
|
|
18
|
+
initialize(api, telegraf, commands, verboseLoggingForIncomingMessage, botInfo) {
|
|
19
|
+
this.botInfo = botInfo;
|
|
18
20
|
this.initializeDependencies(api);
|
|
19
21
|
for (const msgType of Object.values(messageTypes_1.MessageType)) {
|
|
20
22
|
if (msgType == messageTypes_1.MessageType.Text) {
|
|
@@ -87,6 +89,7 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
|
87
89
|
ctx.action = action;
|
|
88
90
|
ctx.chatInfo = message.chatInfo;
|
|
89
91
|
ctx.traceId = message.traceId;
|
|
92
|
+
ctx.botInfo = this.botInfo;
|
|
90
93
|
ctx.isInitialized = true;
|
|
91
94
|
ctx.matchResults = [];
|
|
92
95
|
ctx.logger = this.logger.createScope(this.botName, message.traceId, message.chatInfo.name);
|
|
@@ -108,6 +111,8 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
|
108
111
|
ctx.action = action;
|
|
109
112
|
ctx.chatInfo = message.chatInfo;
|
|
110
113
|
ctx.traceId = message.traceId;
|
|
114
|
+
ctx.botInfo = this.botInfo;
|
|
115
|
+
ctx.customCooldown = undefined;
|
|
111
116
|
ctx.logger = this.logger.createScope(this.botName, message.traceId, message.chatInfo.name);
|
|
112
117
|
}
|
|
113
118
|
}
|
|
@@ -1,33 +1,48 @@
|
|
|
1
|
+
const _SkipTriggerReasonsObject = {
|
|
2
|
+
UserIdMissing: 'UserIdMissing',
|
|
3
|
+
UserForbidden: 'UserForbidden',
|
|
4
|
+
OnCooldown: 'OnCooldown',
|
|
5
|
+
CustomConditionNotMet: 'CustomConditionNotMet',
|
|
6
|
+
TriggerNotSatisfied: 'TriggerNotSatisfied',
|
|
7
|
+
Other: 'Other'
|
|
8
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
export type SkipTriggerReasons = keyof typeof _SkipTriggerReasonsObject;
|
|
11
|
+
|
|
1
12
|
export class CommandTriggerCheckResult {
|
|
2
|
-
static
|
|
3
|
-
return new CommandTriggerCheckResult(false, [], true);
|
|
13
|
+
static DontTriggerAndSkipCooldown(reason: SkipTriggerReasons) {
|
|
14
|
+
return new CommandTriggerCheckResult(false, [], true, reason);
|
|
4
15
|
}
|
|
5
|
-
static
|
|
6
|
-
return new CommandTriggerCheckResult(false, [], false);
|
|
16
|
+
static DoNotTrigger(reason: SkipTriggerReasons) {
|
|
17
|
+
return new CommandTriggerCheckResult(false, [], false, reason);
|
|
7
18
|
}
|
|
8
|
-
static
|
|
19
|
+
static Trigger() {
|
|
9
20
|
return new CommandTriggerCheckResult(true, [], false);
|
|
10
21
|
}
|
|
11
22
|
|
|
12
23
|
readonly shouldExecute: boolean;
|
|
13
24
|
readonly matchResults: RegExpExecArray[];
|
|
14
25
|
readonly skipCooldown: boolean;
|
|
26
|
+
readonly reason: SkipTriggerReasons | undefined;
|
|
15
27
|
|
|
16
28
|
constructor(
|
|
17
29
|
shouldExecute: boolean,
|
|
18
30
|
matchResults: RegExpExecArray[],
|
|
19
|
-
skipCooldown: boolean
|
|
31
|
+
skipCooldown: boolean,
|
|
32
|
+
reason?: SkipTriggerReasons
|
|
20
33
|
) {
|
|
21
34
|
this.shouldExecute = shouldExecute;
|
|
22
35
|
this.matchResults = matchResults;
|
|
23
36
|
this.skipCooldown = skipCooldown;
|
|
37
|
+
this.reason = reason;
|
|
24
38
|
}
|
|
25
39
|
|
|
26
40
|
mergeWith(other: CommandTriggerCheckResult) {
|
|
27
41
|
return new CommandTriggerCheckResult(
|
|
28
42
|
this.shouldExecute || other.shouldExecute,
|
|
29
43
|
this.matchResults.concat(other.matchResults),
|
|
30
|
-
this.skipCooldown || other.skipCooldown
|
|
44
|
+
this.skipCooldown || other.skipCooldown,
|
|
45
|
+
other.reason
|
|
31
46
|
);
|
|
32
47
|
}
|
|
33
48
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
2
|
import { CommandHandler } from '../../types/handlers';
|
|
3
3
|
import { CommandCondition } from '../../types/commandCondition';
|
|
4
|
-
import { Seconds } from '../../types/timeValues';
|
|
5
4
|
import { secondsToMilliseconds } from '../../helpers/timeConvertions';
|
|
6
5
|
import { toArray } from '../../helpers/toArray';
|
|
7
6
|
import { IActionState } from '../../types/actionState';
|
|
@@ -13,6 +12,10 @@ import { Noop } from '../../helpers/noop';
|
|
|
13
12
|
import { MessageType } from '../../types/messageTypes';
|
|
14
13
|
import { Sema as Semaphore } from 'async-sema';
|
|
15
14
|
import { getOrSetIfNotExists } from '../../helpers/mapUtils';
|
|
15
|
+
import { CooldownInfo } from '../../dtos/cooldownInfo';
|
|
16
|
+
import { TextMessage } from '../../dtos/responses/textMessage';
|
|
17
|
+
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
18
|
+
import { Seconds } from '../../types/timeValues';
|
|
16
19
|
|
|
17
20
|
export class CommandAction<TActionState extends IActionState>
|
|
18
21
|
implements IActionWithState<TActionState>
|
|
@@ -22,7 +25,7 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
22
25
|
readonly triggers: CommandTrigger[];
|
|
23
26
|
readonly handler: CommandHandler<TActionState>;
|
|
24
27
|
readonly name: string;
|
|
25
|
-
readonly
|
|
28
|
+
readonly cooldownInfo: CooldownInfo;
|
|
26
29
|
readonly active: boolean;
|
|
27
30
|
readonly chatsBlacklist: number[];
|
|
28
31
|
readonly allowedUsers: number[];
|
|
@@ -32,12 +35,14 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
32
35
|
readonly readmeFactory: (botName: string) => string;
|
|
33
36
|
readonly maxAllowedSimultaniousExecutions: number;
|
|
34
37
|
|
|
38
|
+
lastCustomCooldown: Seconds | undefined;
|
|
39
|
+
|
|
35
40
|
constructor(
|
|
36
41
|
trigger: CommandTrigger | CommandTrigger[],
|
|
37
42
|
handler: CommandHandler<TActionState>,
|
|
38
43
|
name: string,
|
|
39
44
|
active: boolean,
|
|
40
|
-
|
|
45
|
+
cooldownInfo: CooldownInfo,
|
|
41
46
|
chatsBlacklist: number[],
|
|
42
47
|
allowedUsers: number[],
|
|
43
48
|
maxAllowedSimultaniousExecutions: number,
|
|
@@ -48,7 +53,7 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
48
53
|
this.triggers = toArray(trigger);
|
|
49
54
|
this.handler = handler;
|
|
50
55
|
this.name = name;
|
|
51
|
-
this.
|
|
56
|
+
this.cooldownInfo = cooldownInfo;
|
|
52
57
|
this.active = active;
|
|
53
58
|
this.chatsBlacklist = chatsBlacklist;
|
|
54
59
|
this.allowedUsers = allowedUsers;
|
|
@@ -87,14 +92,28 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
87
92
|
ctx.chatInfo.id
|
|
88
93
|
);
|
|
89
94
|
|
|
90
|
-
const { shouldExecute, matchResults, skipCooldown } =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
const { shouldExecute, matchResults, skipCooldown, reason } =
|
|
96
|
+
this.triggers
|
|
97
|
+
.map((x) => this.checkIfShouldBeExecuted(ctx, x, state))
|
|
98
|
+
.reduce(
|
|
99
|
+
(acc, curr) => acc.mergeWith(curr),
|
|
100
|
+
CommandTriggerCheckResult.DoNotTrigger('Other')
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (!shouldExecute) {
|
|
104
|
+
if (reason == 'OnCooldown' && this.cooldownInfo.message)
|
|
105
|
+
return [
|
|
106
|
+
new TextMessage(
|
|
107
|
+
this.cooldownInfo.message,
|
|
108
|
+
ctx.chatInfo,
|
|
109
|
+
ctx.traceId,
|
|
110
|
+
this,
|
|
111
|
+
new ReplyInfo(ctx.messageId)
|
|
112
|
+
)
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
return Noop.NoResponse;
|
|
116
|
+
}
|
|
98
117
|
|
|
99
118
|
ctx.logger.logWithTraceId(
|
|
100
119
|
` - Executing [${this.name}] in ${ctx.chatInfo.id}`
|
|
@@ -108,6 +127,8 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
108
127
|
}
|
|
109
128
|
|
|
110
129
|
if (ctx.startCooldown) {
|
|
130
|
+
this.lastCustomCooldown = ctx.customCooldown;
|
|
131
|
+
|
|
111
132
|
state.lastExecutedDate = moment().valueOf();
|
|
112
133
|
}
|
|
113
134
|
|
|
@@ -128,30 +149,41 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
128
149
|
trigger: CommandTrigger,
|
|
129
150
|
state: TActionState
|
|
130
151
|
) {
|
|
152
|
+
const triggerCheckResult = this.checkTrigger(ctx, trigger);
|
|
153
|
+
|
|
154
|
+
if (!triggerCheckResult.shouldExecute) return triggerCheckResult;
|
|
155
|
+
|
|
131
156
|
if (!ctx.fromUserId)
|
|
132
|
-
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown
|
|
157
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown(
|
|
158
|
+
'UserIdMissing'
|
|
159
|
+
);
|
|
133
160
|
|
|
134
161
|
const isUserAllowed =
|
|
135
162
|
this.allowedUsers.length == 0 ||
|
|
136
163
|
this.allowedUsers.includes(ctx.fromUserId);
|
|
137
164
|
|
|
138
165
|
if (!isUserAllowed)
|
|
139
|
-
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown
|
|
166
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown(
|
|
167
|
+
'UserForbidden'
|
|
168
|
+
);
|
|
140
169
|
|
|
141
170
|
const lastExecutedDate = moment(state.lastExecutedDate);
|
|
142
171
|
const cooldownInMilliseconds = secondsToMilliseconds(
|
|
143
|
-
this.
|
|
172
|
+
this.lastCustomCooldown ?? this.cooldownInfo.seconds
|
|
144
173
|
);
|
|
145
174
|
const onCooldown =
|
|
146
175
|
moment().diff(lastExecutedDate) < cooldownInMilliseconds;
|
|
147
176
|
|
|
148
|
-
if (onCooldown)
|
|
177
|
+
if (onCooldown)
|
|
178
|
+
return CommandTriggerCheckResult.DoNotTrigger('OnCooldown');
|
|
149
179
|
|
|
150
180
|
const isCustomConditionMet = this.condition(ctx, state);
|
|
151
181
|
if (!isCustomConditionMet)
|
|
152
|
-
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown
|
|
182
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown(
|
|
183
|
+
'CustomConditionNotMet'
|
|
184
|
+
);
|
|
153
185
|
|
|
154
|
-
return
|
|
186
|
+
return triggerCheckResult;
|
|
155
187
|
}
|
|
156
188
|
|
|
157
189
|
private checkTrigger(
|
|
@@ -159,12 +191,12 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
159
191
|
trigger: CommandTrigger
|
|
160
192
|
) {
|
|
161
193
|
if (trigger == MessageType.Any || trigger == ctx.messageType)
|
|
162
|
-
return CommandTriggerCheckResult.Trigger;
|
|
194
|
+
return CommandTriggerCheckResult.Trigger();
|
|
163
195
|
|
|
164
196
|
if (typeof trigger == 'string')
|
|
165
197
|
return ctx.messageText.toLowerCase() == trigger.toLowerCase()
|
|
166
|
-
? CommandTriggerCheckResult.Trigger
|
|
167
|
-
: CommandTriggerCheckResult.DoNotTrigger;
|
|
198
|
+
? CommandTriggerCheckResult.Trigger()
|
|
199
|
+
: CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
|
|
168
200
|
|
|
169
201
|
const matchResults: RegExpExecArray[] = [];
|
|
170
202
|
|
|
@@ -45,7 +45,7 @@ export class ReplyCaptureAction<TParentActionState extends IActionState>
|
|
|
45
45
|
.map((x) => this.checkIfShouldBeExecuted(ctx, x))
|
|
46
46
|
.reduce(
|
|
47
47
|
(acc, curr) => acc.mergeWith(curr),
|
|
48
|
-
CommandTriggerCheckResult.DoNotTrigger
|
|
48
|
+
CommandTriggerCheckResult.DoNotTrigger('Other')
|
|
49
49
|
);
|
|
50
50
|
|
|
51
51
|
if (!shouldExecute) return Noop.NoResponse;
|
|
@@ -65,15 +65,20 @@ export class ReplyCaptureAction<TParentActionState extends IActionState>
|
|
|
65
65
|
trigger: CommandTrigger
|
|
66
66
|
) {
|
|
67
67
|
if (ctx.replyMessageId != this.parentMessageId)
|
|
68
|
-
return CommandTriggerCheckResult.DoNotTrigger
|
|
68
|
+
return CommandTriggerCheckResult.DoNotTrigger(
|
|
69
|
+
'TriggerNotSatisfied'
|
|
70
|
+
);
|
|
69
71
|
|
|
70
72
|
if (trigger == ctx.messageType)
|
|
71
|
-
return CommandTriggerCheckResult.Trigger;
|
|
73
|
+
return CommandTriggerCheckResult.Trigger();
|
|
72
74
|
|
|
73
75
|
if (typeof trigger == 'string')
|
|
74
76
|
if (ctx.messageText.toLowerCase() == trigger.toLowerCase())
|
|
75
|
-
return CommandTriggerCheckResult.Trigger;
|
|
76
|
-
else
|
|
77
|
+
return CommandTriggerCheckResult.Trigger();
|
|
78
|
+
else
|
|
79
|
+
return CommandTriggerCheckResult.DoNotTrigger(
|
|
80
|
+
'TriggerNotSatisfied'
|
|
81
|
+
);
|
|
77
82
|
|
|
78
83
|
const matchResults: RegExpExecArray[] = [];
|
|
79
84
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
|
-
import { TelegramEmoji } from 'telegraf/types';
|
|
2
|
+
import { TelegramEmoji, UserFromGetMe } from 'telegraf/types';
|
|
3
3
|
import { IActionState } from '../../types/actionState';
|
|
4
4
|
import { ImageMessage } from '../../dtos/responses/imageMessage';
|
|
5
5
|
import { Reaction } from '../../dtos/responses/reaction';
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from '../../types/messageTypes';
|
|
17
17
|
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
18
18
|
import { CommandAction } from '../actions/commandAction';
|
|
19
|
+
import { Seconds } from '../../types/timeValues';
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Context of action executed in chat, in response to a message
|
|
@@ -39,6 +40,10 @@ export class MessageContext<
|
|
|
39
40
|
messageType!: MessageTypeValue;
|
|
40
41
|
/** Message object recieved from Telegram */
|
|
41
42
|
messageUpdateObject!: TelegrafContextMessage;
|
|
43
|
+
/** Bot info from Telegram */
|
|
44
|
+
botInfo!: UserFromGetMe;
|
|
45
|
+
|
|
46
|
+
customCooldown: Seconds | undefined;
|
|
42
47
|
|
|
43
48
|
private getQuotePart(quote: boolean | string) {
|
|
44
49
|
return typeof quote == 'boolean'
|
|
@@ -111,6 +116,11 @@ export class MessageContext<
|
|
|
111
116
|
return this.createCaptureController(response);
|
|
112
117
|
}
|
|
113
118
|
|
|
119
|
+
startCustomCooldown(customCooldown: Seconds) {
|
|
120
|
+
this.startCooldown = true;
|
|
121
|
+
this.customCooldown = customCooldown;
|
|
122
|
+
}
|
|
123
|
+
|
|
114
124
|
/**
|
|
115
125
|
* Collection of actions that can be done as a reply to a message that triggered this action
|
|
116
126
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TelegramEmoji } from 'telegraf/types';
|
|
1
|
+
import { TelegramEmoji, UserFromGetMe } from 'telegraf/types';
|
|
2
2
|
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
3
3
|
import { ImageMessage } from '../../dtos/responses/imageMessage';
|
|
4
4
|
import { Reaction } from '../../dtos/responses/reaction';
|
|
@@ -36,6 +36,8 @@ export class ReplyContext<
|
|
|
36
36
|
fromUserName!: string;
|
|
37
37
|
/** Message object recieved from Telegram */
|
|
38
38
|
messageUpdateObject!: TelegrafContextMessage;
|
|
39
|
+
/** Bot info from Telegram */
|
|
40
|
+
botInfo!: UserFromGetMe;
|
|
39
41
|
|
|
40
42
|
isInitialized = false;
|
|
41
43
|
|
|
@@ -7,6 +7,7 @@ import { IActionState } from '../../types/actionState';
|
|
|
7
7
|
import { toArray } from '../toArray';
|
|
8
8
|
import { Noop } from '../noop';
|
|
9
9
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
10
|
+
import { CooldownInfo } from '../../dtos/cooldownInfo';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
@@ -24,6 +25,7 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
24
25
|
handler: CommandHandler<TActionState> = Noop.call;
|
|
25
26
|
condition: CommandCondition<TActionState> = Noop.true;
|
|
26
27
|
maxAllowedSimultaniousExecutions: number = 0;
|
|
28
|
+
cooldownMessage: string | undefined;
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
@@ -104,6 +106,15 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
104
106
|
return this;
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
/** Sets action cooldown message.
|
|
110
|
+
* @param message Message that will be sent if action is on cooldown.
|
|
111
|
+
*/
|
|
112
|
+
withCooldownMessage(message: string) {
|
|
113
|
+
this.cooldownMessage = message;
|
|
114
|
+
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
107
118
|
/**
|
|
108
119
|
* Adds a chat to ignore list for this action.
|
|
109
120
|
* @param chatId Chat id to ignore.
|
|
@@ -121,7 +132,7 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
121
132
|
this.handler,
|
|
122
133
|
this.name,
|
|
123
134
|
this.active,
|
|
124
|
-
this.cooldownSeconds,
|
|
135
|
+
new CooldownInfo(this.cooldownSeconds, this.cooldownMessage),
|
|
125
136
|
this.blacklist,
|
|
126
137
|
this.allowedUsers,
|
|
127
138
|
this.maxAllowedSimultaniousExecutions,
|
package/package.json
CHANGED
|
@@ -15,9 +15,11 @@ import {
|
|
|
15
15
|
} from '../../types/messageTypes';
|
|
16
16
|
import { typeSafeObjectFromEntries } from '../../helpers/objectFromEntries';
|
|
17
17
|
import { BaseActionProcessor } from './baseProcessor';
|
|
18
|
+
import { UserFromGetMe } from 'telegraf/types';
|
|
18
19
|
|
|
19
20
|
export class CommandActionProcessor extends BaseActionProcessor {
|
|
20
21
|
private readonly replyCaptures: ReplyCaptureAction<IActionState>[] = [];
|
|
22
|
+
private botInfo!: UserFromGetMe;
|
|
21
23
|
|
|
22
24
|
private commands = typeSafeObjectFromEntries(
|
|
23
25
|
Object.values(MessageType).map((x) => [
|
|
@@ -30,8 +32,10 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
30
32
|
api: TelegramApiService,
|
|
31
33
|
telegraf: Telegraf,
|
|
32
34
|
commands: CommandAction<IActionState>[],
|
|
33
|
-
verboseLoggingForIncomingMessage: boolean
|
|
35
|
+
verboseLoggingForIncomingMessage: boolean,
|
|
36
|
+
botInfo: UserFromGetMe
|
|
34
37
|
) {
|
|
38
|
+
this.botInfo = botInfo;
|
|
35
39
|
this.initializeDependencies(api);
|
|
36
40
|
|
|
37
41
|
for (const msgType of Object.values(MessageType)) {
|
|
@@ -173,6 +177,7 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
173
177
|
ctx.action = action;
|
|
174
178
|
ctx.chatInfo = message.chatInfo;
|
|
175
179
|
ctx.traceId = message.traceId;
|
|
180
|
+
ctx.botInfo = this.botInfo;
|
|
176
181
|
|
|
177
182
|
ctx.isInitialized = true;
|
|
178
183
|
ctx.matchResults = [];
|
|
@@ -207,6 +212,8 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
207
212
|
ctx.action = action;
|
|
208
213
|
ctx.chatInfo = message.chatInfo;
|
|
209
214
|
ctx.traceId = message.traceId;
|
|
215
|
+
ctx.botInfo = this.botInfo;
|
|
216
|
+
ctx.customCooldown = undefined;
|
|
210
217
|
|
|
211
218
|
ctx.logger = this.logger.createScope(
|
|
212
219
|
this.botName,
|