chz-telegram-bot 0.3.17 → 0.3.19
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/builtin/helpAction.ts +8 -5
- package/bun.lock +2 -2
- package/dist/builtin/helpAction.d.ts.map +1 -1
- package/dist/builtin/helpAction.js +7 -5
- package/dist/dtos/ActionPermissionsData.d.ts +7 -0
- package/dist/dtos/ActionPermissionsData.d.ts.map +1 -0
- package/dist/dtos/ActionPermissionsData.js +14 -0
- package/dist/dtos/commandTriggerCheckResult.d.ts +2 -0
- package/dist/dtos/commandTriggerCheckResult.d.ts.map +1 -1
- package/dist/dtos/commandTriggerCheckResult.js +3 -1
- package/dist/entities/actions/commandAction.d.ts +5 -4
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +15 -8
- package/dist/helpers/builders/commandActionBuilder.d.ts +34 -25
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/commandActionBuilder.js +30 -22
- package/dist/helpers/builders/inlineQueryActionBuilder.d.ts +4 -8
- package/dist/helpers/builders/inlineQueryActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/inlineQueryActionBuilder.js +0 -3
- package/dist/helpers/builders/scheduledActionBuilder.d.ts +10 -11
- package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/scheduledActionBuilder.js +4 -4
- package/dist/main.d.ts +3 -3
- package/dist/main.d.ts.map +1 -1
- package/dist/types/capture.d.ts +2 -2
- package/dist/types/capture.d.ts.map +1 -1
- package/dtos/actionPermissionsData.ts +7 -0
- package/dtos/commandTriggerCheckResult.ts +3 -1
- package/entities/actions/commandAction.ts +25 -11
- package/entities/context/chatContext.ts +2 -2
- package/eslint.config.js +5 -1
- package/helpers/builders/commandActionBuilder.ts +51 -40
- package/helpers/builders/inlineQueryActionBuilder.ts +5 -9
- package/helpers/builders/scheduledActionBuilder.ts +14 -11
- package/main.ts +3 -3
- package/package.json +2 -2
- package/types/capture.ts +5 -2
package/builtin/helpAction.ts
CHANGED
|
@@ -2,13 +2,16 @@ import { CommandActionBuilder } from '../helpers/builders/commandActionBuilder';
|
|
|
2
2
|
import { Seconds } from '../types/timeValues';
|
|
3
3
|
|
|
4
4
|
export function buildHelpCommand(readmes: string[], botUsername: string) {
|
|
5
|
-
|
|
5
|
+
const helpCommandBuilder = new CommandActionBuilder('Reaction.Help')
|
|
6
6
|
.on(['/help', `/help@${botUsername}`])
|
|
7
7
|
.do((ctx) => {
|
|
8
|
-
if (readmes.length == 0) return;
|
|
9
|
-
|
|
10
8
|
ctx.reply.withText(readmes.join('\n\n'));
|
|
11
9
|
})
|
|
12
|
-
.
|
|
13
|
-
|
|
10
|
+
.withCooldown({
|
|
11
|
+
seconds: 60 as Seconds
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
if (readmes.length == 0) helpCommandBuilder.disabled();
|
|
15
|
+
|
|
16
|
+
return helpCommandBuilder.build();
|
|
14
17
|
}
|
package/bun.lock
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@types/node": "^22.5.5",
|
|
15
15
|
"eslint": "^9.29.0",
|
|
16
16
|
"globals": "^16.2.0",
|
|
17
|
-
"typescript": "^5.
|
|
17
|
+
"typescript": "^5.9.0-beta",
|
|
18
18
|
"typescript-eslint": "^8.34.1",
|
|
19
19
|
},
|
|
20
20
|
},
|
|
@@ -270,7 +270,7 @@
|
|
|
270
270
|
|
|
271
271
|
"type-check": ["type-check@0.4.0", "", { "dependencies": { "prelude-ls": "^1.2.1" } }, "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew=="],
|
|
272
272
|
|
|
273
|
-
"typescript": ["typescript@5.
|
|
273
|
+
"typescript": ["typescript@5.9.0-beta", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p91qoTdwWKj9YEBYavmGiBn0DF4OBElzw4pW4oPbK4HeCfr/SDz9+yviVWshZXGvGvFCJ3AVQ+J7F1UZXc23QQ=="],
|
|
274
274
|
|
|
275
275
|
"typescript-eslint": ["typescript-eslint@8.34.1", "", { "dependencies": { "@typescript-eslint/eslint-plugin": "8.34.1", "@typescript-eslint/parser": "8.34.1", "@typescript-eslint/utils": "8.34.1" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-XjS+b6Vg9oT1BaIUfkW3M3LvqZE++rbzAMEHuccCfO/YkP43ha6w3jTEMilQxMF92nVOYCcdjv1ZUhAa1D/0ow=="],
|
|
276
276
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpAction.d.ts","sourceRoot":"","sources":["../../builtin/helpAction.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"helpAction.d.ts","sourceRoot":"","sources":["../../builtin/helpAction.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,4DAatE"}
|
|
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildHelpCommand = buildHelpCommand;
|
|
4
4
|
const commandActionBuilder_1 = require("../helpers/builders/commandActionBuilder");
|
|
5
5
|
function buildHelpCommand(readmes, botUsername) {
|
|
6
|
-
|
|
6
|
+
const helpCommandBuilder = new commandActionBuilder_1.CommandActionBuilder('Reaction.Help')
|
|
7
7
|
.on(['/help', `/help@${botUsername}`])
|
|
8
8
|
.do((ctx) => {
|
|
9
|
-
if (readmes.length == 0)
|
|
10
|
-
return;
|
|
11
9
|
ctx.reply.withText(readmes.join('\n\n'));
|
|
12
10
|
})
|
|
13
|
-
.
|
|
14
|
-
|
|
11
|
+
.withCooldown({
|
|
12
|
+
seconds: 60
|
|
13
|
+
});
|
|
14
|
+
if (readmes.length == 0)
|
|
15
|
+
helpCommandBuilder.disabled();
|
|
16
|
+
return helpCommandBuilder.build();
|
|
15
17
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class ActionPermissionsData {
|
|
2
|
+
readonly userIdsWhitelist: number[];
|
|
3
|
+
readonly chatIdsWhitelist: number[];
|
|
4
|
+
readonly chatIdsBlacklist: number[];
|
|
5
|
+
constructor(userIdsWhitelist: number[], chatIdsWhitelist: number[], chatIdsBlacklist: number[]);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=actionPermissionsData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionPermissionsData.d.ts","sourceRoot":"","sources":["../../dtos/actionPermissionsData.ts"],"names":[],"mappings":"AAAA,qBAAa,qBAAqB;IAE1B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,EAAE;IACnC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,EAAE;IACnC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,EAAE;gBAF1B,gBAAgB,EAAE,MAAM,EAAE,EAC1B,gBAAgB,EAAE,MAAM,EAAE,EAC1B,gBAAgB,EAAE,MAAM,EAAE;CAE1C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionPermissionsData = void 0;
|
|
4
|
+
class ActionPermissionsData {
|
|
5
|
+
userIdsWhitelist;
|
|
6
|
+
chatIdsWhitelist;
|
|
7
|
+
chatIdsBlacklist;
|
|
8
|
+
constructor(userIdsWhitelist, chatIdsWhitelist, chatIdsBlacklist) {
|
|
9
|
+
this.userIdsWhitelist = userIdsWhitelist;
|
|
10
|
+
this.chatIdsWhitelist = chatIdsWhitelist;
|
|
11
|
+
this.chatIdsBlacklist = chatIdsBlacklist;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ActionPermissionsData = ActionPermissionsData;
|
|
@@ -5,6 +5,8 @@ declare const _SkipTriggerReasonsObject: {
|
|
|
5
5
|
readonly CustomConditionNotMet: "CustomConditionNotMet";
|
|
6
6
|
readonly TriggerNotSatisfied: "TriggerNotSatisfied";
|
|
7
7
|
readonly Other: "Other";
|
|
8
|
+
readonly ActionDisabled: "ActionDisabled";
|
|
9
|
+
readonly ChatForbidden: "ChatForbidden";
|
|
8
10
|
};
|
|
9
11
|
export type SkipTriggerReasons = keyof typeof _SkipTriggerReasonsObject;
|
|
10
12
|
export declare class CommandTriggerCheckResult {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandTriggerCheckResult.d.ts","sourceRoot":"","sources":["../../dtos/commandTriggerCheckResult.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,yBAAyB
|
|
1
|
+
{"version":3,"file":"commandTriggerCheckResult.d.ts","sourceRoot":"","sources":["../../dtos/commandTriggerCheckResult.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,yBAAyB;;;;;;;;;CASrB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,yBAAyB,CAAC;AAExE,qBAAa,yBAAyB;IAY9B,QAAQ,CAAC,aAAa,EAAE,OAAO;IAC/B,QAAQ,CAAC,YAAY,EAAE,eAAe,EAAE;IACxC,QAAQ,CAAC,YAAY,EAAE,OAAO;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB;IAdxC,MAAM,CAAC,0BAA0B,CAAC,MAAM,EAAE,kBAAkB;IAG5D,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,kBAAkB;IAG9C,MAAM,CAAC,OAAO;gBAKD,aAAa,EAAE,OAAO,EACtB,YAAY,EAAE,eAAe,EAAE,EAC/B,YAAY,EAAE,OAAO,EACrB,MAAM,CAAC,EAAE,kBAAkB,YAAA;IAGxC,SAAS,CAAC,KAAK,EAAE,yBAAyB;CAQ7C"}
|
|
@@ -7,7 +7,9 @@ const _SkipTriggerReasonsObject = {
|
|
|
7
7
|
OnCooldown: 'OnCooldown',
|
|
8
8
|
CustomConditionNotMet: 'CustomConditionNotMet',
|
|
9
9
|
TriggerNotSatisfied: 'TriggerNotSatisfied',
|
|
10
|
-
Other: 'Other'
|
|
10
|
+
Other: 'Other',
|
|
11
|
+
ActionDisabled: 'ActionDisabled',
|
|
12
|
+
ChatForbidden: 'ChatForbidden'
|
|
11
13
|
};
|
|
12
14
|
class CommandTriggerCheckResult {
|
|
13
15
|
shouldExecute;
|
|
@@ -6,7 +6,7 @@ import { MessageContextInternal } from '../context/messageContext';
|
|
|
6
6
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
7
7
|
import { Sema as Semaphore } from 'async-sema';
|
|
8
8
|
import { CooldownInfo } from '../../dtos/cooldownInfo';
|
|
9
|
-
import {
|
|
9
|
+
import { ActionPermissionsData } from '../../dtos/actionPermissionsData';
|
|
10
10
|
export declare class CommandAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
|
|
11
11
|
readonly ratelimitSemaphores: Map<number, Semaphore>;
|
|
12
12
|
readonly triggers: CommandTrigger[];
|
|
@@ -15,14 +15,15 @@ export declare class CommandAction<TActionState extends IActionState> implements
|
|
|
15
15
|
readonly cooldownInfo: CooldownInfo;
|
|
16
16
|
readonly active: boolean;
|
|
17
17
|
readonly chatsBlacklist: number[];
|
|
18
|
-
readonly
|
|
18
|
+
readonly chatsWhitelist: number[];
|
|
19
|
+
readonly usersWhitelist: number[];
|
|
19
20
|
readonly condition: CommandCondition<TActionState>;
|
|
20
21
|
readonly stateConstructor: () => TActionState;
|
|
21
22
|
readonly key: ActionKey;
|
|
22
23
|
readonly readmeFactory: (botName: string) => string;
|
|
23
24
|
readonly maxAllowedSimultaniousExecutions: number;
|
|
24
|
-
lastCustomCooldown
|
|
25
|
-
constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldownInfo: CooldownInfo,
|
|
25
|
+
private lastCustomCooldown;
|
|
26
|
+
constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldownInfo: CooldownInfo, permissionsData: ActionPermissionsData, maxAllowedSimultaniousExecutions: number, condition: CommandCondition<TActionState>, stateConstructor: () => TActionState, readmeFactory: (botName: string) => string);
|
|
26
27
|
exec(ctx: MessageContextInternal<TActionState>): Promise<import("../../types/response").BotResponse[]>;
|
|
27
28
|
private checkIfShouldBeExecuted;
|
|
28
29
|
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;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,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;
|
|
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,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,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;AAIvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEzE,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,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,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,OAAO,CAAC,kBAAkB,CAAsB;gBAG5C,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,eAAe,EAAE,qBAAqB,EACtC,gCAAgC,EAAE,MAAM,EACxC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY,EACpC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM;IAmBxC,IAAI,CAAC,GAAG,EAAE,sBAAsB,CAAC,YAAY,CAAC;IA2EpD,OAAO,CAAC,uBAAuB;IAyD/B,OAAO,CAAC,YAAY;CAuCvB"}
|
|
@@ -22,21 +22,23 @@ class CommandAction {
|
|
|
22
22
|
cooldownInfo;
|
|
23
23
|
active;
|
|
24
24
|
chatsBlacklist;
|
|
25
|
-
|
|
25
|
+
chatsWhitelist;
|
|
26
|
+
usersWhitelist;
|
|
26
27
|
condition;
|
|
27
28
|
stateConstructor;
|
|
28
29
|
key;
|
|
29
30
|
readmeFactory;
|
|
30
31
|
maxAllowedSimultaniousExecutions;
|
|
31
32
|
lastCustomCooldown;
|
|
32
|
-
constructor(trigger, handler, name, active, cooldownInfo,
|
|
33
|
+
constructor(trigger, handler, name, active, cooldownInfo, permissionsData, maxAllowedSimultaniousExecutions, condition, stateConstructor, readmeFactory) {
|
|
33
34
|
this.triggers = (0, toArray_1.toArray)(trigger);
|
|
34
35
|
this.handler = handler;
|
|
35
36
|
this.name = name;
|
|
36
37
|
this.cooldownInfo = cooldownInfo;
|
|
37
38
|
this.active = active;
|
|
38
|
-
this.chatsBlacklist =
|
|
39
|
-
this.
|
|
39
|
+
this.chatsBlacklist = permissionsData.chatIdsBlacklist;
|
|
40
|
+
this.chatsWhitelist = permissionsData.chatIdsWhitelist;
|
|
41
|
+
this.usersWhitelist = permissionsData.userIdsWhitelist;
|
|
40
42
|
this.condition = condition;
|
|
41
43
|
this.stateConstructor = stateConstructor;
|
|
42
44
|
this.readmeFactory = readmeFactory;
|
|
@@ -47,8 +49,6 @@ class CommandAction {
|
|
|
47
49
|
async exec(ctx) {
|
|
48
50
|
if (!ctx.isInitialized)
|
|
49
51
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
50
|
-
if (!this.active || this.chatsBlacklist.includes(ctx.chatInfo.id))
|
|
51
|
-
return noop_1.Noop.NoResponse;
|
|
52
52
|
let lock;
|
|
53
53
|
if (this.maxAllowedSimultaniousExecutions != 0) {
|
|
54
54
|
lock = (0, mapUtils_1.getOrSetIfNotExists)(this.ratelimitSemaphores, ctx.chatInfo.id, new async_sema_1.Sema(this.maxAllowedSimultaniousExecutions));
|
|
@@ -84,13 +84,20 @@ class CommandAction {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
checkIfShouldBeExecuted(ctx, trigger, state) {
|
|
87
|
+
if (!this.active)
|
|
88
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ActionDisabled');
|
|
89
|
+
const isChatInBlacklist = this.chatsBlacklist.includes(ctx.chatInfo.id);
|
|
90
|
+
const isChatInWhitelist = this.chatsWhitelist.length != 0 &&
|
|
91
|
+
this.chatsWhitelist.includes(ctx.chatInfo.id);
|
|
92
|
+
if (isChatInBlacklist || !isChatInWhitelist)
|
|
93
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ChatForbidden');
|
|
87
94
|
const triggerCheckResult = this.checkTrigger(ctx, trigger);
|
|
88
95
|
if (!triggerCheckResult.shouldExecute)
|
|
89
96
|
return triggerCheckResult;
|
|
90
97
|
if (!ctx.userInfo.id)
|
|
91
98
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserIdMissing');
|
|
92
|
-
const isUserAllowed = this.
|
|
93
|
-
this.
|
|
99
|
+
const isUserAllowed = this.usersWhitelist.length == 0 ||
|
|
100
|
+
this.usersWhitelist.includes(ctx.userInfo.id);
|
|
94
101
|
if (!isUserAllowed)
|
|
95
102
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserForbidden');
|
|
96
103
|
const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
|
|
@@ -9,18 +9,19 @@ import { CommandTrigger } from '../../types/commandTrigger';
|
|
|
9
9
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
10
10
|
*/
|
|
11
11
|
export declare class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
12
|
-
name
|
|
13
|
-
trigger
|
|
14
|
-
active
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
allowedUsers
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
private readonly name;
|
|
13
|
+
private trigger;
|
|
14
|
+
private active;
|
|
15
|
+
private cooldownSeconds;
|
|
16
|
+
private blacklist;
|
|
17
|
+
private whitelist;
|
|
18
|
+
private allowedUsers;
|
|
19
|
+
private readmeFactory;
|
|
20
|
+
private readonly stateConstructor;
|
|
21
|
+
private handler;
|
|
22
|
+
private condition;
|
|
23
|
+
private maxAllowedSimultaniousExecutions;
|
|
24
|
+
private cooldownMessage;
|
|
24
25
|
/**
|
|
25
26
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
26
27
|
* @param name Action name, will be used for logging and storage
|
|
@@ -38,6 +39,16 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
38
39
|
* @param id User id or ids
|
|
39
40
|
*/
|
|
40
41
|
from(id: number | number[]): this;
|
|
42
|
+
/**
|
|
43
|
+
* Sets chats whitelist for this action.
|
|
44
|
+
* @param chatIds Chats ids to allow.
|
|
45
|
+
*/
|
|
46
|
+
in(chatIds: number[]): this;
|
|
47
|
+
/**
|
|
48
|
+
* Sets chats blacklist for this action.
|
|
49
|
+
* @param chatIds Chats ids to ignore.
|
|
50
|
+
*/
|
|
51
|
+
notIn(chatIds: number[]): this;
|
|
41
52
|
/** Defines action logic itself, will be executed on trigger.
|
|
42
53
|
* @param handler Callback that will be called on trigger
|
|
43
54
|
*/
|
|
@@ -46,24 +57,22 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
46
57
|
* @param condition Condition check predicate
|
|
47
58
|
*/
|
|
48
59
|
when(condition: CommandCondition<TActionState>): this;
|
|
60
|
+
/**
|
|
61
|
+
* Sets factory method for readme (shown on /help) for this action.
|
|
62
|
+
* @param readmeFactory readme factory
|
|
63
|
+
*/
|
|
49
64
|
withHelp(readmeFactory: (botName: string) => string): this;
|
|
50
65
|
/** If called during building, action is marked as disabled and never checked. */
|
|
51
66
|
disabled(): this;
|
|
52
67
|
/** Sets maximum number of simultaniously executing handlers for this command per chat. 0 is treated as unlimited. */
|
|
53
|
-
|
|
54
|
-
/** Sets action cooldown.
|
|
55
|
-
* @param
|
|
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;
|
|
62
|
-
/**
|
|
63
|
-
* Adds a chat to ignore list for this action.
|
|
64
|
-
* @param chatId Chat id to ignore.
|
|
68
|
+
withRatelimit(maxAllowedSimultaniousExecutions: number): this;
|
|
69
|
+
/** Sets action cooldown settings.
|
|
70
|
+
* @param cooldownSettings Settings.
|
|
65
71
|
*/
|
|
66
|
-
|
|
72
|
+
withCooldown(cooldownSettings: {
|
|
73
|
+
seconds: Seconds;
|
|
74
|
+
message?: string;
|
|
75
|
+
}): this;
|
|
67
76
|
/** Builds action */
|
|
68
77
|
build(): CommandAction<TActionState>;
|
|
69
78
|
}
|
|
@@ -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;AAI5D;;GAEG;AACH,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,OAAO,CAAyC;IAExD,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,aAAa,CAAiD;IACtE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;IACtD,OAAO,CAAC,OAAO,CAA2C;IAC1D,OAAO,CAAC,SAAS,CAA6C;IAC9D,OAAO,CAAC,gCAAgC,CAAa;IACrD,OAAO,CAAC,eAAe,CAAqB;IAE5C;;;;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;;;OAGG;IACH,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE;IAMpB;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE;IAMvB;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC;IAMxC;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAM9C;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM;IAMnD,iFAAiF;IACjF,QAAQ;IAMR,qHAAqH;IACrH,aAAa,CAAC,gCAAgC,EAAE,MAAM;IAOtD;;OAEG;IACH,YAAY,CAAC,gBAAgB,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAOrE,oBAAoB;IACpB,KAAK;CAkBR;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,6BAA6B,CAAC,eAAe,CAAC;IACpF;;OAEG;gBACS,IAAI,EAAE,MAAM;CAG3B"}
|
|
@@ -6,6 +6,7 @@ const actionStateBase_1 = require("../../entities/states/actionStateBase");
|
|
|
6
6
|
const toArray_1 = require("../toArray");
|
|
7
7
|
const noop_1 = require("../noop");
|
|
8
8
|
const cooldownInfo_1 = require("../../dtos/cooldownInfo");
|
|
9
|
+
const actionPermissionsData_1 = require("../../dtos/actionPermissionsData");
|
|
9
10
|
/**
|
|
10
11
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
11
12
|
*/
|
|
@@ -13,10 +14,11 @@ class CommandActionBuilderWithState {
|
|
|
13
14
|
name;
|
|
14
15
|
trigger = [];
|
|
15
16
|
active = true;
|
|
16
|
-
readmeFactory = null;
|
|
17
17
|
cooldownSeconds = 0;
|
|
18
18
|
blacklist = [];
|
|
19
|
+
whitelist = [];
|
|
19
20
|
allowedUsers = [];
|
|
21
|
+
readmeFactory = noop_1.Noop.emptyString;
|
|
20
22
|
stateConstructor;
|
|
21
23
|
handler = noop_1.Noop.call;
|
|
22
24
|
condition = noop_1.Noop.true;
|
|
@@ -48,6 +50,22 @@ class CommandActionBuilderWithState {
|
|
|
48
50
|
this.allowedUsers = (0, toArray_1.toArray)(id);
|
|
49
51
|
return this;
|
|
50
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Sets chats whitelist for this action.
|
|
55
|
+
* @param chatIds Chats ids to allow.
|
|
56
|
+
*/
|
|
57
|
+
in(chatIds) {
|
|
58
|
+
this.whitelist = chatIds;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sets chats blacklist for this action.
|
|
63
|
+
* @param chatIds Chats ids to ignore.
|
|
64
|
+
*/
|
|
65
|
+
notIn(chatIds) {
|
|
66
|
+
this.blacklist = chatIds;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
51
69
|
/** Defines action logic itself, will be executed on trigger.
|
|
52
70
|
* @param handler Callback that will be called on trigger
|
|
53
71
|
*/
|
|
@@ -62,6 +80,10 @@ class CommandActionBuilderWithState {
|
|
|
62
80
|
this.condition = condition;
|
|
63
81
|
return this;
|
|
64
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Sets factory method for readme (shown on /help) for this action.
|
|
85
|
+
* @param readmeFactory readme factory
|
|
86
|
+
*/
|
|
65
87
|
withHelp(readmeFactory) {
|
|
66
88
|
this.readmeFactory = readmeFactory;
|
|
67
89
|
return this;
|
|
@@ -72,36 +94,22 @@ class CommandActionBuilderWithState {
|
|
|
72
94
|
return this;
|
|
73
95
|
}
|
|
74
96
|
/** Sets maximum number of simultaniously executing handlers for this command per chat. 0 is treated as unlimited. */
|
|
75
|
-
|
|
97
|
+
withRatelimit(maxAllowedSimultaniousExecutions) {
|
|
76
98
|
this.maxAllowedSimultaniousExecutions =
|
|
77
99
|
maxAllowedSimultaniousExecutions;
|
|
78
100
|
return this;
|
|
79
101
|
}
|
|
80
|
-
/** Sets action cooldown.
|
|
81
|
-
* @param
|
|
82
|
-
*/
|
|
83
|
-
cooldown(seconds) {
|
|
84
|
-
this.cooldownSeconds = seconds;
|
|
85
|
-
return this;
|
|
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
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Adds a chat to ignore list for this action.
|
|
96
|
-
* @param chatId Chat id to ignore.
|
|
102
|
+
/** Sets action cooldown settings.
|
|
103
|
+
* @param cooldownSettings Settings.
|
|
97
104
|
*/
|
|
98
|
-
|
|
99
|
-
this.
|
|
105
|
+
withCooldown(cooldownSettings) {
|
|
106
|
+
this.cooldownSeconds = cooldownSettings.seconds;
|
|
107
|
+
this.cooldownMessage = cooldownSettings.message;
|
|
100
108
|
return this;
|
|
101
109
|
}
|
|
102
110
|
/** Builds action */
|
|
103
111
|
build() {
|
|
104
|
-
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, new cooldownInfo_1.CooldownInfo(this.cooldownSeconds, this.cooldownMessage), this.
|
|
112
|
+
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, new cooldownInfo_1.CooldownInfo(this.cooldownSeconds, this.cooldownMessage), new actionPermissionsData_1.ActionPermissionsData(this.allowedUsers, this.whitelist, this.blacklist), this.maxAllowedSimultaniousExecutions, this.condition, this.stateConstructor, this.readmeFactory);
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
115
|
exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { InlineQueryHandler } from '../../types/handlers';
|
|
2
|
-
import { Seconds } from '../../types/timeValues';
|
|
3
2
|
import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
|
|
4
3
|
/**
|
|
5
4
|
* Builder for `InlineQueryAction`
|
|
6
5
|
*/
|
|
7
6
|
export declare class InlineQueryActionBuilder {
|
|
8
|
-
name
|
|
9
|
-
pattern
|
|
10
|
-
active
|
|
11
|
-
|
|
12
|
-
blacklist: number[];
|
|
13
|
-
allowedUsers: number[];
|
|
14
|
-
handler: InlineQueryHandler;
|
|
7
|
+
private readonly name;
|
|
8
|
+
private pattern;
|
|
9
|
+
private active;
|
|
10
|
+
private handler;
|
|
15
11
|
/**
|
|
16
12
|
* Builder for `InlineQueryAction`
|
|
17
13
|
* @param name Action name, will be used for logging and storage
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inlineQueryActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/inlineQueryActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"inlineQueryActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/inlineQueryActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAE7E;;GAEG;AACH,qBAAa,wBAAwB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,OAAO,CAAkB;IAEjC,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAiC;IAEhD;;;OAGG;gBACS,IAAI,EAAE,MAAM;IAIxB;;;OAGG;IACH,EAAE,CAAC,OAAO,EAAE,MAAM;IAMlB;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,kBAAkB;IAM9B,iFAAiF;IACjF,QAAQ;IAMR,oBAAoB;IACpB,KAAK;CAQR"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ScheduledAction } from '../../entities/actions/scheduledAction';
|
|
2
|
-
import { CachedStateFactory } from '../../entities/cachedStateFactory';
|
|
3
2
|
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
4
3
|
import { IActionState } from '../../types/actionState';
|
|
5
4
|
import { ScheduledHandler } from '../../types/handlers';
|
|
@@ -8,13 +7,13 @@ import { Hours, HoursOfDay } from '../../types/timeValues';
|
|
|
8
7
|
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
9
8
|
*/
|
|
10
9
|
export declare class ScheduledActionBuilderWithState<TActionState extends IActionState> {
|
|
11
|
-
active
|
|
12
|
-
time
|
|
13
|
-
|
|
14
|
-
whitelist
|
|
15
|
-
|
|
16
|
-
handler
|
|
17
|
-
name
|
|
10
|
+
private active;
|
|
11
|
+
private time;
|
|
12
|
+
private readonly cachedStateFactories;
|
|
13
|
+
private whitelist;
|
|
14
|
+
private readonly stateConstructor;
|
|
15
|
+
private handler;
|
|
16
|
+
private readonly name;
|
|
18
17
|
/**
|
|
19
18
|
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
20
19
|
* @param name Action name, will be used for logging and storage
|
|
@@ -22,10 +21,10 @@ export declare class ScheduledActionBuilderWithState<TActionState extends IActio
|
|
|
22
21
|
*/
|
|
23
22
|
constructor(name: string, stateConstructor: () => TActionState);
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @param
|
|
24
|
+
* Sets whitelist for this action.
|
|
25
|
+
* @param chatIds Chat ids to execute in.
|
|
27
26
|
*/
|
|
28
|
-
|
|
27
|
+
in(chatIds: number[]): this;
|
|
29
28
|
/**
|
|
30
29
|
* Defines time for scheduled item execution.
|
|
31
30
|
* @param time Time of day (0 - 23) to execute action.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduledActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/scheduledActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduledActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/scheduledActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAG3D;;GAEG;AACH,qBAAa,+BAA+B,CACxC,YAAY,SAAS,YAAY;IAEjC,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAGjC;IACJ,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;IACtD,OAAO,CAAC,OAAO,CAA6C;IAE5D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B;;;;OAIG;gBACS,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,YAAY;IAK9D;;;OAGG;IACH,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE;IAMpB;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU;IAMtB;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAM1C;;;;;;OAMG;IACH,eAAe,CACX,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EACnC,0BAA0B,GAAE,KAAmB;IAUnD,iFAAiF;IACjF,QAAQ;IAMR,oBAAoB;IACpB,KAAK;CAWR;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,+BAA+B,CAAC,eAAe,CAAC;IACxF;;OAEG;gBACS,IAAI,EAAE,MAAM;CAG3B"}
|
|
@@ -26,11 +26,11 @@ class ScheduledActionBuilderWithState {
|
|
|
26
26
|
this.stateConstructor = stateConstructor;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @param
|
|
29
|
+
* Sets whitelist for this action.
|
|
30
|
+
* @param chatIds Chat ids to execute in.
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
this.whitelist
|
|
32
|
+
in(chatIds) {
|
|
33
|
+
this.whitelist = chatIds;
|
|
34
34
|
return this;
|
|
35
35
|
}
|
|
36
36
|
/**
|
package/dist/main.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { BotInstance } from './entities/botInstance';
|
|
|
5
5
|
import { Seconds } from './types/timeValues';
|
|
6
6
|
import { IScheduler } from './types/scheduler';
|
|
7
7
|
import { ILogger } from './types/logger';
|
|
8
|
-
import { ActionStateBase } from './entities/states/actionStateBase';
|
|
9
8
|
import { InlineQueryAction } from './entities/actions/inlineQueryAction';
|
|
9
|
+
import { IActionState } from './types/actionState';
|
|
10
10
|
declare class BotOrchestrator {
|
|
11
11
|
bots: BotInstance[];
|
|
12
12
|
/**
|
|
@@ -19,9 +19,9 @@ declare class BotOrchestrator {
|
|
|
19
19
|
tokenFilePath: string;
|
|
20
20
|
actions: {
|
|
21
21
|
/** Collection of actions that will be executed as a response to message from used. Created using `CommandActionBuilder`.*/
|
|
22
|
-
commands: CommandAction<
|
|
22
|
+
commands: CommandAction<IActionState>[];
|
|
23
23
|
/** Collection of actions that will be executed on timer. Created using `ScheduledActionBuilder`.*/
|
|
24
|
-
scheduled: ScheduledAction<
|
|
24
|
+
scheduled: ScheduledAction<IActionState>[];
|
|
25
25
|
/** Collection of actions that will handle inline queries */
|
|
26
26
|
inlineQueries: InlineQueryAction[];
|
|
27
27
|
};
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,cAAM,eAAe;IACjB,IAAI,EAAE,WAAW,EAAE,CAAM;IAEzB;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE;QACpB,gCAAgC;QAChC,IAAI,EAAE,MAAM,CAAC;QACb,kDAAkD;QAClD,aAAa,EAAE,MAAM,CAAC;QACtB,OAAO,EAAE;YACL,2HAA2H;YAC3H,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;YACxC,mGAAmG;YACnG,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;YAC3C,4DAA4D;YAC5D,aAAa,EAAE,iBAAiB,EAAE,CAAC;SACtC,CAAC;QACF,yGAAyG;QACzG,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,2KAA2K;QAC3K,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,6DAA6D;QAC7D,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,+EAA+E;QAC/E,gCAAgC,CAAC,EAAE,OAAO,CAAC;QAC3C,QAAQ,CAAC,EAAE;YACP,qGAAqG;YACrG,aAAa,CAAC,EAAE,cAAc,CAAC;YAC/B,8FAA8F;YAC9F,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,yGAAyG;YACzG,SAAS,CAAC,EAAE,UAAU,CAAC;SAC1B,CAAC;KACL;IA0BD;;OAEG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM;CAKhC;AAED,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|
package/dist/types/capture.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReplyContextInternal } from '../entities/context/replyContext';
|
|
1
|
+
import { ReplyContext, ReplyContextInternal } from '../entities/context/replyContext';
|
|
2
2
|
import { IActionState } from './actionState';
|
|
3
3
|
import { CommandTrigger } from './commandTrigger';
|
|
4
4
|
import { IActionWithState } from './action';
|
|
@@ -11,7 +11,7 @@ export interface ICaptureController {
|
|
|
11
11
|
*/
|
|
12
12
|
trigger: CommandTrigger[],
|
|
13
13
|
/** Callback that will be called on trigger */
|
|
14
|
-
handler: (replyContext:
|
|
14
|
+
handler: (replyContext: ReplyContext<TParentActionState>) => Promise<void>,
|
|
15
15
|
/** Abort controller to abort capturing manually */
|
|
16
16
|
abortController: AbortController) => void;
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../types/capture.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,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,gBAAgB,CAAC,YAAY,CAAC,CAAC;CAC1C"}
|
|
@@ -4,7 +4,9 @@ const _SkipTriggerReasonsObject = {
|
|
|
4
4
|
OnCooldown: 'OnCooldown',
|
|
5
5
|
CustomConditionNotMet: 'CustomConditionNotMet',
|
|
6
6
|
TriggerNotSatisfied: 'TriggerNotSatisfied',
|
|
7
|
-
Other: 'Other'
|
|
7
|
+
Other: 'Other',
|
|
8
|
+
ActionDisabled: 'ActionDisabled',
|
|
9
|
+
ChatForbidden: 'ChatForbidden'
|
|
8
10
|
} as const;
|
|
9
11
|
|
|
10
12
|
export type SkipTriggerReasons = keyof typeof _SkipTriggerReasonsObject;
|
|
@@ -16,6 +16,7 @@ import { CooldownInfo } from '../../dtos/cooldownInfo';
|
|
|
16
16
|
import { TextMessage } from '../../dtos/responses/textMessage';
|
|
17
17
|
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
18
18
|
import { Seconds } from '../../types/timeValues';
|
|
19
|
+
import { ActionPermissionsData } from '../../dtos/actionPermissionsData';
|
|
19
20
|
|
|
20
21
|
export class CommandAction<TActionState extends IActionState>
|
|
21
22
|
implements IActionWithState<TActionState>
|
|
@@ -28,14 +29,15 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
28
29
|
readonly cooldownInfo: CooldownInfo;
|
|
29
30
|
readonly active: boolean;
|
|
30
31
|
readonly chatsBlacklist: number[];
|
|
31
|
-
readonly
|
|
32
|
+
readonly chatsWhitelist: number[];
|
|
33
|
+
readonly usersWhitelist: number[];
|
|
32
34
|
readonly condition: CommandCondition<TActionState>;
|
|
33
35
|
readonly stateConstructor: () => TActionState;
|
|
34
36
|
readonly key: ActionKey;
|
|
35
37
|
readonly readmeFactory: (botName: string) => string;
|
|
36
38
|
readonly maxAllowedSimultaniousExecutions: number;
|
|
37
39
|
|
|
38
|
-
lastCustomCooldown: Seconds | undefined;
|
|
40
|
+
private lastCustomCooldown: Seconds | undefined;
|
|
39
41
|
|
|
40
42
|
constructor(
|
|
41
43
|
trigger: CommandTrigger | CommandTrigger[],
|
|
@@ -43,8 +45,7 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
43
45
|
name: string,
|
|
44
46
|
active: boolean,
|
|
45
47
|
cooldownInfo: CooldownInfo,
|
|
46
|
-
|
|
47
|
-
allowedUsers: number[],
|
|
48
|
+
permissionsData: ActionPermissionsData,
|
|
48
49
|
maxAllowedSimultaniousExecutions: number,
|
|
49
50
|
condition: CommandCondition<TActionState>,
|
|
50
51
|
stateConstructor: () => TActionState,
|
|
@@ -55,8 +56,9 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
55
56
|
this.name = name;
|
|
56
57
|
this.cooldownInfo = cooldownInfo;
|
|
57
58
|
this.active = active;
|
|
58
|
-
this.chatsBlacklist =
|
|
59
|
-
this.
|
|
59
|
+
this.chatsBlacklist = permissionsData.chatIdsBlacklist;
|
|
60
|
+
this.chatsWhitelist = permissionsData.chatIdsWhitelist;
|
|
61
|
+
this.usersWhitelist = permissionsData.userIdsWhitelist;
|
|
60
62
|
this.condition = condition;
|
|
61
63
|
this.stateConstructor = stateConstructor;
|
|
62
64
|
this.readmeFactory = readmeFactory;
|
|
@@ -72,9 +74,6 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
72
74
|
`Context for ${this.key} is not initialized or already consumed`
|
|
73
75
|
);
|
|
74
76
|
|
|
75
|
-
if (!this.active || this.chatsBlacklist.includes(ctx.chatInfo.id))
|
|
76
|
-
return Noop.NoResponse;
|
|
77
|
-
|
|
78
77
|
let lock: Semaphore | undefined;
|
|
79
78
|
if (this.maxAllowedSimultaniousExecutions != 0) {
|
|
80
79
|
lock = getOrSetIfNotExists(
|
|
@@ -149,6 +148,21 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
149
148
|
trigger: CommandTrigger,
|
|
150
149
|
state: TActionState
|
|
151
150
|
) {
|
|
151
|
+
if (!this.active)
|
|
152
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown(
|
|
153
|
+
'ActionDisabled'
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const isChatInBlacklist = this.chatsBlacklist.includes(ctx.chatInfo.id);
|
|
157
|
+
const isChatInWhitelist =
|
|
158
|
+
this.chatsWhitelist.length != 0 &&
|
|
159
|
+
this.chatsWhitelist.includes(ctx.chatInfo.id);
|
|
160
|
+
|
|
161
|
+
if (isChatInBlacklist || !isChatInWhitelist)
|
|
162
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown(
|
|
163
|
+
'ChatForbidden'
|
|
164
|
+
);
|
|
165
|
+
|
|
152
166
|
const triggerCheckResult = this.checkTrigger(ctx, trigger);
|
|
153
167
|
|
|
154
168
|
if (!triggerCheckResult.shouldExecute) return triggerCheckResult;
|
|
@@ -159,8 +173,8 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
159
173
|
);
|
|
160
174
|
|
|
161
175
|
const isUserAllowed =
|
|
162
|
-
this.
|
|
163
|
-
this.
|
|
176
|
+
this.usersWhitelist.length == 0 ||
|
|
177
|
+
this.usersWhitelist.includes(ctx.userInfo.id);
|
|
164
178
|
|
|
165
179
|
if (!isUserAllowed)
|
|
166
180
|
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown(
|
|
@@ -14,7 +14,7 @@ import { Milliseconds } from '../../types/timeValues';
|
|
|
14
14
|
import { DelayResponse } from '../../dtos/responses/delay';
|
|
15
15
|
import { ICaptureController } from '../../types/capture';
|
|
16
16
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
17
|
-
import {
|
|
17
|
+
import { ReplyContext } from './replyContext';
|
|
18
18
|
import {
|
|
19
19
|
BaseContextInternal,
|
|
20
20
|
BaseContextPropertiesToOmit
|
|
@@ -43,7 +43,7 @@ export class ChatContextInternal<
|
|
|
43
43
|
captureReplies: (
|
|
44
44
|
trigger: CommandTrigger[],
|
|
45
45
|
handler: (
|
|
46
|
-
replyContext:
|
|
46
|
+
replyContext: ReplyContext<TActionState>
|
|
47
47
|
) => Promise<void>,
|
|
48
48
|
abortController: AbortController
|
|
49
49
|
) => {
|
package/eslint.config.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import eslint from '@eslint/js';
|
|
2
2
|
import tseslint from 'typescript-eslint';
|
|
3
|
+
import parser from '@typescript-eslint/parser';
|
|
3
4
|
|
|
4
5
|
export default tseslint.config(
|
|
5
6
|
eslint.configs.recommended,
|
|
6
|
-
|
|
7
|
+
tseslint.configs.strictTypeChecked,
|
|
7
8
|
{
|
|
8
9
|
languageOptions: {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
11
|
+
parser,
|
|
9
12
|
parserOptions: {
|
|
10
13
|
project: './tsconfig.json',
|
|
14
|
+
tsconfigRootDir: import.meta.dirname,
|
|
11
15
|
sourceType: 'module'
|
|
12
16
|
}
|
|
13
17
|
},
|
|
@@ -8,24 +8,26 @@ import { toArray } from '../toArray';
|
|
|
8
8
|
import { Noop } from '../noop';
|
|
9
9
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
10
10
|
import { CooldownInfo } from '../../dtos/cooldownInfo';
|
|
11
|
+
import { ActionPermissionsData } from '../../dtos/actionPermissionsData';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
14
15
|
*/
|
|
15
16
|
export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
16
|
-
name: string;
|
|
17
|
-
trigger: CommandTrigger | CommandTrigger[] = [];
|
|
18
|
-
|
|
19
|
-
active = true;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
allowedUsers: number[] = [];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
private readonly name: string;
|
|
18
|
+
private trigger: CommandTrigger | CommandTrigger[] = [];
|
|
19
|
+
|
|
20
|
+
private active = true;
|
|
21
|
+
private cooldownSeconds: Seconds = 0 as Seconds;
|
|
22
|
+
private blacklist: number[] = [];
|
|
23
|
+
private whitelist: number[] = [];
|
|
24
|
+
private allowedUsers: number[] = [];
|
|
25
|
+
private readmeFactory: (botName: string) => string = Noop.emptyString;
|
|
26
|
+
private readonly stateConstructor: () => TActionState;
|
|
27
|
+
private handler: CommandHandler<TActionState> = Noop.call;
|
|
28
|
+
private condition: CommandCondition<TActionState> = Noop.true;
|
|
29
|
+
private maxAllowedSimultaniousExecutions: number = 0;
|
|
30
|
+
private cooldownMessage: string | undefined;
|
|
29
31
|
|
|
30
32
|
/**
|
|
31
33
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
@@ -58,6 +60,26 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
58
60
|
return this;
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Sets chats whitelist for this action.
|
|
65
|
+
* @param chatIds Chats ids to allow.
|
|
66
|
+
*/
|
|
67
|
+
in(chatIds: number[]) {
|
|
68
|
+
this.whitelist = chatIds;
|
|
69
|
+
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Sets chats blacklist for this action.
|
|
75
|
+
* @param chatIds Chats ids to ignore.
|
|
76
|
+
*/
|
|
77
|
+
notIn(chatIds: number[]) {
|
|
78
|
+
this.blacklist = chatIds;
|
|
79
|
+
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
61
83
|
/** Defines action logic itself, will be executed on trigger.
|
|
62
84
|
* @param handler Callback that will be called on trigger
|
|
63
85
|
*/
|
|
@@ -76,6 +98,10 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
76
98
|
return this;
|
|
77
99
|
}
|
|
78
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Sets factory method for readme (shown on /help) for this action.
|
|
103
|
+
* @param readmeFactory readme factory
|
|
104
|
+
*/
|
|
79
105
|
withHelp(readmeFactory: (botName: string) => string) {
|
|
80
106
|
this.readmeFactory = readmeFactory;
|
|
81
107
|
|
|
@@ -90,37 +116,19 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
90
116
|
}
|
|
91
117
|
|
|
92
118
|
/** Sets maximum number of simultaniously executing handlers for this command per chat. 0 is treated as unlimited. */
|
|
93
|
-
|
|
119
|
+
withRatelimit(maxAllowedSimultaniousExecutions: number) {
|
|
94
120
|
this.maxAllowedSimultaniousExecutions =
|
|
95
121
|
maxAllowedSimultaniousExecutions;
|
|
96
122
|
|
|
97
123
|
return this;
|
|
98
124
|
}
|
|
99
125
|
|
|
100
|
-
/** Sets action cooldown.
|
|
101
|
-
* @param
|
|
102
|
-
*/
|
|
103
|
-
cooldown(seconds: Seconds) {
|
|
104
|
-
this.cooldownSeconds = seconds;
|
|
105
|
-
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
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
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Adds a chat to ignore list for this action.
|
|
120
|
-
* @param chatId Chat id to ignore.
|
|
126
|
+
/** Sets action cooldown settings.
|
|
127
|
+
* @param cooldownSettings Settings.
|
|
121
128
|
*/
|
|
122
|
-
|
|
123
|
-
this.
|
|
129
|
+
withCooldown(cooldownSettings: { seconds: Seconds; message?: string }) {
|
|
130
|
+
this.cooldownSeconds = cooldownSettings.seconds;
|
|
131
|
+
this.cooldownMessage = cooldownSettings.message;
|
|
124
132
|
|
|
125
133
|
return this;
|
|
126
134
|
}
|
|
@@ -133,12 +141,15 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
133
141
|
this.name,
|
|
134
142
|
this.active,
|
|
135
143
|
new CooldownInfo(this.cooldownSeconds, this.cooldownMessage),
|
|
136
|
-
|
|
137
|
-
|
|
144
|
+
new ActionPermissionsData(
|
|
145
|
+
this.allowedUsers,
|
|
146
|
+
this.whitelist,
|
|
147
|
+
this.blacklist
|
|
148
|
+
),
|
|
138
149
|
this.maxAllowedSimultaniousExecutions,
|
|
139
150
|
this.condition,
|
|
140
151
|
this.stateConstructor,
|
|
141
|
-
this.readmeFactory
|
|
152
|
+
this.readmeFactory
|
|
142
153
|
);
|
|
143
154
|
}
|
|
144
155
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { InlineQueryHandler } from '../../types/handlers';
|
|
2
|
-
import { Seconds } from '../../types/timeValues';
|
|
3
2
|
import { Noop } from '../noop';
|
|
4
3
|
import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
|
|
5
4
|
|
|
@@ -7,14 +6,11 @@ import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
|
|
|
7
6
|
* Builder for `InlineQueryAction`
|
|
8
7
|
*/
|
|
9
8
|
export class InlineQueryActionBuilder {
|
|
10
|
-
name: string;
|
|
11
|
-
pattern: RegExp = /.+/gi;
|
|
12
|
-
|
|
13
|
-
active = true;
|
|
14
|
-
|
|
15
|
-
blacklist: number[] = [];
|
|
16
|
-
allowedUsers: number[] = [];
|
|
17
|
-
handler: InlineQueryHandler = Noop.call;
|
|
9
|
+
private readonly name: string;
|
|
10
|
+
private pattern: RegExp = /.+/gi;
|
|
11
|
+
|
|
12
|
+
private active = true;
|
|
13
|
+
private handler: InlineQueryHandler = Noop.call;
|
|
18
14
|
|
|
19
15
|
/**
|
|
20
16
|
* Builder for `InlineQueryAction`
|
|
@@ -12,14 +12,17 @@ import { Noop } from '../noop';
|
|
|
12
12
|
export class ScheduledActionBuilderWithState<
|
|
13
13
|
TActionState extends IActionState
|
|
14
14
|
> {
|
|
15
|
-
active = true;
|
|
16
|
-
time: HoursOfDay = 0;
|
|
17
|
-
cachedStateFactories = new Map<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
private active = true;
|
|
16
|
+
private time: HoursOfDay = 0;
|
|
17
|
+
private readonly cachedStateFactories = new Map<
|
|
18
|
+
string,
|
|
19
|
+
CachedStateFactory
|
|
20
|
+
>();
|
|
21
|
+
private whitelist: number[] = [];
|
|
22
|
+
private readonly stateConstructor: () => TActionState;
|
|
23
|
+
private handler: ScheduledHandler<TActionState> = Noop.call;
|
|
21
24
|
|
|
22
|
-
name: string;
|
|
25
|
+
private readonly name: string;
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
@@ -32,11 +35,11 @@ export class ScheduledActionBuilderWithState<
|
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param
|
|
38
|
+
* Sets whitelist for this action.
|
|
39
|
+
* @param chatIds Chat ids to execute in.
|
|
37
40
|
*/
|
|
38
|
-
|
|
39
|
-
this.whitelist
|
|
41
|
+
in(chatIds: number[]) {
|
|
42
|
+
this.whitelist = chatIds;
|
|
40
43
|
|
|
41
44
|
return this;
|
|
42
45
|
}
|
package/main.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { BotInstance } from './entities/botInstance';
|
|
|
6
6
|
import { Seconds } from './types/timeValues';
|
|
7
7
|
import { IScheduler } from './types/scheduler';
|
|
8
8
|
import { ILogger } from './types/logger';
|
|
9
|
-
import { ActionStateBase } from './entities/states/actionStateBase';
|
|
10
9
|
import { InlineQueryAction } from './entities/actions/inlineQueryAction';
|
|
10
|
+
import { IActionState } from './types/actionState';
|
|
11
11
|
|
|
12
12
|
class BotOrchestrator {
|
|
13
13
|
bots: BotInstance[] = [];
|
|
@@ -22,9 +22,9 @@ class BotOrchestrator {
|
|
|
22
22
|
tokenFilePath: string;
|
|
23
23
|
actions: {
|
|
24
24
|
/** Collection of actions that will be executed as a response to message from used. Created using `CommandActionBuilder`.*/
|
|
25
|
-
commands: CommandAction<
|
|
25
|
+
commands: CommandAction<IActionState>[];
|
|
26
26
|
/** Collection of actions that will be executed on timer. Created using `ScheduledActionBuilder`.*/
|
|
27
|
-
scheduled: ScheduledAction<
|
|
27
|
+
scheduled: ScheduledAction<IActionState>[];
|
|
28
28
|
/** Collection of actions that will handle inline queries */
|
|
29
29
|
inlineQueries: InlineQueryAction[];
|
|
30
30
|
};
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "https://github.com/AlexSolari/botFramework.git"
|
|
16
16
|
},
|
|
17
|
-
"version": "0.3.
|
|
17
|
+
"version": "0.3.19",
|
|
18
18
|
"type": "module",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"async-sema": "^3.1.1",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@types/node": "^22.5.5",
|
|
30
30
|
"eslint": "^9.29.0",
|
|
31
31
|
"globals": "^16.2.0",
|
|
32
|
-
"typescript": "^5.
|
|
32
|
+
"typescript": "^5.9.0-beta",
|
|
33
33
|
"typescript-eslint": "^8.34.1"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
package/types/capture.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ReplyContext,
|
|
3
|
+
ReplyContextInternal
|
|
4
|
+
} from '../entities/context/replyContext';
|
|
2
5
|
import { IActionState } from './actionState';
|
|
3
6
|
import { CommandTrigger } from './commandTrigger';
|
|
4
7
|
import { IActionWithState } from './action';
|
|
@@ -13,7 +16,7 @@ export interface ICaptureController {
|
|
|
13
16
|
trigger: CommandTrigger[],
|
|
14
17
|
/** Callback that will be called on trigger */
|
|
15
18
|
handler: (
|
|
16
|
-
replyContext:
|
|
19
|
+
replyContext: ReplyContext<TParentActionState>
|
|
17
20
|
) => Promise<void>,
|
|
18
21
|
/** Abort controller to abort capturing manually */
|
|
19
22
|
abortController: AbortController
|