chz-telegram-bot 0.0.29 → 0.0.30
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,3 +1,4 @@
|
|
|
1
|
+
import { Seconds } from '../types/timeValues';
|
|
1
2
|
import { IStorageClient } from '../types/storage';
|
|
2
3
|
import { IActionState } from '../types/actionState';
|
|
3
4
|
import { CommandAction } from './actions/commandAction';
|
|
@@ -18,6 +19,7 @@ export declare class BotInstance {
|
|
|
18
19
|
chats: Record<string, number>;
|
|
19
20
|
storageClient?: IStorageClient;
|
|
20
21
|
storagePath?: string;
|
|
22
|
+
scheduledPeriod?: Seconds;
|
|
21
23
|
});
|
|
22
24
|
private initializeScheduledProcessing;
|
|
23
25
|
private initializeMessageProcessing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"
|
|
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;IA6CrC,OAAO,CAAC,2BAA2B;IAsB7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAYT,YAAY;YAyBZ,cAAc;CAmB/B"}
|
|
@@ -26,18 +26,18 @@ class BotInstance {
|
|
|
26
26
|
new jsonFileStorage_1.JsonFileStorage(options.name, actions, options.storagePath);
|
|
27
27
|
this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage, this.chats);
|
|
28
28
|
this.initializeMessageProcessing();
|
|
29
|
-
this.initializeScheduledProcessing();
|
|
29
|
+
this.initializeScheduledProcessing(options.scheduledPeriod ?? (0, timeConvertions_1.hoursToSeconds)(1));
|
|
30
30
|
this.storage.saveMetadata(actions, this.name);
|
|
31
31
|
this.telegraf.launch();
|
|
32
32
|
}
|
|
33
|
-
initializeScheduledProcessing() {
|
|
33
|
+
initializeScheduledProcessing(period) {
|
|
34
34
|
if (this.scheduled.length > 0) {
|
|
35
35
|
const now = (0, moment_1.default)();
|
|
36
36
|
let nextExecutionTime = now.clone().startOf('hour');
|
|
37
37
|
if (now.minute() == 0 && now.second() == 0) {
|
|
38
38
|
taskScheduler_1.Scheduler.createTask('ScheduledProcessing', async () => {
|
|
39
39
|
await this.runScheduled();
|
|
40
|
-
}, (0, timeConvertions_1.
|
|
40
|
+
}, (0, timeConvertions_1.secondsToMilliseconds)(period), true, this.name);
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
if (now.minute() > 0 || now.second() > 0) {
|
|
@@ -47,7 +47,7 @@ class BotInstance {
|
|
|
47
47
|
taskScheduler_1.Scheduler.createOnetimeTask('ScheduledProcessing_OneTime', async () => {
|
|
48
48
|
taskScheduler_1.Scheduler.createTask('ScheduledProcessing', async () => {
|
|
49
49
|
await this.runScheduled();
|
|
50
|
-
}, (0, timeConvertions_1.
|
|
50
|
+
}, (0, timeConvertions_1.secondsToMilliseconds)(period), true, this.name);
|
|
51
51
|
}, delay, this.name);
|
|
52
52
|
}
|
|
53
53
|
}
|
package/entities/botInstance.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Telegraf } from 'telegraf';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
hoursToSeconds,
|
|
4
|
+
secondsToMilliseconds
|
|
5
|
+
} from '../helpers/timeConvertions';
|
|
6
|
+
import { Hours, Milliseconds, Seconds } from '../types/timeValues';
|
|
4
7
|
import { IStorageClient } from '../types/storage';
|
|
5
8
|
import { JsonFileStorage } from '../services/jsonFileStorage';
|
|
6
9
|
import { TelegramApiService } from '../services/telegramApi';
|
|
@@ -29,6 +32,7 @@ export class BotInstance {
|
|
|
29
32
|
chats: Record<string, number>;
|
|
30
33
|
storageClient?: IStorageClient;
|
|
31
34
|
storagePath?: string;
|
|
35
|
+
scheduledPeriod?: Seconds;
|
|
32
36
|
}) {
|
|
33
37
|
this.name = options.name;
|
|
34
38
|
this.commands = options.commands;
|
|
@@ -55,14 +59,16 @@ export class BotInstance {
|
|
|
55
59
|
);
|
|
56
60
|
|
|
57
61
|
this.initializeMessageProcessing();
|
|
58
|
-
this.initializeScheduledProcessing(
|
|
62
|
+
this.initializeScheduledProcessing(
|
|
63
|
+
options.scheduledPeriod ?? hoursToSeconds(1 as Hours)
|
|
64
|
+
);
|
|
59
65
|
|
|
60
66
|
this.storage.saveMetadata(actions, this.name);
|
|
61
67
|
|
|
62
68
|
this.telegraf.launch();
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
private initializeScheduledProcessing() {
|
|
71
|
+
private initializeScheduledProcessing(period: Seconds) {
|
|
66
72
|
if (this.scheduled.length > 0) {
|
|
67
73
|
const now = moment();
|
|
68
74
|
|
|
@@ -74,7 +80,7 @@ export class BotInstance {
|
|
|
74
80
|
async () => {
|
|
75
81
|
await this.runScheduled();
|
|
76
82
|
},
|
|
77
|
-
|
|
83
|
+
secondsToMilliseconds(period),
|
|
78
84
|
true,
|
|
79
85
|
this.name
|
|
80
86
|
);
|
|
@@ -96,7 +102,7 @@ export class BotInstance {
|
|
|
96
102
|
async () => {
|
|
97
103
|
await this.runScheduled();
|
|
98
104
|
},
|
|
99
|
-
|
|
105
|
+
secondsToMilliseconds(period),
|
|
100
106
|
true,
|
|
101
107
|
this.name
|
|
102
108
|
);
|