chz-telegram-bot 0.1.7 → 0.1.9

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.
@@ -0,0 +1,14 @@
1
+ import { CommandActionBuilder } from '../helpers/builders/commandActionBuilder';
2
+ import { Seconds } from '../types/timeValues';
3
+
4
+ export function buildHelpCommand(readmes: string[]) {
5
+ return new CommandActionBuilder('Reaction.Help')
6
+ .on('/help')
7
+ .do(async (ctx) => {
8
+ if (readmes.length == 0) return;
9
+
10
+ ctx.replyWithText(readmes.join('\n\n'));
11
+ })
12
+ .cooldown(60 as Seconds)
13
+ .build();
14
+ }
@@ -0,0 +1,2 @@
1
+ export declare function buildHelpCommand(readmes: string[]): import("../entities/actions/commandAction").CommandAction<import("..").ActionStateBase>;
2
+ //# sourceMappingURL=helpAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpAction.d.ts","sourceRoot":"","sources":["../../builtin/helpAction.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,2FAUjD"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildHelpCommand = buildHelpCommand;
4
+ const commandActionBuilder_1 = require("../helpers/builders/commandActionBuilder");
5
+ function buildHelpCommand(readmes) {
6
+ return new commandActionBuilder_1.CommandActionBuilder('Reaction.Help')
7
+ .on('/help')
8
+ .do(async (ctx) => {
9
+ if (readmes.length == 0)
10
+ return;
11
+ ctx.replyWithText(readmes.join('\n\n'));
12
+ })
13
+ .cooldown(60)
14
+ .build();
15
+ }
@@ -16,7 +16,8 @@ export declare class CommandAction<TActionState extends IActionState> implements
16
16
  readonly condition: CommandCondition<TActionState>;
17
17
  readonly stateConstructor: () => TActionState;
18
18
  readonly key: ActionKey;
19
- constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState);
19
+ readonly readme: string;
20
+ constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState, readme: string);
20
21
  exec(ctx: MessageContext<TActionState>): Promise<import("../../types/response").BotResponse[]>;
21
22
  private checkIfShouldBeExecuted;
22
23
  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;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,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,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC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I,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAGpB,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,EAC1C,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO,EACjB,cAAc,EAAE,MAAM,EAAE,EACxB,YAAY,EAAE,MAAM,EAAE,EACtB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY,EACpC,MAAM,EAAE,MAAM;IAgBZ,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC;IAkD5C,OAAO,CAAC,uBAAuB;IAqC/B,OAAO,CAAC,YAAY;CAmCvB"}
@@ -10,7 +10,7 @@ const toArray_1 = require("../../helpers/toArray");
10
10
  const commandTriggerCheckResult_1 = require("../../dtos/commandTriggerCheckResult");
11
11
  const noop_1 = require("../../helpers/noop");
12
12
  class CommandAction {
13
- constructor(trigger, handler, name, active, cooldown, chatsBlacklist, allowedUsers, condition, stateConstructor) {
13
+ constructor(trigger, handler, name, active, cooldown, chatsBlacklist, allowedUsers, condition, stateConstructor, readme) {
14
14
  this.triggers = (0, toArray_1.toArray)(trigger);
15
15
  this.handler = handler;
16
16
  this.name = name;
@@ -20,6 +20,7 @@ class CommandAction {
20
20
  this.allowedUsers = allowedUsers;
21
21
  this.condition = condition;
22
22
  this.stateConstructor = stateConstructor;
23
+ this.readme = readme;
23
24
  this.key = `command:${this.name.replace('.', '-')}`;
24
25
  }
25
26
  async exec(ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuB,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAO5D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAIhE,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAqB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;IACzD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkC;IAC5D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;IACpD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;gBAEnC,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE;YACL,QAAQ,EAAE,aAAa,CAAC,YAAY,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CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;IACzD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkC;IAC5D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;IACpD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;gBAEnC,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE;YACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;YACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;YAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;SACtC,CAAC;QACF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,gCAAgC,CAAC,EAAE,OAAO,CAAC;QAC3C,QAAQ,CAAC,EAAE;YACP,aAAa,CAAC,EAAE,cAAc,CAAC;YAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,SAAS,CAAC,EAAE,UAAU,CAAC;SAC1B,CAAC;KACL;IAoDD,OAAO,CAAC,6BAA6B;IA4CrC,OAAO,CAAC,+BAA+B;IA2EvC,OAAO,CAAC,2BAA2B;IAiC7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAaT,YAAY;YAuCZ,cAAc;CA2B/B"}
@@ -18,10 +18,19 @@ const nodeTimeoutScheduler_1 = require("../services/nodeTimeoutScheduler");
18
18
  const traceFactory_1 = require("../helpers/traceFactory");
19
19
  const incomingQuery_1 = require("../dtos/incomingQuery");
20
20
  const inlineQueryContext_1 = require("./context/inlineQueryContext");
21
+ const helpAction_1 = require("../builtin/helpAction");
21
22
  class BotInstance {
22
23
  constructor(options) {
23
24
  this.name = options.name;
24
- this.commands = options.actions.commands;
25
+ this.commands =
26
+ options.actions.commands.length > 0
27
+ ? [
28
+ (0, helpAction_1.buildHelpCommand)(options.actions.commands
29
+ .map((x) => x.readme)
30
+ .filter((x) => !!x)),
31
+ ...options.actions.commands
32
+ ]
33
+ : [];
25
34
  this.scheduled = options.actions.scheduled;
26
35
  this.inlineQueries = options.actions.inlineQueries;
27
36
  this.chats = options.chats;
@@ -36,7 +45,7 @@ class BotInstance {
36
45
  new jsonFileStorage_1.JsonFileStorage(options.name, actions, options.storagePath);
37
46
  this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage, this.logger);
38
47
  this.initializeMessageProcessing(options.verboseLoggingForIncomingMessage ?? false);
39
- this.initializeInlineQueryProcessing(500);
48
+ this.initializeInlineQueryProcessing(1000);
40
49
  this.initializeScheduledProcessing(options.scheduledPeriod ?? (0, timeConvertions_1.hoursToSeconds)(1));
41
50
  this.storage.saveMetadata(actions, this.name);
42
51
  this.logger.logWithTraceId(this.name, (0, traceFactory_1.createTrace)(this, this.name, 'Start'), 'System', 'Starting bot...');
@@ -12,6 +12,7 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
12
12
  name: string;
13
13
  trigger: CommandTrigger | CommandTrigger[];
14
14
  active: boolean;
15
+ readme: string;
15
16
  cooldownSeconds: Seconds;
16
17
  blacklist: number[];
17
18
  allowedUsers: number[];
@@ -43,6 +44,7 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
43
44
  * @param condition Condition check predicate
44
45
  */
45
46
  when(condition: CommandCondition<TActionState>): this;
47
+ withHelp(readme: string): void;
46
48
  /** If called during building, action is marked as disabled and never checked. */
47
49
  disabled(): this;
48
50
  /** Sets action cooldown.
@@ -1 +1 @@
1
- {"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/buil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M,GAAG,MAAM,EAAE;IAM1B;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC;IAMxC;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAM9C,QAAQ,CAAC,MAAM,EAAE,MAAM;IAIvB,iFAAiF;IACjF,QAAQ;IAMR;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO;IAMzB;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM;IAMzB,oBAAoB;IACpB,KAAK;CAcR;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,6BAA6B,CAAC,eAAe,CAAC;IACpF;;OAEG;gBACS,IAAI,EAAE,MAAM;CAG3B"}
@@ -17,6 +17,7 @@ class CommandActionBuilderWithState {
17
17
  constructor(name, stateConstructor) {
18
18
  this.trigger = [];
19
19
  this.active = true;
20
+ this.readme = '';
20
21
  this.cooldownSeconds = 0;
21
22
  this.blacklist = [];
22
23
  this.allowedUsers = [];
@@ -56,6 +57,9 @@ class CommandActionBuilderWithState {
56
57
  this.condition = condition;
57
58
  return this;
58
59
  }
60
+ withHelp(readme) {
61
+ this.readme = readme;
62
+ }
59
63
  /** If called during building, action is marked as disabled and never checked. */
60
64
  disabled() {
61
65
  this.active = false;
@@ -78,7 +82,7 @@ class CommandActionBuilderWithState {
78
82
  }
79
83
  /** Builds action */
80
84
  build() {
81
- return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, this.cooldownSeconds, this.blacklist, this.allowedUsers, this.condition, this.stateConstructor);
85
+ return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, this.cooldownSeconds, this.blacklist, this.allowedUsers, this.condition, this.stateConstructor, this.readme);
82
86
  }
83
87
  }
84
88
  exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
@@ -24,6 +24,7 @@ export class CommandAction<TActionState extends IActionState>
24
24
  readonly condition: CommandCondition<TActionState>;
25
25
  readonly stateConstructor: () => TActionState;
26
26
  readonly key: ActionKey;
27
+ readonly readme: string;
27
28
 
28
29
  constructor(
29
30
  trigger: CommandTrigger | CommandTrigger[],
@@ -34,7 +35,8 @@ export class CommandAction<TActionState extends IActionState>
34
35
  chatsBlacklist: number[],
35
36
  allowedUsers: number[],
36
37
  condition: CommandCondition<TActionState>,
37
- stateConstructor: () => TActionState
38
+ stateConstructor: () => TActionState,
39
+ readme: string
38
40
  ) {
39
41
  this.triggers = toArray(trigger);
40
42
  this.handler = handler;
@@ -45,6 +47,7 @@ export class CommandAction<TActionState extends IActionState>
45
47
  this.allowedUsers = allowedUsers;
46
48
  this.condition = condition;
47
49
  this.stateConstructor = stateConstructor;
50
+ this.readme = readme;
48
51
 
49
52
  this.key = `command:${this.name.replace('.', '-')}` as ActionKey;
50
53
  }
@@ -23,6 +23,7 @@ import { createTrace } from '../helpers/traceFactory';
23
23
  import { InlineQueryAction } from './actions/inlineQueryAction';
24
24
  import { IncomingInlineQuery } from '../dtos/incomingQuery';
25
25
  import { InlineQueryContext } from './context/inlineQueryContext';
26
+ import { buildHelpCommand } from '../builtin/helpAction';
26
27
 
27
28
  export class BotInstance {
28
29
  private readonly api: TelegramApiService;
@@ -56,7 +57,17 @@ export class BotInstance {
56
57
  };
57
58
  }) {
58
59
  this.name = options.name;
59
- this.commands = options.actions.commands;
60
+ this.commands =
61
+ options.actions.commands.length > 0
62
+ ? [
63
+ buildHelpCommand(
64
+ options.actions.commands
65
+ .map((x) => x.readme)
66
+ .filter((x) => !!x)
67
+ ),
68
+ ...options.actions.commands
69
+ ]
70
+ : [];
60
71
  this.scheduled = options.actions.scheduled;
61
72
  this.inlineQueries = options.actions.inlineQueries;
62
73
  this.chats = options.chats;
@@ -80,7 +91,7 @@ export class BotInstance {
80
91
  this.initializeMessageProcessing(
81
92
  options.verboseLoggingForIncomingMessage ?? false
82
93
  );
83
- this.initializeInlineQueryProcessing(500 as Milliseconds);
94
+ this.initializeInlineQueryProcessing(1000 as Milliseconds);
84
95
  this.initializeScheduledProcessing(
85
96
  options.scheduledPeriod ?? hoursToSeconds(1 as Hours)
86
97
  );
@@ -16,6 +16,7 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
16
16
  trigger: CommandTrigger | CommandTrigger[] = [];
17
17
 
18
18
  active = true;
19
+ readme = '';
19
20
  cooldownSeconds: Seconds = 0 as Seconds;
20
21
  blacklist: number[] = [];
21
22
  allowedUsers: number[] = [];
@@ -72,6 +73,10 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
72
73
  return this;
73
74
  }
74
75
 
76
+ withHelp(readme: string) {
77
+ this.readme = readme;
78
+ }
79
+
75
80
  /** If called during building, action is marked as disabled and never checked. */
76
81
  disabled() {
77
82
  this.active = false;
@@ -109,7 +114,8 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
109
114
  this.blacklist,
110
115
  this.allowedUsers,
111
116
  this.condition,
112
- this.stateConstructor
117
+ this.stateConstructor,
118
+ this.readme
113
119
  );
114
120
  }
115
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chz-telegram-bot",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "async-sema": "^3.1.1",