chz-telegram-bot 0.0.32 → 0.0.33
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 +3 -2
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +5 -1
- package/dist/helpers/builders/commandActionBuilder.d.ts +3 -2
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/types/commandTrigger.d.ts +5 -0
- package/dist/types/commandTrigger.d.ts.map +1 -0
- package/dist/types/commandTrigger.js +7 -0
- package/entities/actions/commandAction.ts +7 -4
- package/helpers/builders/commandActionBuilder.ts +3 -2
- package/package.json +1 -1
- package/types/commandTrigger.ts +5 -0
|
@@ -4,8 +4,9 @@ import { Seconds } from '../../types/timeValues';
|
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
5
|
import { IActionWithState, ActionKey } from '../../types/actionWithState';
|
|
6
6
|
import { MessageContext } from '../context/messageContext';
|
|
7
|
+
import { CommandTrigger } from '../../types/commandTrigger';
|
|
7
8
|
export declare class CommandAction<TActionState extends IActionState> implements IActionWithState {
|
|
8
|
-
triggers:
|
|
9
|
+
triggers: CommandTrigger[];
|
|
9
10
|
handler: CommandHandler<TActionState>;
|
|
10
11
|
name: string;
|
|
11
12
|
cooldownInSeconds: Seconds;
|
|
@@ -15,7 +16,7 @@ export declare class CommandAction<TActionState extends IActionState> implements
|
|
|
15
16
|
condition: CommandCondition<TActionState>;
|
|
16
17
|
stateConstructor: () => TActionState;
|
|
17
18
|
key: ActionKey;
|
|
18
|
-
constructor(trigger:
|
|
19
|
+
constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState);
|
|
19
20
|
exec(ctx: MessageContext<TActionState>): Promise<void>;
|
|
20
21
|
private checkTrigger;
|
|
21
22
|
}
|
|
@@ -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,6BAA6B,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,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,EAAE,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAkB,MAAM,4BAA4B,CAAC;AAE5E,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB;IAE3B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,OAAO,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC1C,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,GAAG,EAAE,SAAS,CAAC;gBAGX,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;IAelC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC;IAgD5C,OAAO,CAAC,YAAY;CAwDvB"}
|
|
@@ -10,6 +10,7 @@ const toArray_1 = require("../../helpers/toArray");
|
|
|
10
10
|
const commandTriggerCheckResult_1 = require("../commandTriggerCheckResult");
|
|
11
11
|
const logger_1 = require("../../services/logger");
|
|
12
12
|
const actionExecutionResult_1 = require("../actionExecutionResult");
|
|
13
|
+
const commandTrigger_1 = require("../../types/commandTrigger");
|
|
13
14
|
class CommandAction {
|
|
14
15
|
constructor(trigger, handler, name, active, cooldown, chatsBlacklist, allowedUsers, condition, stateConstructor) {
|
|
15
16
|
this.triggers = (0, toArray_1.toArray)(trigger);
|
|
@@ -61,7 +62,10 @@ class CommandAction {
|
|
|
61
62
|
const onCooldown = (0, moment_1.default)().diff(lastExecutedDate) < cooldownInMilliseconds;
|
|
62
63
|
if (onCooldown)
|
|
63
64
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
|
|
64
|
-
if (
|
|
65
|
+
if (trigger == commandTrigger_1.NonTextMessage.Any) {
|
|
66
|
+
shouldTrigger = ctx.messageText == '';
|
|
67
|
+
}
|
|
68
|
+
else if (typeof trigger == 'string') {
|
|
65
69
|
shouldTrigger = ctx.messageText.toLowerCase() == trigger;
|
|
66
70
|
}
|
|
67
71
|
else {
|
|
@@ -4,12 +4,13 @@ import { Seconds } from '../../types/timeValues';
|
|
|
4
4
|
import { CommandAction } from '../../entities/actions/commandAction';
|
|
5
5
|
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
6
6
|
import { IActionState } from '../../types/actionState';
|
|
7
|
+
import { CommandTrigger } from '../../types/commandTrigger';
|
|
7
8
|
/**
|
|
8
9
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
9
10
|
*/
|
|
10
11
|
export declare class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
11
12
|
name: string;
|
|
12
|
-
trigger:
|
|
13
|
+
trigger: CommandTrigger | CommandTrigger[];
|
|
13
14
|
active: boolean;
|
|
14
15
|
cooldownSeconds: Seconds;
|
|
15
16
|
blacklist: number[];
|
|
@@ -29,7 +30,7 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
29
30
|
*
|
|
30
31
|
* If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
|
|
31
32
|
*/
|
|
32
|
-
on(trigger:
|
|
33
|
+
on(trigger: CommandTrigger | CommandTrigger[]): this;
|
|
33
34
|
/** Defines id (or ids) of users that are allowed to trigger this action.
|
|
34
35
|
* @param id User id or ids
|
|
35
36
|
*/
|
|
@@ -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,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version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QAAQ,CAAC,OAAO,EAAE,OAAO;IAMzB;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM;IAMzB,oBAAoB;IACpB,KAAK;CAaR;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,6BAA6B,CAAC,eAAe,CAAC;IACpF;;OAEG;gBACS,IAAI,EAAE,MAAM;CAG3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandTrigger.d.ts","sourceRoot":"","sources":["../../types/commandTrigger.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACtB,GAAG,IAAA;CACN;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NonTextMessage = void 0;
|
|
4
|
+
var NonTextMessage;
|
|
5
|
+
(function (NonTextMessage) {
|
|
6
|
+
NonTextMessage[NonTextMessage["Any"] = 0] = "Any";
|
|
7
|
+
})(NonTextMessage || (exports.NonTextMessage = NonTextMessage = {}));
|
|
@@ -10,11 +10,12 @@ import { CommandTriggerCheckResult } from '../commandTriggerCheckResult';
|
|
|
10
10
|
import { MessageContext } from '../context/messageContext';
|
|
11
11
|
import { Logger } from '../../services/logger';
|
|
12
12
|
import { ActionExecutionResult } from '../actionExecutionResult';
|
|
13
|
+
import { CommandTrigger, NonTextMessage } from '../../types/commandTrigger';
|
|
13
14
|
|
|
14
15
|
export class CommandAction<TActionState extends IActionState>
|
|
15
16
|
implements IActionWithState
|
|
16
17
|
{
|
|
17
|
-
triggers:
|
|
18
|
+
triggers: CommandTrigger[];
|
|
18
19
|
handler: CommandHandler<TActionState>;
|
|
19
20
|
name: string;
|
|
20
21
|
cooldownInSeconds: Seconds;
|
|
@@ -26,7 +27,7 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
26
27
|
key: ActionKey;
|
|
27
28
|
|
|
28
29
|
constructor(
|
|
29
|
-
trigger:
|
|
30
|
+
trigger: CommandTrigger | CommandTrigger[],
|
|
30
31
|
handler: CommandHandler<TActionState>,
|
|
31
32
|
name: string,
|
|
32
33
|
active: boolean,
|
|
@@ -99,7 +100,7 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
99
100
|
|
|
100
101
|
private checkTrigger(
|
|
101
102
|
ctx: MessageContext<TActionState>,
|
|
102
|
-
trigger:
|
|
103
|
+
trigger: CommandTrigger,
|
|
103
104
|
state: IActionState
|
|
104
105
|
) {
|
|
105
106
|
let shouldTrigger = false;
|
|
@@ -124,7 +125,9 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
124
125
|
|
|
125
126
|
if (onCooldown) return CommandTriggerCheckResult.DoNotTrigger;
|
|
126
127
|
|
|
127
|
-
if (
|
|
128
|
+
if (trigger == NonTextMessage.Any) {
|
|
129
|
+
shouldTrigger = ctx.messageText == '';
|
|
130
|
+
} else if (typeof trigger == 'string') {
|
|
128
131
|
shouldTrigger = ctx.messageText.toLowerCase() == trigger;
|
|
129
132
|
} else {
|
|
130
133
|
trigger.lastIndex = 0;
|
|
@@ -6,13 +6,14 @@ import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
|
6
6
|
import { IActionState } from '../../types/actionState';
|
|
7
7
|
import { toArray } from '../toArray';
|
|
8
8
|
import { Noop } from '../noop';
|
|
9
|
+
import { CommandTrigger } from '../../types/commandTrigger';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Builder for `CommandAction` with state represented by `TActionState`
|
|
12
13
|
*/
|
|
13
14
|
export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
14
15
|
name: string;
|
|
15
|
-
trigger:
|
|
16
|
+
trigger: CommandTrigger | CommandTrigger[] = [];
|
|
16
17
|
|
|
17
18
|
active = true;
|
|
18
19
|
cooldownSeconds: Seconds = 0 as Seconds;
|
|
@@ -38,7 +39,7 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
38
39
|
*
|
|
39
40
|
* If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
|
|
40
41
|
*/
|
|
41
|
-
on(trigger:
|
|
42
|
+
on(trigger: CommandTrigger | CommandTrigger[]) {
|
|
42
43
|
this.trigger = trigger;
|
|
43
44
|
|
|
44
45
|
return this;
|
package/package.json
CHANGED