chz-telegram-bot 0.3.25 → 0.3.26

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.
Files changed (43) hide show
  1. package/builtin/helpAction.ts +1 -1
  2. package/dist/builtin/helpAction.js +1 -1
  3. package/dist/dtos/cooldownInfo.d.ts +6 -6
  4. package/dist/dtos/cooldownInfo.d.ts.map +1 -1
  5. package/dist/dtos/cooldownInfo.js +4 -4
  6. package/dist/dtos/propertyProviderSets.d.ts +16 -0
  7. package/dist/dtos/propertyProviderSets.d.ts.map +1 -0
  8. package/dist/dtos/propertyProviderSets.js +2 -0
  9. package/dist/entities/actions/commandAction.d.ts +12 -12
  10. package/dist/entities/actions/commandAction.d.ts.map +1 -1
  11. package/dist/entities/actions/commandAction.js +33 -26
  12. package/dist/entities/actions/inlineQueryAction.d.ts +3 -2
  13. package/dist/entities/actions/inlineQueryAction.d.ts.map +1 -1
  14. package/dist/entities/actions/inlineQueryAction.js +4 -4
  15. package/dist/entities/actions/scheduledAction.d.ts +5 -5
  16. package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
  17. package/dist/entities/actions/scheduledAction.js +14 -13
  18. package/dist/helpers/builders/commandActionBuilder.d.ts +18 -7
  19. package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
  20. package/dist/helpers/builders/commandActionBuilder.js +35 -14
  21. package/dist/helpers/builders/inlineQueryActionBuilder.d.ts +8 -1
  22. package/dist/helpers/builders/inlineQueryActionBuilder.d.ts.map +1 -1
  23. package/dist/helpers/builders/inlineQueryActionBuilder.js +11 -3
  24. package/dist/helpers/builders/scheduledActionBuilder.d.ts +13 -4
  25. package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -1
  26. package/dist/helpers/builders/scheduledActionBuilder.js +24 -8
  27. package/dist/types/propertyProvider.d.ts +8 -0
  28. package/dist/types/propertyProvider.d.ts.map +1 -0
  29. package/dist/types/propertyProvider.js +2 -0
  30. package/dtos/cooldownInfo.ts +3 -3
  31. package/dtos/propertyProviderSets.ts +20 -0
  32. package/entities/actions/commandAction.ts +59 -36
  33. package/entities/actions/inlineQueryAction.ts +5 -4
  34. package/entities/actions/scheduledAction.ts +26 -15
  35. package/helpers/builders/commandActionBuilder.ts +57 -21
  36. package/helpers/builders/inlineQueryActionBuilder.ts +16 -3
  37. package/helpers/builders/scheduledActionBuilder.ts +36 -10
  38. package/package.json +44 -44
  39. package/types/propertyProvider.ts +14 -0
  40. package/dist/dtos/actionPermissionsData.d.ts +0 -7
  41. package/dist/dtos/actionPermissionsData.d.ts.map +0 -1
  42. package/dist/dtos/actionPermissionsData.js +0 -14
  43. package/dtos/actionPermissionsData.ts +0 -7
@@ -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 active = true;
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 readonly name: string;
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.whitelist = chatIds;
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.time = time;
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.active = false;
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
- this.time,
99
- this.active,
100
- this.whitelist,
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.25",
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.26",
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;
@@ -1,7 +0,0 @@
1
- export class ActionPermissionsData {
2
- constructor(
3
- readonly userIdsWhitelist: number[],
4
- readonly chatIdsWhitelist: number[],
5
- readonly chatIdsBlacklist: number[]
6
- ) {}
7
- }