chz-telegram-bot 0.0.31 → 0.0.32

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.
@@ -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;AAI3D,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB;IAE3B,QAAQ,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC9B,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,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAC9C,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,E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AAc,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;CAsDvB"}
@@ -54,31 +54,33 @@ class CommandAction {
54
54
  return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
55
55
  const isUserAllowed = this.allowedUsers.length == 0 ||
56
56
  this.allowedUsers.includes(ctx.fromUserId);
57
+ if (!isUserAllowed)
58
+ return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
57
59
  const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
58
60
  const cooldownInMilliseconds = (0, timeConvertions_1.secondsToMilliseconds)(this.cooldownInSeconds);
59
- const notOnCooldown = (0, moment_1.default)().diff(lastExecutedDate) >= cooldownInMilliseconds;
60
- if (isUserAllowed && notOnCooldown) {
61
- if (typeof trigger == 'string') {
62
- shouldTrigger = ctx.messageText.toLowerCase() == trigger;
63
- }
64
- else {
65
- trigger.lastIndex = 0;
66
- const execResult = trigger.exec(ctx.messageText);
67
- if (execResult != null) {
68
- matchResults.push(execResult);
69
- if (trigger.global) {
70
- while (true) {
71
- const nextResult = trigger.exec(ctx.messageText);
72
- if (nextResult == null)
73
- break;
74
- matchResults.push(nextResult);
75
- }
61
+ const onCooldown = (0, moment_1.default)().diff(lastExecutedDate) < cooldownInMilliseconds;
62
+ if (onCooldown)
63
+ return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
64
+ if (typeof trigger == 'string') {
65
+ shouldTrigger = ctx.messageText.toLowerCase() == trigger;
66
+ }
67
+ else {
68
+ trigger.lastIndex = 0;
69
+ const execResult = trigger.exec(ctx.messageText);
70
+ if (execResult != null) {
71
+ matchResults.push(execResult);
72
+ if (trigger.global) {
73
+ while (true) {
74
+ const nextResult = trigger.exec(ctx.messageText);
75
+ if (nextResult == null)
76
+ break;
77
+ matchResults.push(nextResult);
76
78
  }
77
79
  }
78
- shouldTrigger = matchResults.length > 0;
79
80
  }
81
+ shouldTrigger = matchResults.length > 0;
80
82
  }
81
- return new commandTriggerCheckResult_1.CommandTriggerCheckResult(shouldTrigger, matchResults, !isUserAllowed);
83
+ return new commandTriggerCheckResult_1.CommandTriggerCheckResult(shouldTrigger, matchResults, false);
82
84
  }
83
85
  }
84
86
  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,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yBZ,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
  }
@@ -112,40 +112,43 @@ export class CommandAction<TActionState extends IActionState>
112
112
  this.allowedUsers.length == 0 ||
113
113
  this.allowedUsers.includes(ctx.fromUserId);
114
114
 
115
+ if (!isUserAllowed)
116
+ return CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
117
+
115
118
  const lastExecutedDate = moment(state.lastExecutedDate);
116
119
  const cooldownInMilliseconds = secondsToMilliseconds(
117
120
  this.cooldownInSeconds
118
121
  );
119
- const notOnCooldown =
120
- moment().diff(lastExecutedDate) >= cooldownInMilliseconds;
121
-
122
- if (isUserAllowed && notOnCooldown) {
123
- if (typeof trigger == 'string') {
124
- shouldTrigger = ctx.messageText.toLowerCase() == trigger;
125
- } else {
126
- trigger.lastIndex = 0;
127
-
128
- const execResult = trigger.exec(ctx.messageText);
129
- if (execResult != null) {
130
- matchResults.push(execResult);
131
-
132
- if (trigger.global) {
133
- while (true) {
134
- const nextResult = trigger.exec(ctx.messageText);
135
- if (nextResult == null) break;
136
- matchResults.push(nextResult);
137
- }
122
+ const onCooldown =
123
+ moment().diff(lastExecutedDate) < cooldownInMilliseconds;
124
+
125
+ if (onCooldown) return CommandTriggerCheckResult.DoNotTrigger;
126
+
127
+ if (typeof trigger == 'string') {
128
+ shouldTrigger = ctx.messageText.toLowerCase() == trigger;
129
+ } else {
130
+ trigger.lastIndex = 0;
131
+
132
+ const execResult = trigger.exec(ctx.messageText);
133
+ if (execResult != null) {
134
+ matchResults.push(execResult);
135
+
136
+ if (trigger.global) {
137
+ while (true) {
138
+ const nextResult = trigger.exec(ctx.messageText);
139
+ if (nextResult == null) break;
140
+ matchResults.push(nextResult);
138
141
  }
139
142
  }
140
-
141
- shouldTrigger = matchResults.length > 0;
142
143
  }
144
+
145
+ shouldTrigger = matchResults.length > 0;
143
146
  }
144
147
 
145
148
  return new CommandTriggerCheckResult(
146
149
  shouldTrigger,
147
150
  matchResults,
148
- !isUserAllowed
151
+ false
149
152
  );
150
153
  }
151
154
  }
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chz-telegram-bot",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "async-sema": "^3.1.1",