chz-telegram-bot 0.3.25 → 0.3.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builtin/helpAction.ts +1 -1
- package/dist/builtin/helpAction.js +1 -1
- package/dist/dtos/cooldownInfo.d.ts +6 -6
- package/dist/dtos/cooldownInfo.d.ts.map +1 -1
- package/dist/dtos/cooldownInfo.js +4 -4
- package/dist/dtos/propertyProviderSets.d.ts +16 -0
- package/dist/dtos/propertyProviderSets.d.ts.map +1 -0
- package/dist/dtos/propertyProviderSets.js +2 -0
- package/dist/entities/actions/commandAction.d.ts +12 -12
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +33 -26
- package/dist/entities/actions/inlineQueryAction.d.ts +3 -2
- package/dist/entities/actions/inlineQueryAction.d.ts.map +1 -1
- package/dist/entities/actions/inlineQueryAction.js +4 -4
- package/dist/entities/actions/scheduledAction.d.ts +5 -5
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
- package/dist/entities/actions/scheduledAction.js +14 -13
- package/dist/entities/context/baseContext.d.ts +1 -1
- package/dist/entities/context/baseContext.d.ts.map +1 -1
- package/dist/helpers/builders/commandActionBuilder.d.ts +18 -7
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/commandActionBuilder.js +35 -14
- package/dist/helpers/builders/inlineQueryActionBuilder.d.ts +8 -1
- package/dist/helpers/builders/inlineQueryActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/inlineQueryActionBuilder.js +11 -3
- package/dist/helpers/builders/scheduledActionBuilder.d.ts +13 -4
- package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/scheduledActionBuilder.js +24 -8
- package/dist/types/propertyProvider.d.ts +8 -0
- package/dist/types/propertyProvider.d.ts.map +1 -0
- package/dist/types/propertyProvider.js +2 -0
- package/dtos/cooldownInfo.ts +3 -3
- package/dtos/propertyProviderSets.ts +20 -0
- package/entities/actions/commandAction.ts +59 -36
- package/entities/actions/inlineQueryAction.ts +5 -4
- package/entities/actions/scheduledAction.ts +26 -15
- package/entities/context/baseContext.ts +1 -2
- package/helpers/builders/commandActionBuilder.ts +57 -21
- package/helpers/builders/inlineQueryActionBuilder.ts +16 -3
- package/helpers/builders/scheduledActionBuilder.ts +36 -10
- package/package.json +44 -44
- package/types/propertyProvider.ts +14 -0
- package/dist/dtos/actionPermissionsData.d.ts +0 -7
- package/dist/dtos/actionPermissionsData.d.ts.map +0 -1
- package/dist/dtos/actionPermissionsData.js +0 -14
- package/dtos/actionPermissionsData.ts +0 -7
package/builtin/helpAction.ts
CHANGED
|
@@ -8,7 +8,7 @@ export function buildHelpCommand(readmes: string[], botUsername: string) {
|
|
|
8
8
|
ctx.reply.withText(readmes.join('\n\n'));
|
|
9
9
|
})
|
|
10
10
|
.withCooldown({
|
|
11
|
-
|
|
11
|
+
cooldown: 60 as Seconds
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
if (readmes.length == 0) helpCommandBuilder.disabled();
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Seconds } from '../types/timeValues';
|
|
2
2
|
export declare class CooldownInfo {
|
|
3
|
-
/**
|
|
4
|
-
readonly
|
|
3
|
+
/** Cooldown configuration */
|
|
4
|
+
readonly cooldown: Seconds;
|
|
5
5
|
/** Cooldown message to be shown */
|
|
6
|
-
readonly message
|
|
6
|
+
readonly message?: string | undefined;
|
|
7
7
|
constructor(
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/** Cooldown configuration */
|
|
9
|
+
cooldown: Seconds,
|
|
10
10
|
/** Cooldown message to be shown */
|
|
11
|
-
message
|
|
11
|
+
message?: string | undefined);
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=cooldownInfo.d.ts.map
|
|
@@ -1 +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;IAEjB,
|
|
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;IAEjB,6BAA6B;IAC7B,QAAQ,CAAC,QAAQ,EAAE,OAAO;IAC1B,mCAAmC;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM;;IAHzB,6BAA6B;IACpB,QAAQ,EAAE,OAAO;IAC1B,mCAAmC;IAC1B,OAAO,CAAC,EAAE,MAAM,YAAA;CAEhC"}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CooldownInfo = void 0;
|
|
4
4
|
class CooldownInfo {
|
|
5
|
-
|
|
5
|
+
cooldown;
|
|
6
6
|
message;
|
|
7
7
|
constructor(
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/** Cooldown configuration */
|
|
9
|
+
cooldown,
|
|
10
10
|
/** Cooldown message to be shown */
|
|
11
11
|
message) {
|
|
12
|
-
this.
|
|
12
|
+
this.cooldown = cooldown;
|
|
13
13
|
this.message = message;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CooldownInfo } from './cooldownInfo';
|
|
2
|
+
import { CommandActionPropertyProvider, ScheduledActionPropertyProvider } from '../types/propertyProvider';
|
|
3
|
+
import { HoursOfDay } from '../types/timeValues';
|
|
4
|
+
export type CommandActionProviders = {
|
|
5
|
+
cooldownProvider: CommandActionPropertyProvider<CooldownInfo>;
|
|
6
|
+
isActiveProvider: CommandActionPropertyProvider<boolean>;
|
|
7
|
+
chatsBlacklistProvider: CommandActionPropertyProvider<number[]>;
|
|
8
|
+
chatsWhitelistProvider: CommandActionPropertyProvider<number[]>;
|
|
9
|
+
usersWhitelistProvider: CommandActionPropertyProvider<number[]>;
|
|
10
|
+
};
|
|
11
|
+
export type ScheduledActionProviders = {
|
|
12
|
+
timeinHoursProvider: ScheduledActionPropertyProvider<HoursOfDay>;
|
|
13
|
+
isActiveProvider: ScheduledActionPropertyProvider<boolean>;
|
|
14
|
+
chatsWhitelistProvider: ScheduledActionPropertyProvider<number[]>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=propertyProviderSets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyProviderSets.d.ts","sourceRoot":"","sources":["../../dtos/propertyProviderSets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACH,6BAA6B,EAC7B,+BAA+B,EAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,MAAM,sBAAsB,GAAG;IACjC,gBAAgB,EAAE,6BAA6B,CAAC,YAAY,CAAC,CAAC;IAC9D,gBAAgB,EAAE,6BAA6B,CAAC,OAAO,CAAC,CAAC;IACzD,sBAAsB,EAAE,6BAA6B,CAAC,MAAM,EAAE,CAAC,CAAC;IAChE,sBAAsB,EAAE,6BAA6B,CAAC,MAAM,EAAE,CAAC,CAAC;IAChE,sBAAsB,EAAE,6BAA6B,CAAC,MAAM,EAAE,CAAC,CAAC;CACnE,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACnC,mBAAmB,EAAE,+BAA+B,CAAC,UAAU,CAAC,CAAC;IACjE,gBAAgB,EAAE,+BAA+B,CAAC,OAAO,CAAC,CAAC;IAC3D,sBAAsB,EAAE,+BAA+B,CAAC,MAAM,EAAE,CAAC,CAAC;CACrE,CAAC"}
|
|
@@ -5,26 +5,26 @@ import { IActionWithState, ActionKey } from '../../types/action';
|
|
|
5
5
|
import { MessageContextInternal } from '../context/messageContext';
|
|
6
6
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
7
7
|
import { Sema as Semaphore } from 'async-sema';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { CommandActionProviders } from '../../dtos/propertyProviderSets';
|
|
9
|
+
import { BotResponse } from '../../types/response';
|
|
10
10
|
export declare class CommandAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
|
|
11
|
+
private readonly cooldownInfoProvider;
|
|
12
|
+
private readonly isActiveProvider;
|
|
13
|
+
private readonly chatsBlacklistProvider;
|
|
14
|
+
private readonly chatsWhitelistProvider;
|
|
15
|
+
private readonly usersWhitelistProvider;
|
|
16
|
+
readonly key: ActionKey;
|
|
17
|
+
readonly name: string;
|
|
11
18
|
readonly ratelimitSemaphores: Map<number, Semaphore>;
|
|
19
|
+
readonly maxAllowedSimultaniousExecutions: number;
|
|
12
20
|
readonly triggers: CommandTrigger[];
|
|
13
21
|
readonly handler: CommandHandler<TActionState>;
|
|
14
|
-
readonly name: string;
|
|
15
|
-
readonly cooldownInfo: CooldownInfo;
|
|
16
|
-
readonly active: boolean;
|
|
17
|
-
readonly chatsBlacklist: number[];
|
|
18
|
-
readonly chatsWhitelist: number[];
|
|
19
|
-
readonly usersWhitelist: number[];
|
|
20
22
|
readonly condition: CommandCondition<TActionState>;
|
|
21
23
|
readonly stateConstructor: () => TActionState;
|
|
22
|
-
readonly key: ActionKey;
|
|
23
24
|
readonly readmeFactory: (botName: string) => string;
|
|
24
|
-
readonly maxAllowedSimultaniousExecutions: number;
|
|
25
25
|
private lastCustomCooldown;
|
|
26
|
-
constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string,
|
|
27
|
-
exec(ctx: MessageContextInternal<TActionState>): Promise<
|
|
26
|
+
constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, providers: CommandActionProviders, maxAllowedSimultaniousExecutions: number, condition: CommandCondition<TActionState>, stateConstructor: () => TActionState, readmeFactory: (botName: string) => string);
|
|
27
|
+
exec(ctx: MessageContextInternal<TActionState>): Promise<BotResponse[]>;
|
|
28
28
|
private checkIfShouldBeExecuted;
|
|
29
29
|
private checkTrigger;
|
|
30
30
|
}
|
|
@@ -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;
|
|
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;AAO/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,sBA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,OAAO,CAAC,uBAAuB;IA6D/B,OAAO,CAAC,YAAY;CAuCvB"}
|
|
@@ -15,30 +15,30 @@ const mapUtils_1 = require("../../helpers/mapUtils");
|
|
|
15
15
|
const textMessage_1 = require("../../dtos/responses/textMessage");
|
|
16
16
|
const replyInfo_1 = require("../../dtos/replyInfo");
|
|
17
17
|
class CommandAction {
|
|
18
|
+
cooldownInfoProvider;
|
|
19
|
+
isActiveProvider;
|
|
20
|
+
chatsBlacklistProvider;
|
|
21
|
+
chatsWhitelistProvider;
|
|
22
|
+
usersWhitelistProvider;
|
|
23
|
+
key;
|
|
24
|
+
name;
|
|
18
25
|
ratelimitSemaphores = new Map();
|
|
26
|
+
maxAllowedSimultaniousExecutions;
|
|
19
27
|
triggers;
|
|
20
28
|
handler;
|
|
21
|
-
name;
|
|
22
|
-
cooldownInfo;
|
|
23
|
-
active;
|
|
24
|
-
chatsBlacklist;
|
|
25
|
-
chatsWhitelist;
|
|
26
|
-
usersWhitelist;
|
|
27
29
|
condition;
|
|
28
30
|
stateConstructor;
|
|
29
|
-
key;
|
|
30
31
|
readmeFactory;
|
|
31
|
-
maxAllowedSimultaniousExecutions;
|
|
32
32
|
lastCustomCooldown;
|
|
33
|
-
constructor(trigger, handler, name,
|
|
33
|
+
constructor(trigger, handler, name, providers, maxAllowedSimultaniousExecutions, condition, stateConstructor, readmeFactory) {
|
|
34
34
|
this.triggers = (0, toArray_1.toArray)(trigger);
|
|
35
|
-
this.handler = handler;
|
|
36
35
|
this.name = name;
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
36
|
+
this.cooldownInfoProvider = providers.cooldownProvider;
|
|
37
|
+
this.isActiveProvider = providers.isActiveProvider;
|
|
38
|
+
this.chatsBlacklistProvider = providers.chatsBlacklistProvider;
|
|
39
|
+
this.chatsWhitelistProvider = providers.chatsWhitelistProvider;
|
|
40
|
+
this.usersWhitelistProvider = providers.usersWhitelistProvider;
|
|
41
|
+
this.handler = handler;
|
|
42
42
|
this.condition = condition;
|
|
43
43
|
this.stateConstructor = stateConstructor;
|
|
44
44
|
this.readmeFactory = readmeFactory;
|
|
@@ -60,10 +60,14 @@ class CommandAction {
|
|
|
60
60
|
.map((x) => this.checkIfShouldBeExecuted(ctx, x, state))
|
|
61
61
|
.reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('Other'));
|
|
62
62
|
if (!shouldExecute) {
|
|
63
|
-
if (reason == 'OnCooldown'
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (reason == 'OnCooldown') {
|
|
64
|
+
const cooldownMessage = this.cooldownInfoProvider(ctx).message;
|
|
65
|
+
return cooldownMessage
|
|
66
|
+
? [
|
|
67
|
+
new textMessage_1.TextMessage(cooldownMessage, ctx.chatInfo, ctx.traceId, this, new replyInfo_1.ReplyInfo(ctx.messageInfo.id))
|
|
68
|
+
]
|
|
69
|
+
: noop_1.Noop.NoResponse;
|
|
70
|
+
}
|
|
67
71
|
return noop_1.Noop.NoResponse;
|
|
68
72
|
}
|
|
69
73
|
ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
|
|
@@ -84,11 +88,13 @@ class CommandAction {
|
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
checkIfShouldBeExecuted(ctx, trigger, state) {
|
|
87
|
-
if (!this.
|
|
91
|
+
if (!this.isActiveProvider(ctx))
|
|
88
92
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ActionDisabled');
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
93
|
+
const chatsBlacklist = this.chatsBlacklistProvider(ctx);
|
|
94
|
+
const chatsWhitelist = this.chatsWhitelistProvider(ctx);
|
|
95
|
+
const isChatInBlacklist = chatsBlacklist.includes(ctx.chatInfo.id);
|
|
96
|
+
const isChatInWhitelist = chatsWhitelist.length == 0 ||
|
|
97
|
+
chatsWhitelist.includes(ctx.chatInfo.id);
|
|
92
98
|
if (isChatInBlacklist || !isChatInWhitelist)
|
|
93
99
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('ChatForbidden');
|
|
94
100
|
const triggerCheckResult = this.checkTrigger(ctx, trigger);
|
|
@@ -96,12 +102,13 @@ class CommandAction {
|
|
|
96
102
|
return triggerCheckResult;
|
|
97
103
|
if (!ctx.userInfo.id)
|
|
98
104
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserIdMissing');
|
|
99
|
-
const
|
|
100
|
-
|
|
105
|
+
const usersWhitelist = this.usersWhitelistProvider(ctx);
|
|
106
|
+
const isUserAllowed = usersWhitelist.length == 0 ||
|
|
107
|
+
usersWhitelist.includes(ctx.userInfo.id);
|
|
101
108
|
if (!isUserAllowed)
|
|
102
109
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown('UserForbidden');
|
|
103
110
|
const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
|
|
104
|
-
const cooldownInMilliseconds = (0, timeConvertions_1.secondsToMilliseconds)(this.lastCustomCooldown ?? this.
|
|
111
|
+
const cooldownInMilliseconds = (0, timeConvertions_1.secondsToMilliseconds)(this.lastCustomCooldown ?? this.cooldownInfoProvider(ctx).cooldown);
|
|
105
112
|
const onCooldown = (0, moment_1.default)().diff(lastExecutedDate) < cooldownInMilliseconds;
|
|
106
113
|
if (onCooldown)
|
|
107
114
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('OnCooldown');
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ActionKey, IAction } from '../../types/action';
|
|
2
2
|
import { InlineQueryContextInternal } from '../context/inlineQueryContext';
|
|
3
3
|
import { InlineQueryHandler } from '../../types/handlers';
|
|
4
|
+
import { InlineActionPropertyProvider } from '../../types/propertyProvider';
|
|
4
5
|
export declare class InlineQueryAction implements IAction {
|
|
5
6
|
readonly key: ActionKey;
|
|
6
|
-
readonly
|
|
7
|
+
readonly isActiveProvider: InlineActionPropertyProvider<boolean>;
|
|
7
8
|
readonly handler: InlineQueryHandler;
|
|
8
9
|
readonly name: string;
|
|
9
10
|
readonly pattern: RegExp;
|
|
10
|
-
constructor(handler: InlineQueryHandler, name: string,
|
|
11
|
+
constructor(handler: InlineQueryHandler, name: string, activeProvider: InlineActionPropertyProvider<boolean>, pattern: RegExp);
|
|
11
12
|
exec(ctx: InlineQueryContextInternal): Promise<import("../../types/response").BotResponse[]>;
|
|
12
13
|
}
|
|
13
14
|
//# sourceMappingURL=inlineQueryAction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inlineQueryAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/inlineQueryAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"inlineQueryAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/inlineQueryAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAE5E,qBAAa,iBAAkB,YAAW,OAAO;IAC7C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAC;IACjE,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAGrB,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,4BAA4B,CAAC,OAAO,CAAC,EACrD,OAAO,EAAE,MAAM;IAUb,IAAI,CAAC,GAAG,EAAE,0BAA0B;CAuC7C"}
|
|
@@ -4,21 +4,21 @@ exports.InlineQueryAction = void 0;
|
|
|
4
4
|
const noop_1 = require("../../helpers/noop");
|
|
5
5
|
class InlineQueryAction {
|
|
6
6
|
key;
|
|
7
|
-
|
|
7
|
+
isActiveProvider;
|
|
8
8
|
handler;
|
|
9
9
|
name;
|
|
10
10
|
pattern;
|
|
11
|
-
constructor(handler, name,
|
|
11
|
+
constructor(handler, name, activeProvider, pattern) {
|
|
12
12
|
this.handler = handler;
|
|
13
13
|
this.name = name;
|
|
14
|
-
this.
|
|
14
|
+
this.isActiveProvider = activeProvider;
|
|
15
15
|
this.pattern = pattern;
|
|
16
16
|
this.key = `inline:${this.name.replace('.', '-')}`;
|
|
17
17
|
}
|
|
18
18
|
async exec(ctx) {
|
|
19
19
|
if (!ctx.isInitialized)
|
|
20
20
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
21
|
-
if (!this.
|
|
21
|
+
if (!this.isActiveProvider(ctx))
|
|
22
22
|
return noop_1.Noop.NoResponse;
|
|
23
23
|
const matchResults = [];
|
|
24
24
|
this.pattern.lastIndex = 0;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { Sema as Semaphore } from 'async-sema';
|
|
2
2
|
import { ScheduledHandler } from '../../types/handlers';
|
|
3
|
-
import { HoursOfDay } from '../../types/timeValues';
|
|
4
3
|
import { IActionState } from '../../types/actionState';
|
|
5
4
|
import { IActionWithState, ActionKey } from '../../types/action';
|
|
6
5
|
import { CachedStateFactory } from '../cachedStateFactory';
|
|
7
6
|
import { ChatContextInternal } from '../context/chatContext';
|
|
7
|
+
import { ScheduledActionProviders } from '../../dtos/propertyProviderSets';
|
|
8
8
|
export declare class ScheduledAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
|
|
9
9
|
static readonly locks: Map<string, Semaphore>;
|
|
10
10
|
readonly name: string;
|
|
11
|
-
readonly timeinHours: HoursOfDay;
|
|
12
|
-
readonly active: boolean;
|
|
13
|
-
readonly chatsWhitelist: number[];
|
|
14
11
|
readonly key: ActionKey;
|
|
12
|
+
private readonly timeinHoursProvider;
|
|
13
|
+
private readonly activeProvider;
|
|
14
|
+
private readonly chatsWhitelistProvider;
|
|
15
15
|
readonly cachedState: Map<string, unknown>;
|
|
16
16
|
readonly stateConstructor: () => TActionState;
|
|
17
17
|
readonly cachedStateFactories: Map<string, CachedStateFactory>;
|
|
18
18
|
readonly handler: ScheduledHandler<TActionState>;
|
|
19
|
-
constructor(name: string, handler: ScheduledHandler<TActionState>,
|
|
19
|
+
constructor(name: string, handler: ScheduledHandler<TActionState>, providers: ScheduledActionProviders, cachedStateFactories: Map<string, CachedStateFactory>, stateConstructor: () => TActionState);
|
|
20
20
|
exec(ctx: ChatContextInternal<TActionState>): Promise<import("../../types/response").BotResponse[]>;
|
|
21
21
|
private getCachedValue;
|
|
22
22
|
private checkIfShouldBeExecuted;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduledAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/scheduledAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduledAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/scheduledAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD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ledAction {
|
|
13
13
|
static locks = new Map();
|
|
14
14
|
name;
|
|
15
|
-
timeinHours;
|
|
16
|
-
active;
|
|
17
|
-
chatsWhitelist;
|
|
18
15
|
key;
|
|
16
|
+
timeinHoursProvider;
|
|
17
|
+
activeProvider;
|
|
18
|
+
chatsWhitelistProvider;
|
|
19
19
|
cachedState = new Map();
|
|
20
20
|
stateConstructor;
|
|
21
21
|
cachedStateFactories;
|
|
22
22
|
handler;
|
|
23
|
-
constructor(name, handler,
|
|
23
|
+
constructor(name, handler, providers, cachedStateFactories, stateConstructor) {
|
|
24
24
|
this.name = name;
|
|
25
|
-
this.handler = handler;
|
|
26
|
-
this.timeinHours = timeinHours;
|
|
27
|
-
this.active = active;
|
|
28
|
-
this.chatsWhitelist = whitelist;
|
|
29
|
-
this.cachedStateFactories = cachedStateFactories;
|
|
30
25
|
this.key = `scheduled:${this.name.replace('.', '-')}`;
|
|
26
|
+
this.timeinHoursProvider = providers.timeinHoursProvider;
|
|
27
|
+
this.activeProvider = providers.isActiveProvider;
|
|
28
|
+
this.chatsWhitelistProvider = providers.chatsWhitelistProvider;
|
|
29
|
+
this.cachedStateFactories = cachedStateFactories;
|
|
31
30
|
this.stateConstructor = stateConstructor;
|
|
31
|
+
this.handler = handler;
|
|
32
32
|
}
|
|
33
33
|
async exec(ctx) {
|
|
34
34
|
if (!ctx.isInitialized)
|
|
35
35
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
36
|
-
if (!this.
|
|
36
|
+
if (!this.activeProvider(ctx) ||
|
|
37
|
+
!this.chatsWhitelistProvider(ctx).includes(ctx.chatInfo.id))
|
|
37
38
|
return noop_1.Noop.NoResponse;
|
|
38
39
|
const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
|
|
39
|
-
const isAllowedToTrigger = this.checkIfShouldBeExecuted(state);
|
|
40
|
+
const isAllowedToTrigger = this.checkIfShouldBeExecuted(state, ctx);
|
|
40
41
|
if (!isAllowedToTrigger)
|
|
41
42
|
return noop_1.Noop.NoResponse;
|
|
42
43
|
ctx.logger.logWithTraceId(` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
|
|
@@ -63,13 +64,13 @@ class ScheduledAction {
|
|
|
63
64
|
semaphore.release();
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
checkIfShouldBeExecuted(state) {
|
|
67
|
+
checkIfShouldBeExecuted(state, ctx) {
|
|
67
68
|
const startOfToday = (0, moment_1.default)().startOf('day').valueOf();
|
|
68
69
|
const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
|
|
69
70
|
const currentTime = (0, moment_1.default)();
|
|
70
71
|
const scheduledTime = (0, moment_1.default)()
|
|
71
72
|
.startOf('day')
|
|
72
|
-
.add(this.
|
|
73
|
+
.add(this.timeinHoursProvider(ctx), 'hours');
|
|
73
74
|
const isAllowedToTrigger = currentTime.isSameOrAfter(scheduledTime);
|
|
74
75
|
const hasTriggeredToday = lastExecutedDate.isAfter(startOfToday);
|
|
75
76
|
return isAllowedToTrigger && !hasTriggeredToday;
|
|
@@ -7,7 +7,7 @@ import { BotResponse, IReplyResponse } from '../../types/response';
|
|
|
7
7
|
import { IScheduler } from '../../types/scheduler';
|
|
8
8
|
import { IStorageClient } from '../../types/storage';
|
|
9
9
|
import { TraceId } from '../../types/trace';
|
|
10
|
-
export type BaseContextPropertiesToOmit = 'action' | 'isInitialized' | 'storage' | 'scheduler' | 'logger' | 'responses' | 'traceId'
|
|
10
|
+
export type BaseContextPropertiesToOmit = 'action' | 'isInitialized' | 'storage' | 'scheduler' | 'logger' | 'responses' | 'traceId';
|
|
11
11
|
export declare abstract class BaseContextInternal<TAction extends IAction> {
|
|
12
12
|
isInitialized: boolean;
|
|
13
13
|
private _responses;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseContext.d.ts","sourceRoot":"","sources":["../../../entities/context/baseContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC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hB,8BAAsB,mBAAmB,CAAC,OAAO,SAAS,OAAO;IAC7D,aAAa,UAAS;IACtB,OAAO,CAAC,UAAU,CAAqB;IAEvC,MAAM,EAAG,OAAO,CAAC;IAEjB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,MAAM,EAAG,aAAa,CAAC;IACvB,sCAAsC;IACtC,OAAO,EAAG,OAAO,CAAC;IAClB,+CAA+C;IAC/C,OAAO,EAAG,MAAM,CAAC;IACjB,wBAAwB;IACxB,QAAQ,EAAG,QAAQ,CAAC;IACpB,IAAI,SAAS,2CAEZ;IAED,uDAAuD;IACvD,IAAW,SAAS,IAAI,WAAW,EAAE,CAEpC;IACD,IAAW,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,EAExC;gBAEW,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAK1D,SAAS,CAAC,uBAAuB,CAC7B,QAAQ,EAAE,cAAc,GACzB,kBAAkB;IAmBrB;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,MAAM,EAAE,gBAAgB,CAAC,mBAAmB,CAAC;CAWpD"}
|
|
@@ -5,23 +5,24 @@ import { CommandAction } from '../../entities/actions/commandAction';
|
|
|
5
5
|
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
6
6
|
import { IActionState } from '../../types/actionState';
|
|
7
7
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
8
|
+
import { CooldownInfo } from '../../dtos/cooldownInfo';
|
|
9
|
+
import { CommandActionPropertyProvider } from '../../types/propertyProvider';
|
|
8
10
|
/**
|
|
9
11
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
10
12
|
*/
|
|
11
13
|
export declare class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
12
14
|
private readonly name;
|
|
13
15
|
private trigger;
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
16
|
+
private activeProvider;
|
|
17
|
+
private cooldownSettingsProvider;
|
|
18
|
+
private blacklistProvider;
|
|
19
|
+
private whitelistProvider;
|
|
20
|
+
private allowedUsersProvider;
|
|
19
21
|
private readmeFactory;
|
|
20
22
|
private readonly stateConstructor;
|
|
21
23
|
private handler;
|
|
22
24
|
private condition;
|
|
23
25
|
private maxAllowedSimultaniousExecutions;
|
|
24
|
-
private cooldownMessage;
|
|
25
26
|
/**
|
|
26
27
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
27
28
|
* @param name Action name, will be used for logging and storage
|
|
@@ -70,9 +71,19 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
70
71
|
* @param cooldownSettings Settings.
|
|
71
72
|
*/
|
|
72
73
|
withCooldown(cooldownSettings: {
|
|
73
|
-
|
|
74
|
+
cooldown: Seconds;
|
|
74
75
|
message?: string;
|
|
75
76
|
}): this;
|
|
77
|
+
/**
|
|
78
|
+
* Configures action to use property value providers instead of static value to allow changes in runtime
|
|
79
|
+
*/
|
|
80
|
+
withConfiguration(configuration: {
|
|
81
|
+
cooldownProvider?: CommandActionPropertyProvider<CooldownInfo>;
|
|
82
|
+
isActiveProvider?: CommandActionPropertyProvider<boolean>;
|
|
83
|
+
chatsBlacklistProvider?: CommandActionPropertyProvider<number[]>;
|
|
84
|
+
chatsWhitelistProvider?: CommandActionPropertyProvider<number[]>;
|
|
85
|
+
usersWhitelistProvider?: CommandActionPropertyProvider<number[]>;
|
|
86
|
+
}): this;
|
|
76
87
|
/** Builds action */
|
|
77
88
|
build(): CommandAction<TActionState>;
|
|
78
89
|
}
|
|
@@ -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,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AkBR;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,6BAA6B,CAAC,eAAe,CAAC;IACpF;;OAEG;gBACS,IAAI,EAAE,MAAM;CAG3B"}
|
|
@@ -6,24 +6,22 @@ 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");
|
|
10
9
|
/**
|
|
11
10
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
12
11
|
*/
|
|
13
12
|
class CommandActionBuilderWithState {
|
|
14
13
|
name;
|
|
15
14
|
trigger = [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
activeProvider = () => true;
|
|
16
|
+
cooldownSettingsProvider = () => new cooldownInfo_1.CooldownInfo(0);
|
|
17
|
+
blacklistProvider = () => [];
|
|
18
|
+
whitelistProvider = () => [];
|
|
19
|
+
allowedUsersProvider = () => [];
|
|
21
20
|
readmeFactory = noop_1.Noop.emptyString;
|
|
22
21
|
stateConstructor;
|
|
23
22
|
handler = noop_1.Noop.call;
|
|
24
23
|
condition = noop_1.Noop.true;
|
|
25
24
|
maxAllowedSimultaniousExecutions = 0;
|
|
26
|
-
cooldownMessage;
|
|
27
25
|
/**
|
|
28
26
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
29
27
|
* @param name Action name, will be used for logging and storage
|
|
@@ -47,7 +45,8 @@ class CommandActionBuilderWithState {
|
|
|
47
45
|
* @param id User id or ids
|
|
48
46
|
*/
|
|
49
47
|
from(id) {
|
|
50
|
-
|
|
48
|
+
const ids = (0, toArray_1.toArray)(id);
|
|
49
|
+
this.allowedUsersProvider = () => ids;
|
|
51
50
|
return this;
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
@@ -55,7 +54,7 @@ class CommandActionBuilderWithState {
|
|
|
55
54
|
* @param chatIds Chats ids to allow.
|
|
56
55
|
*/
|
|
57
56
|
in(chatIds) {
|
|
58
|
-
this.
|
|
57
|
+
this.whitelistProvider = () => chatIds;
|
|
59
58
|
return this;
|
|
60
59
|
}
|
|
61
60
|
/**
|
|
@@ -63,7 +62,7 @@ class CommandActionBuilderWithState {
|
|
|
63
62
|
* @param chatIds Chats ids to ignore.
|
|
64
63
|
*/
|
|
65
64
|
notIn(chatIds) {
|
|
66
|
-
this.
|
|
65
|
+
this.blacklistProvider = () => chatIds;
|
|
67
66
|
return this;
|
|
68
67
|
}
|
|
69
68
|
/** Defines action logic itself, will be executed on trigger.
|
|
@@ -90,7 +89,7 @@ class CommandActionBuilderWithState {
|
|
|
90
89
|
}
|
|
91
90
|
/** If called during building, action is marked as disabled and never checked. */
|
|
92
91
|
disabled() {
|
|
93
|
-
this.
|
|
92
|
+
this.activeProvider = () => false;
|
|
94
93
|
return this;
|
|
95
94
|
}
|
|
96
95
|
/** Sets maximum number of simultaniously executing handlers for this command per chat. 0 is treated as unlimited. */
|
|
@@ -103,13 +102,35 @@ class CommandActionBuilderWithState {
|
|
|
103
102
|
* @param cooldownSettings Settings.
|
|
104
103
|
*/
|
|
105
104
|
withCooldown(cooldownSettings) {
|
|
106
|
-
|
|
107
|
-
this.
|
|
105
|
+
const settings = new cooldownInfo_1.CooldownInfo(cooldownSettings.cooldown, cooldownSettings.message);
|
|
106
|
+
this.cooldownSettingsProvider = () => settings;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Configures action to use property value providers instead of static value to allow changes in runtime
|
|
111
|
+
*/
|
|
112
|
+
withConfiguration(configuration) {
|
|
113
|
+
if (configuration.cooldownProvider)
|
|
114
|
+
this.cooldownSettingsProvider = configuration.cooldownProvider;
|
|
115
|
+
if (configuration.chatsWhitelistProvider)
|
|
116
|
+
this.whitelistProvider = configuration.chatsWhitelistProvider;
|
|
117
|
+
if (configuration.chatsBlacklistProvider)
|
|
118
|
+
this.blacklistProvider = configuration.chatsBlacklistProvider;
|
|
119
|
+
if (configuration.usersWhitelistProvider)
|
|
120
|
+
this.allowedUsersProvider = configuration.usersWhitelistProvider;
|
|
121
|
+
if (configuration.isActiveProvider)
|
|
122
|
+
this.activeProvider = configuration.isActiveProvider;
|
|
108
123
|
return this;
|
|
109
124
|
}
|
|
110
125
|
/** Builds action */
|
|
111
126
|
build() {
|
|
112
|
-
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name,
|
|
127
|
+
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, {
|
|
128
|
+
cooldownProvider: this.cooldownSettingsProvider,
|
|
129
|
+
isActiveProvider: this.activeProvider,
|
|
130
|
+
chatsBlacklistProvider: this.blacklistProvider,
|
|
131
|
+
chatsWhitelistProvider: this.whitelistProvider,
|
|
132
|
+
usersWhitelistProvider: this.allowedUsersProvider
|
|
133
|
+
}, this.maxAllowedSimultaniousExecutions, this.condition, this.stateConstructor, this.readmeFactory);
|
|
113
134
|
}
|
|
114
135
|
}
|
|
115
136
|
exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { InlineQueryHandler } from '../../types/handlers';
|
|
2
2
|
import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
|
|
3
|
+
import { InlineActionPropertyProvider } from '../../types/propertyProvider';
|
|
3
4
|
/**
|
|
4
5
|
* Builder for `InlineQueryAction`
|
|
5
6
|
*/
|
|
6
7
|
export declare class InlineQueryActionBuilder {
|
|
7
8
|
private readonly name;
|
|
8
9
|
private pattern;
|
|
9
|
-
private
|
|
10
|
+
private activeProvider;
|
|
10
11
|
private handler;
|
|
11
12
|
/**
|
|
12
13
|
* Builder for `InlineQueryAction`
|
|
@@ -24,6 +25,12 @@ export declare class InlineQueryActionBuilder {
|
|
|
24
25
|
do(handler: InlineQueryHandler): this;
|
|
25
26
|
/** If called during building, action is marked as disabled and never checked. */
|
|
26
27
|
disabled(): this;
|
|
28
|
+
/**
|
|
29
|
+
* Configures action to use property value providers instead of static value to allow changes in runtime
|
|
30
|
+
*/
|
|
31
|
+
withConfiguration(configuration: {
|
|
32
|
+
isActiveProvider?: InlineActionPropertyProvider<boolean>;
|
|
33
|
+
}): this;
|
|
27
34
|
/** Builds action */
|
|
28
35
|
build(): InlineQueryAction;
|
|
29
36
|
}
|
|
@@ -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;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,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;AAC7E,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAE5E;;GAEG;AACH,qBAAa,wBAAwB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,OAAO,CAAkB;IAEjC,OAAO,CAAC,cAAc,CAAqD;IAC3E,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;;OAEG;IACH,iBAAiB,CAAC,aAAa,EAAE;QAC7B,gBAAgB,CAAC,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAC;KAC5D;IAOD,oBAAoB;IACpB,KAAK;CAQR"}
|