chz-telegram-bot 0.0.31 → 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 +25 -19
- package/dist/entities/botInstance.d.ts.map +1 -1
- package/dist/entities/botInstance.js +1 -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 +31 -25
- package/entities/botInstance.ts +1 -2
- 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);
|
|
@@ -54,31 +55,36 @@ class CommandAction {
|
|
|
54
55
|
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
|
|
55
56
|
const isUserAllowed = this.allowedUsers.length == 0 ||
|
|
56
57
|
this.allowedUsers.includes(ctx.fromUserId);
|
|
58
|
+
if (!isUserAllowed)
|
|
59
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
|
|
57
60
|
const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
|
|
58
61
|
const cooldownInMilliseconds = (0, timeConvertions_1.secondsToMilliseconds)(this.cooldownInSeconds);
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
const onCooldown = (0, moment_1.default)().diff(lastExecutedDate) < cooldownInMilliseconds;
|
|
63
|
+
if (onCooldown)
|
|
64
|
+
return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
|
|
65
|
+
if (trigger == commandTrigger_1.NonTextMessage.Any) {
|
|
66
|
+
shouldTrigger = ctx.messageText == '';
|
|
67
|
+
}
|
|
68
|
+
else if (typeof trigger == 'string') {
|
|
69
|
+
shouldTrigger = ctx.messageText.toLowerCase() == trigger;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
trigger.lastIndex = 0;
|
|
73
|
+
const execResult = trigger.exec(ctx.messageText);
|
|
74
|
+
if (execResult != null) {
|
|
75
|
+
matchResults.push(execResult);
|
|
76
|
+
if (trigger.global) {
|
|
77
|
+
while (true) {
|
|
78
|
+
const nextResult = trigger.exec(ctx.messageText);
|
|
79
|
+
if (nextResult == null)
|
|
80
|
+
break;
|
|
81
|
+
matchResults.push(nextResult);
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
|
-
shouldTrigger = matchResults.length > 0;
|
|
79
84
|
}
|
|
85
|
+
shouldTrigger = matchResults.length > 0;
|
|
80
86
|
}
|
|
81
|
-
return new commandTriggerCheckResult_1.CommandTriggerCheckResult(shouldTrigger, matchResults,
|
|
87
|
+
return new commandTriggerCheckResult_1.CommandTriggerCheckResult(shouldTrigger, matchResults, false);
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
exports.CommandAction = CommandAction;
|
|
@@ -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;AAM5D,qBAAa,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,EAAE,cAAc,CAAC;gBAEZ,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,aAAa,CAAC,EAAE,cAAc,CAAC;QAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC7B;IAmCD,OAAO,CAAC,6BAA6B;
|
|
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;AAM5D,qBAAa,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,EAAE,cAAc,CAAC;gBAEZ,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,aAAa,CAAC,EAAE,cAAc,CAAC;QAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC7B;IAmCD,OAAO,CAAC,6BAA6B;IA4CrC,OAAO,CAAC,2BAA2B;IAsB7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAYT,YAAY;YAyBZ,cAAc;CAmB/B"}
|
|
@@ -33,13 +33,13 @@ class BotInstance {
|
|
|
33
33
|
initializeScheduledProcessing(period) {
|
|
34
34
|
if (this.scheduled.length > 0) {
|
|
35
35
|
const now = (0, moment_1.default)();
|
|
36
|
-
let nextExecutionTime = now.clone().startOf('hour');
|
|
37
36
|
if (now.minute() == 0 && now.second() == 0) {
|
|
38
37
|
taskScheduler_1.Scheduler.createTask('ScheduledProcessing', async () => {
|
|
39
38
|
await this.runScheduled();
|
|
40
39
|
}, (0, timeConvertions_1.secondsToMilliseconds)(period), true, this.name);
|
|
41
40
|
return;
|
|
42
41
|
}
|
|
42
|
+
let nextExecutionTime = now.clone().startOf('hour');
|
|
43
43
|
if (now.minute() > 0 || now.second() > 0) {
|
|
44
44
|
nextExecutionTime = nextExecutionTime.add(1, 'hour');
|
|
45
45
|
}
|
|
@@ -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":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;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D;;GAEG;AACH,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,CAAM;IAEhD,MAAM,UAAQ;IACd,eAAe,EAAE,OAAO,CAAgB;IACxC,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,YAAY,EAAE,MAAM,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,iFAAiF;IACjF,QAAQ;IAMR;;OAEG;IACH,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;
|
|
@@ -112,40 +113,45 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
112
113
|
this.allowedUsers.length == 0 ||
|
|
113
114
|
this.allowedUsers.includes(ctx.fromUserId);
|
|
114
115
|
|
|
116
|
+
if (!isUserAllowed)
|
|
117
|
+
return CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
|
|
118
|
+
|
|
115
119
|
const lastExecutedDate = moment(state.lastExecutedDate);
|
|
116
120
|
const cooldownInMilliseconds = secondsToMilliseconds(
|
|
117
121
|
this.cooldownInSeconds
|
|
118
122
|
);
|
|
119
|
-
const
|
|
120
|
-
moment().diff(lastExecutedDate)
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
123
|
+
const onCooldown =
|
|
124
|
+
moment().diff(lastExecutedDate) < cooldownInMilliseconds;
|
|
125
|
+
|
|
126
|
+
if (onCooldown) return CommandTriggerCheckResult.DoNotTrigger;
|
|
127
|
+
|
|
128
|
+
if (trigger == NonTextMessage.Any) {
|
|
129
|
+
shouldTrigger = ctx.messageText == '';
|
|
130
|
+
} else if (typeof trigger == 'string') {
|
|
131
|
+
shouldTrigger = ctx.messageText.toLowerCase() == trigger;
|
|
132
|
+
} else {
|
|
133
|
+
trigger.lastIndex = 0;
|
|
134
|
+
|
|
135
|
+
const execResult = trigger.exec(ctx.messageText);
|
|
136
|
+
if (execResult != null) {
|
|
137
|
+
matchResults.push(execResult);
|
|
138
|
+
|
|
139
|
+
if (trigger.global) {
|
|
140
|
+
while (true) {
|
|
141
|
+
const nextResult = trigger.exec(ctx.messageText);
|
|
142
|
+
if (nextResult == null) break;
|
|
143
|
+
matchResults.push(nextResult);
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
|
-
|
|
141
|
-
shouldTrigger = matchResults.length > 0;
|
|
142
146
|
}
|
|
147
|
+
|
|
148
|
+
shouldTrigger = matchResults.length > 0;
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
return new CommandTriggerCheckResult(
|
|
146
152
|
shouldTrigger,
|
|
147
153
|
matchResults,
|
|
148
|
-
|
|
154
|
+
false
|
|
149
155
|
);
|
|
150
156
|
}
|
|
151
157
|
}
|
package/entities/botInstance.ts
CHANGED
|
@@ -72,8 +72,6 @@ export class BotInstance {
|
|
|
72
72
|
if (this.scheduled.length > 0) {
|
|
73
73
|
const now = moment();
|
|
74
74
|
|
|
75
|
-
let nextExecutionTime = now.clone().startOf('hour');
|
|
76
|
-
|
|
77
75
|
if (now.minute() == 0 && now.second() == 0) {
|
|
78
76
|
Scheduler.createTask(
|
|
79
77
|
'ScheduledProcessing',
|
|
@@ -88,6 +86,7 @@ export class BotInstance {
|
|
|
88
86
|
return;
|
|
89
87
|
}
|
|
90
88
|
|
|
89
|
+
let nextExecutionTime = now.clone().startOf('hour');
|
|
91
90
|
if (now.minute() > 0 || now.second() > 0) {
|
|
92
91
|
nextExecutionTime = nextExecutionTime.add(1, 'hour');
|
|
93
92
|
}
|
|
@@ -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