chz-telegram-bot 0.1.9 → 0.1.11
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/dist/entities/actions/commandAction.d.ts +2 -2
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +2 -2
- package/dist/entities/botInstance.d.ts +1 -0
- package/dist/entities/botInstance.d.ts.map +1 -1
- package/dist/entities/botInstance.js +4 -3
- package/dist/helpers/builders/commandActionBuilder.d.ts +2 -2
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/commandActionBuilder.js +5 -4
- package/entities/actions/commandAction.ts +3 -3
- package/entities/botInstance.ts +9 -3
- package/eslint.config.js +14 -0
- package/helpers/builders/commandActionBuilder.ts +6 -4
- package/package.json +1 -1
|
@@ -16,8 +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
|
-
readonly
|
|
20
|
-
constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState,
|
|
19
|
+
readonly readmeFactory: (botName: string) => string;
|
|
20
|
+
constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState, readmeFactory: (botName: string) => string);
|
|
21
21
|
exec(ctx: MessageContext<TActionState>): Promise<import("../../types/response").BotResponse[]>;
|
|
22
22
|
private checkIfShouldBeExecuted;
|
|
23
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,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,
|
|
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,EA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,EAAE,MAAM,KAAK,MAAM;IAgBxC,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, readmeFactory) {
|
|
14
14
|
this.triggers = (0, toArray_1.toArray)(trigger);
|
|
15
15
|
this.handler = handler;
|
|
16
16
|
this.name = name;
|
|
@@ -20,7 +20,7 @@ class CommandAction {
|
|
|
20
20
|
this.allowedUsers = allowedUsers;
|
|
21
21
|
this.condition = condition;
|
|
22
22
|
this.stateConstructor = stateConstructor;
|
|
23
|
-
this.
|
|
23
|
+
this.readmeFactory = readmeFactory;
|
|
24
24
|
this.key = `command:${this.name.replace('.', '-')}`;
|
|
25
25
|
}
|
|
26
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,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AC;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;IAwDD,OAAO,CAAC,6BAA6B;IA4CrC,OAAO,CAAC,+BAA+B;IA2EvC,OAAO,CAAC,2BAA2B;IAiC7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAaT,YAAY;YAuCZ,cAAc;CA2B/B"}
|
|
@@ -21,12 +21,15 @@ const inlineQueryContext_1 = require("./context/inlineQueryContext");
|
|
|
21
21
|
const helpAction_1 = require("../builtin/helpAction");
|
|
22
22
|
class BotInstance {
|
|
23
23
|
constructor(options) {
|
|
24
|
+
this.telegraf = new telegraf_1.Telegraf(options.token);
|
|
25
|
+
this.telegraf.launch();
|
|
26
|
+
this.botInfo = this.telegraf.botInfo;
|
|
24
27
|
this.name = options.name;
|
|
25
28
|
this.commands =
|
|
26
29
|
options.actions.commands.length > 0
|
|
27
30
|
? [
|
|
28
31
|
(0, helpAction_1.buildHelpCommand)(options.actions.commands
|
|
29
|
-
.map((x) => x.
|
|
32
|
+
.map((x) => x.readmeFactory(this.botInfo.username))
|
|
30
33
|
.filter((x) => !!x)),
|
|
31
34
|
...options.actions.commands
|
|
32
35
|
]
|
|
@@ -35,7 +38,6 @@ class BotInstance {
|
|
|
35
38
|
this.inlineQueries = options.actions.inlineQueries;
|
|
36
39
|
this.chats = options.chats;
|
|
37
40
|
const actions = [...this.commands, ...this.scheduled];
|
|
38
|
-
this.telegraf = new telegraf_1.Telegraf(options.token);
|
|
39
41
|
this.logger = options.services?.logger ?? new jsonLogger_1.JsonLogger();
|
|
40
42
|
this.scheduler =
|
|
41
43
|
options.services?.scheduler ??
|
|
@@ -49,7 +51,6 @@ class BotInstance {
|
|
|
49
51
|
this.initializeScheduledProcessing(options.scheduledPeriod ?? (0, timeConvertions_1.hoursToSeconds)(1));
|
|
50
52
|
this.storage.saveMetadata(actions, this.name);
|
|
51
53
|
this.logger.logWithTraceId(this.name, (0, traceFactory_1.createTrace)(this, this.name, 'Start'), 'System', 'Starting bot...');
|
|
52
|
-
this.telegraf.launch();
|
|
53
54
|
}
|
|
54
55
|
initializeScheduledProcessing(period) {
|
|
55
56
|
if (this.scheduled.length > 0) {
|
|
@@ -12,7 +12,7 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
12
12
|
name: string;
|
|
13
13
|
trigger: CommandTrigger | CommandTrigger[];
|
|
14
14
|
active: boolean;
|
|
15
|
-
|
|
15
|
+
readmeFactory: null | ((botName: string) => string);
|
|
16
16
|
cooldownSeconds: Seconds;
|
|
17
17
|
blacklist: number[];
|
|
18
18
|
allowedUsers: number[];
|
|
@@ -44,7 +44,7 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
44
44
|
* @param condition Condition check predicate
|
|
45
45
|
*/
|
|
46
46
|
when(condition: CommandCondition<TActionState>): this;
|
|
47
|
-
withHelp(
|
|
47
|
+
withHelp(readmeFactory: (botName: string) => string): this;
|
|
48
48
|
/** If called during building, action is marked as disabled and never checked. */
|
|
49
49
|
disabled(): this;
|
|
50
50
|
/** Sets action cooldown.
|
|
@@ -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,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AAM,EAAE,CAAM;IAC5B,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAa;IAClD,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAa;IAEtD;;;;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;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC;IAMxC;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAM9C,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM;IAMnD,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,7 +17,7 @@ class CommandActionBuilderWithState {
|
|
|
17
17
|
constructor(name, stateConstructor) {
|
|
18
18
|
this.trigger = [];
|
|
19
19
|
this.active = true;
|
|
20
|
-
this.
|
|
20
|
+
this.readmeFactory = null;
|
|
21
21
|
this.cooldownSeconds = 0;
|
|
22
22
|
this.blacklist = [];
|
|
23
23
|
this.allowedUsers = [];
|
|
@@ -57,8 +57,9 @@ class CommandActionBuilderWithState {
|
|
|
57
57
|
this.condition = condition;
|
|
58
58
|
return this;
|
|
59
59
|
}
|
|
60
|
-
withHelp(
|
|
61
|
-
this.
|
|
60
|
+
withHelp(readmeFactory) {
|
|
61
|
+
this.readmeFactory = readmeFactory;
|
|
62
|
+
return this;
|
|
62
63
|
}
|
|
63
64
|
/** If called during building, action is marked as disabled and never checked. */
|
|
64
65
|
disabled() {
|
|
@@ -82,7 +83,7 @@ class CommandActionBuilderWithState {
|
|
|
82
83
|
}
|
|
83
84
|
/** Builds action */
|
|
84
85
|
build() {
|
|
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.
|
|
86
|
+
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, this.cooldownSeconds, this.blacklist, this.allowedUsers, this.condition, this.stateConstructor, this.readmeFactory != null ? this.readmeFactory : (_) => '');
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
|
|
@@ -24,7 +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
|
|
27
|
+
readonly readmeFactory: (botName: string) => string;
|
|
28
28
|
|
|
29
29
|
constructor(
|
|
30
30
|
trigger: CommandTrigger | CommandTrigger[],
|
|
@@ -36,7 +36,7 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
36
36
|
allowedUsers: number[],
|
|
37
37
|
condition: CommandCondition<TActionState>,
|
|
38
38
|
stateConstructor: () => TActionState,
|
|
39
|
-
|
|
39
|
+
readmeFactory: (botName: string) => string
|
|
40
40
|
) {
|
|
41
41
|
this.triggers = toArray(trigger);
|
|
42
42
|
this.handler = handler;
|
|
@@ -47,7 +47,7 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
47
47
|
this.allowedUsers = allowedUsers;
|
|
48
48
|
this.condition = condition;
|
|
49
49
|
this.stateConstructor = stateConstructor;
|
|
50
|
-
this.
|
|
50
|
+
this.readmeFactory = readmeFactory;
|
|
51
51
|
|
|
52
52
|
this.key = `command:${this.name.replace('.', '-')}` as ActionKey;
|
|
53
53
|
}
|
package/entities/botInstance.ts
CHANGED
|
@@ -24,12 +24,14 @@ import { InlineQueryAction } from './actions/inlineQueryAction';
|
|
|
24
24
|
import { IncomingInlineQuery } from '../dtos/incomingQuery';
|
|
25
25
|
import { InlineQueryContext } from './context/inlineQueryContext';
|
|
26
26
|
import { buildHelpCommand } from '../builtin/helpAction';
|
|
27
|
+
import { UserFromGetMe } from 'telegraf/types';
|
|
27
28
|
|
|
28
29
|
export class BotInstance {
|
|
29
30
|
private readonly api: TelegramApiService;
|
|
30
31
|
private readonly storage: IStorageClient;
|
|
31
32
|
private readonly scheduler: IScheduler;
|
|
32
33
|
private readonly logger: ILogger;
|
|
34
|
+
private readonly botInfo: UserFromGetMe;
|
|
33
35
|
|
|
34
36
|
readonly name: string;
|
|
35
37
|
private readonly telegraf: Telegraf;
|
|
@@ -56,13 +58,19 @@ export class BotInstance {
|
|
|
56
58
|
scheduler?: IScheduler;
|
|
57
59
|
};
|
|
58
60
|
}) {
|
|
61
|
+
this.telegraf = new Telegraf(options.token);
|
|
62
|
+
this.telegraf.launch();
|
|
63
|
+
this.botInfo = this.telegraf.botInfo!;
|
|
64
|
+
|
|
59
65
|
this.name = options.name;
|
|
60
66
|
this.commands =
|
|
61
67
|
options.actions.commands.length > 0
|
|
62
68
|
? [
|
|
63
69
|
buildHelpCommand(
|
|
64
70
|
options.actions.commands
|
|
65
|
-
.map((x) =>
|
|
71
|
+
.map((x) =>
|
|
72
|
+
x.readmeFactory(this.botInfo.username)
|
|
73
|
+
)
|
|
66
74
|
.filter((x) => !!x)
|
|
67
75
|
),
|
|
68
76
|
...options.actions.commands
|
|
@@ -73,7 +81,6 @@ export class BotInstance {
|
|
|
73
81
|
this.chats = options.chats;
|
|
74
82
|
|
|
75
83
|
const actions = [...this.commands, ...this.scheduled];
|
|
76
|
-
this.telegraf = new Telegraf(options.token);
|
|
77
84
|
this.logger = options.services?.logger ?? new JsonLogger();
|
|
78
85
|
this.scheduler =
|
|
79
86
|
options.services?.scheduler ??
|
|
@@ -104,7 +111,6 @@ export class BotInstance {
|
|
|
104
111
|
'System',
|
|
105
112
|
'Starting bot...'
|
|
106
113
|
);
|
|
107
|
-
this.telegraf.launch();
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
private initializeScheduledProcessing(period: Seconds) {
|
package/eslint.config.js
CHANGED
|
@@ -5,6 +5,20 @@ export default tseslint.config(
|
|
|
5
5
|
eslint.configs.recommended,
|
|
6
6
|
...tseslint.configs.recommended,
|
|
7
7
|
{
|
|
8
|
+
rules: {
|
|
9
|
+
'@typescript-eslint/no-unused-vars': [
|
|
10
|
+
'error',
|
|
11
|
+
{
|
|
12
|
+
args: 'all',
|
|
13
|
+
argsIgnorePattern: '^_',
|
|
14
|
+
caughtErrors: 'all',
|
|
15
|
+
caughtErrorsIgnorePattern: '^_',
|
|
16
|
+
destructuredArrayIgnorePattern: '^_',
|
|
17
|
+
varsIgnorePattern: '^_',
|
|
18
|
+
ignoreRestSiblings: true
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
8
22
|
ignores: ['dist/*']
|
|
9
23
|
}
|
|
10
24
|
);
|
|
@@ -16,7 +16,7 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
16
16
|
trigger: CommandTrigger | CommandTrigger[] = [];
|
|
17
17
|
|
|
18
18
|
active = true;
|
|
19
|
-
|
|
19
|
+
readmeFactory: null | ((botName: string) => string) = null;
|
|
20
20
|
cooldownSeconds: Seconds = 0 as Seconds;
|
|
21
21
|
blacklist: number[] = [];
|
|
22
22
|
allowedUsers: number[] = [];
|
|
@@ -73,8 +73,10 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
73
73
|
return this;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
withHelp(
|
|
77
|
-
this.
|
|
76
|
+
withHelp(readmeFactory: (botName: string) => string) {
|
|
77
|
+
this.readmeFactory = readmeFactory;
|
|
78
|
+
|
|
79
|
+
return this;
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
/** If called during building, action is marked as disabled and never checked. */
|
|
@@ -115,7 +117,7 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
115
117
|
this.allowedUsers,
|
|
116
118
|
this.condition,
|
|
117
119
|
this.stateConstructor,
|
|
118
|
-
this.
|
|
120
|
+
this.readmeFactory != null ? this.readmeFactory : (_) => ''
|
|
119
121
|
);
|
|
120
122
|
}
|
|
121
123
|
}
|