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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InlineQueryHandler } from '../../types/handlers';
|
|
2
2
|
import { Noop } from '../noop';
|
|
3
3
|
import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
|
|
4
|
+
import { InlineActionPropertyProvider } from '../../types/propertyProvider';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Builder for `InlineQueryAction`
|
|
@@ -9,7 +10,7 @@ export class InlineQueryActionBuilder {
|
|
|
9
10
|
private readonly name: string;
|
|
10
11
|
private pattern: RegExp = /.+/gi;
|
|
11
12
|
|
|
12
|
-
private
|
|
13
|
+
private activeProvider: InlineActionPropertyProvider<boolean> = () => true;
|
|
13
14
|
private handler: InlineQueryHandler = Noop.call;
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -41,7 +42,19 @@ export class InlineQueryActionBuilder {
|
|
|
41
42
|
|
|
42
43
|
/** If called during building, action is marked as disabled and never checked. */
|
|
43
44
|
disabled() {
|
|
44
|
-
this.
|
|
45
|
+
this.activeProvider = () => false;
|
|
46
|
+
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Configures action to use property value providers instead of static value to allow changes in runtime
|
|
52
|
+
*/
|
|
53
|
+
withConfiguration(configuration: {
|
|
54
|
+
isActiveProvider?: InlineActionPropertyProvider<boolean>;
|
|
55
|
+
}) {
|
|
56
|
+
if (configuration.isActiveProvider)
|
|
57
|
+
this.activeProvider = configuration.isActiveProvider;
|
|
45
58
|
|
|
46
59
|
return this;
|
|
47
60
|
}
|
|
@@ -51,7 +64,7 @@ export class InlineQueryActionBuilder {
|
|
|
51
64
|
return new InlineQueryAction(
|
|
52
65
|
this.handler,
|
|
53
66
|
this.name,
|
|
54
|
-
this.
|
|
67
|
+
this.activeProvider,
|
|
55
68
|
this.pattern
|
|
56
69
|
);
|
|
57
70
|
}
|
|
@@ -3,6 +3,7 @@ import { CachedStateFactory } from '../../entities/cachedStateFactory';
|
|
|
3
3
|
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
5
|
import { ScheduledHandler } from '../../types/handlers';
|
|
6
|
+
import { ScheduledActionPropertyProvider } from '../../types/propertyProvider';
|
|
6
7
|
import { Hours, HoursOfDay } from '../../types/timeValues';
|
|
7
8
|
import { Noop } from '../noop';
|
|
8
9
|
|
|
@@ -12,17 +13,20 @@ import { Noop } from '../noop';
|
|
|
12
13
|
export class ScheduledActionBuilderWithState<
|
|
13
14
|
TActionState extends IActionState
|
|
14
15
|
> {
|
|
15
|
-
private
|
|
16
|
-
private time: HoursOfDay = 0;
|
|
16
|
+
private readonly name: string;
|
|
17
17
|
private readonly cachedStateFactories = new Map<
|
|
18
18
|
string,
|
|
19
19
|
CachedStateFactory
|
|
20
20
|
>();
|
|
21
|
-
private whitelist: number[] = [];
|
|
22
21
|
private readonly stateConstructor: () => TActionState;
|
|
23
22
|
private handler: ScheduledHandler<TActionState> = Noop.call;
|
|
24
23
|
|
|
25
|
-
private
|
|
24
|
+
private whitelistProvider: ScheduledActionPropertyProvider<number[]> =
|
|
25
|
+
() => [];
|
|
26
|
+
private activeProvider: ScheduledActionPropertyProvider<boolean> = () =>
|
|
27
|
+
true;
|
|
28
|
+
private timeinHoursProvider: ScheduledActionPropertyProvider<HoursOfDay> =
|
|
29
|
+
() => 0;
|
|
26
30
|
|
|
27
31
|
/**
|
|
28
32
|
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
@@ -39,7 +43,7 @@ export class ScheduledActionBuilderWithState<
|
|
|
39
43
|
* @param chatIds Chat ids to execute in.
|
|
40
44
|
*/
|
|
41
45
|
in(chatIds: number[]) {
|
|
42
|
-
this.
|
|
46
|
+
this.whitelistProvider = () => chatIds;
|
|
43
47
|
|
|
44
48
|
return this;
|
|
45
49
|
}
|
|
@@ -49,7 +53,7 @@ export class ScheduledActionBuilderWithState<
|
|
|
49
53
|
* @param time Time of day (0 - 23) to execute action.
|
|
50
54
|
*/
|
|
51
55
|
runAt(time: HoursOfDay) {
|
|
52
|
-
this.
|
|
56
|
+
this.timeinHoursProvider = () => time;
|
|
53
57
|
|
|
54
58
|
return this;
|
|
55
59
|
}
|
|
@@ -85,7 +89,27 @@ export class ScheduledActionBuilderWithState<
|
|
|
85
89
|
|
|
86
90
|
/** If called during building, action is marked as disabled and never checked. */
|
|
87
91
|
disabled() {
|
|
88
|
-
this.
|
|
92
|
+
this.activeProvider = () => false;
|
|
93
|
+
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Configures action to use property value providers instead of static value to allow changes in runtime
|
|
99
|
+
*/
|
|
100
|
+
withConfiguration(configuration: {
|
|
101
|
+
timeinHoursProvider?: ScheduledActionPropertyProvider<HoursOfDay>;
|
|
102
|
+
isActiveProvider?: ScheduledActionPropertyProvider<boolean>;
|
|
103
|
+
chatsWhitelistProvider?: ScheduledActionPropertyProvider<number[]>;
|
|
104
|
+
}) {
|
|
105
|
+
if (configuration.chatsWhitelistProvider)
|
|
106
|
+
this.whitelistProvider = configuration.chatsWhitelistProvider;
|
|
107
|
+
|
|
108
|
+
if (configuration.timeinHoursProvider)
|
|
109
|
+
this.timeinHoursProvider = configuration.timeinHoursProvider;
|
|
110
|
+
|
|
111
|
+
if (configuration.isActiveProvider)
|
|
112
|
+
this.activeProvider = configuration.isActiveProvider;
|
|
89
113
|
|
|
90
114
|
return this;
|
|
91
115
|
}
|
|
@@ -95,9 +119,11 @@ export class ScheduledActionBuilderWithState<
|
|
|
95
119
|
return new ScheduledAction<TActionState>(
|
|
96
120
|
this.name,
|
|
97
121
|
this.handler,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
122
|
+
{
|
|
123
|
+
chatsWhitelistProvider: this.whitelistProvider,
|
|
124
|
+
isActiveProvider: this.activeProvider,
|
|
125
|
+
timeinHoursProvider: this.timeinHoursProvider
|
|
126
|
+
},
|
|
101
127
|
this.cachedStateFactories,
|
|
102
128
|
this.stateConstructor
|
|
103
129
|
);
|
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "chz-telegram-bot",
|
|
3
|
-
"description": "Opinionated TypeScript framework that provides a structured approach to building Telegram bots.",
|
|
4
|
-
"author": {
|
|
5
|
-
"name": "Alex Halanin",
|
|
6
|
-
"url": "https://github.com/AlexSolari"
|
|
7
|
-
},
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"keywords": [
|
|
10
|
-
"telegram",
|
|
11
|
-
"telegram bot"
|
|
12
|
-
],
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "https://github.com/AlexSolari/botFramework.git"
|
|
16
|
-
},
|
|
17
|
-
"version": "0.3.
|
|
18
|
-
"type": "module",
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"async-sema": "^3.1.1",
|
|
21
|
-
"moment": "^2.29.4",
|
|
22
|
-
"telegraf": "^4.16.3"
|
|
23
|
-
},
|
|
24
|
-
"main": "dist/index.js",
|
|
25
|
-
"types": "dist/index.d.ts",
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"@eslint/js": "^9.29.0",
|
|
28
|
-
"@types/markdown-escape": "^1.1.3",
|
|
29
|
-
"@types/node": "^22.5.5",
|
|
30
|
-
"eslint": "^9.29.0",
|
|
31
|
-
"globals": "^16.2.0",
|
|
32
|
-
"typescript": "^5.9.0-beta",
|
|
33
|
-
"typescript-eslint": "^8.34.1"
|
|
34
|
-
},
|
|
35
|
-
"scripts": {
|
|
36
|
-
"build": "tsc",
|
|
37
|
-
"lint": "npx eslint && tsc --noEmit"
|
|
38
|
-
},
|
|
39
|
-
"overrides": {
|
|
40
|
-
"telegraf": {
|
|
41
|
-
"node-fetch": "3.3.2"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "chz-telegram-bot",
|
|
3
|
+
"description": "Opinionated TypeScript framework that provides a structured approach to building Telegram bots.",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "Alex Halanin",
|
|
6
|
+
"url": "https://github.com/AlexSolari"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"telegram",
|
|
11
|
+
"telegram bot"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/AlexSolari/botFramework.git"
|
|
16
|
+
},
|
|
17
|
+
"version": "0.3.27",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"async-sema": "^3.1.1",
|
|
21
|
+
"moment": "^2.29.4",
|
|
22
|
+
"telegraf": "^4.16.3"
|
|
23
|
+
},
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@eslint/js": "^9.29.0",
|
|
28
|
+
"@types/markdown-escape": "^1.1.3",
|
|
29
|
+
"@types/node": "^22.5.5",
|
|
30
|
+
"eslint": "^9.29.0",
|
|
31
|
+
"globals": "^16.2.0",
|
|
32
|
+
"typescript": "^5.9.0-beta",
|
|
33
|
+
"typescript-eslint": "^8.34.1"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"lint": "npx eslint && tsc --noEmit"
|
|
38
|
+
},
|
|
39
|
+
"overrides": {
|
|
40
|
+
"telegraf": {
|
|
41
|
+
"node-fetch": "3.3.2"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChatContext } from '../entities/context/chatContext';
|
|
2
|
+
import { InlineQueryContext } from '../entities/context/inlineQueryContext';
|
|
3
|
+
import { MessageContext } from '../entities/context/messageContext';
|
|
4
|
+
import { IActionState } from './actionState';
|
|
5
|
+
|
|
6
|
+
export type CommandActionPropertyProvider<T> = (
|
|
7
|
+
ctx: MessageContext<IActionState>
|
|
8
|
+
) => T;
|
|
9
|
+
|
|
10
|
+
export type InlineActionPropertyProvider<T> = (ctx: InlineQueryContext) => T;
|
|
11
|
+
|
|
12
|
+
export type ScheduledActionPropertyProvider<T> = (
|
|
13
|
+
ctx: ChatContext<IActionState>
|
|
14
|
+
) => T;
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|