@kingsworld/plugin-cron 2.0.0-next.d6af196 → 2.0.0-next.d90cc7f
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/README.md +3 -3
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +103 -7
- package/dist/cjs/lib/CronTaskHandler.cjs +29 -2
- package/dist/cjs/lib/CronTaskHandler.cjs.map +1 -1
- package/dist/cjs/lib/structures/CronTask.cjs +35 -0
- package/dist/cjs/lib/structures/CronTask.cjs.map +1 -1
- package/dist/cjs/lib/structures/CronTaskStore.cjs +13 -0
- package/dist/cjs/lib/structures/CronTaskStore.cjs.map +1 -1
- package/dist/esm/index.d.mts +103 -7
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/CronTaskHandler.mjs +29 -2
- package/dist/esm/lib/CronTaskHandler.mjs.map +1 -1
- package/dist/esm/lib/structures/CronTask.mjs +35 -0
- package/dist/esm/lib/structures/CronTask.mjs.map +1 -1
- package/dist/esm/lib/structures/CronTaskStore.mjs +13 -0
- package/dist/esm/lib/structures/CronTaskStore.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
@@ -54,9 +54,9 @@ const options = {
|
|
54
54
|
disableSentry: false,
|
55
55
|
/**
|
56
56
|
* The timezone to use for the cron tasks
|
57
|
-
* @default '
|
57
|
+
* @default 'system'
|
58
58
|
*/
|
59
|
-
|
59
|
+
defaultTimezone: 'Europe/London'
|
60
60
|
}
|
61
61
|
};
|
62
62
|
```
|
@@ -122,7 +122,7 @@ The `CronTask` class provides logging helpers that are similar to the ones provi
|
|
122
122
|
|
123
123
|
This is an example of how to use the `info` helper:
|
124
124
|
|
125
|
-
```
|
125
|
+
```typescript
|
126
126
|
import { CronTask } from '@kingsworld/plugin-cron';
|
127
127
|
|
128
128
|
export class PingPong extends CronTask {
|
package/dist/cjs/index.cjs
CHANGED
@@ -6,7 +6,7 @@ var CronTaskStore_cjs = require('./lib/structures/CronTaskStore.cjs');
|
|
6
6
|
var CronTaskTypes_cjs = require('./lib/types/CronTaskTypes.cjs');
|
7
7
|
|
8
8
|
// src/index.ts
|
9
|
-
var version = "2.0.0-next.
|
9
|
+
var version = "2.0.0-next.d90cc7f";
|
10
10
|
|
11
11
|
exports.version = version;
|
12
12
|
Object.keys(CronTaskHandler_cjs).forEach(function (k) {
|
package/dist/cjs/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.cjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcron: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcron?: CronTaskHandlerOptions;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '2.0.0-next.
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.cjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcron: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcron?: CronTaskHandlerOptions;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '2.0.0-next.d90cc7f';\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
@@ -7,28 +7,84 @@ interface CronTaskHandlerOptions {
|
|
7
7
|
/**
|
8
8
|
* The default timezone to use for all cron tasks.
|
9
9
|
* You can override this per task, using the timeZone option.
|
10
|
-
* @see https://
|
11
|
-
* @default
|
10
|
+
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
11
|
+
* @default 'system'
|
12
12
|
*/
|
13
|
-
defaultTimezone
|
13
|
+
defaultTimezone: string;
|
14
14
|
/**
|
15
15
|
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
16
16
|
* If you don't use Sentry, you can ignore this option.
|
17
17
|
* @see https://docs.sentry.io/product/crons/
|
18
|
-
* @default
|
18
|
+
* @default false
|
19
19
|
*/
|
20
|
-
disableSentry
|
20
|
+
disableSentry: boolean;
|
21
21
|
}
|
22
22
|
type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
|
23
23
|
|
24
|
+
/**
|
25
|
+
* @example
|
26
|
+
*
|
27
|
+
* ```typescript
|
28
|
+
* // ping.ts
|
29
|
+
* import { CronTask } from '@kingsworld/plugin-cron';
|
30
|
+
*
|
31
|
+
* export class PingPong extends CronTask {
|
32
|
+
* public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
|
33
|
+
* super(context, {
|
34
|
+
* ...options,
|
35
|
+
* cronTime: '* * * * *'
|
36
|
+
* });
|
37
|
+
* }
|
38
|
+
*
|
39
|
+
* public run() {
|
40
|
+
* this.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓
|
41
|
+
* }
|
42
|
+
* }
|
43
|
+
* ```
|
44
|
+
*/
|
24
45
|
declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
|
25
46
|
job: CronJob<null, CronTask>;
|
26
47
|
constructor(context: CronTask.LoaderContext, options: Options);
|
27
48
|
abstract run(): Awaitable<unknown>;
|
49
|
+
/**
|
50
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
51
|
+
* @param message The message to include after the prefix
|
52
|
+
* @param other Extra parameters to pass to the logger
|
53
|
+
* @example
|
54
|
+
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
55
|
+
*/
|
28
56
|
info(message: string, ...other: unknown[]): void;
|
57
|
+
/**
|
58
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
59
|
+
* @param message The message to include after the prefix
|
60
|
+
* @param other Extra parameters to pass to the logger
|
61
|
+
* @example
|
62
|
+
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
63
|
+
*/
|
29
64
|
error(message: string, ...other: unknown[]): void;
|
65
|
+
/**
|
66
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
67
|
+
* @param message The message to include after the prefix
|
68
|
+
* @param other Extra parameters to pass to the logger
|
69
|
+
* @example
|
70
|
+
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
71
|
+
*/
|
30
72
|
warn(message: string, ...other: unknown[]): void;
|
73
|
+
/**
|
74
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
75
|
+
* @param message The message to include after the prefix
|
76
|
+
* @param other Extra parameters to pass to the logger
|
77
|
+
* @example
|
78
|
+
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
79
|
+
*/
|
31
80
|
debug(message: string, ...other: unknown[]): void;
|
81
|
+
/**
|
82
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
83
|
+
* @param message The message to include after the prefix
|
84
|
+
* @param other Extra parameters to pass to the logger
|
85
|
+
* @example
|
86
|
+
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
87
|
+
*/
|
32
88
|
trace(message: string, ...other: unknown[]): void;
|
33
89
|
}
|
34
90
|
declare namespace CronTask {
|
@@ -40,20 +96,60 @@ declare namespace CronTask {
|
|
40
96
|
|
41
97
|
declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
|
42
98
|
constructor();
|
99
|
+
/**
|
100
|
+
* Loops over all tasks and starts those that are enabled.
|
101
|
+
* This gets called automatically when the Client is ready.
|
102
|
+
* @returns CronTaskStore
|
103
|
+
*/
|
43
104
|
startAll(): this;
|
105
|
+
/**
|
106
|
+
* Loops over all tasks and stops those that are running.
|
107
|
+
* @returns CronTaskStore
|
108
|
+
*/
|
44
109
|
stopAll(): this;
|
45
110
|
set(key: string, value: CronTask): this;
|
46
111
|
delete(key: string): boolean;
|
112
|
+
/**
|
113
|
+
* Stops all running cron jobs and clears the store.
|
114
|
+
* @returns void
|
115
|
+
*/
|
47
116
|
clear(): void;
|
48
117
|
}
|
49
118
|
|
50
119
|
declare class CronTaskHandler {
|
51
|
-
|
52
|
-
|
120
|
+
/**
|
121
|
+
* The default timezone to use for all cron tasks.
|
122
|
+
* You can override this per task, using the timeZone option.
|
123
|
+
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
124
|
+
* @default 'system'
|
125
|
+
*/
|
126
|
+
defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];
|
127
|
+
/**
|
128
|
+
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
129
|
+
* If you don't use Sentry, you can ignore this option.
|
130
|
+
* @see https://docs.sentry.io/product/crons/
|
131
|
+
* @default false
|
132
|
+
*/
|
133
|
+
disableSentry: boolean;
|
134
|
+
/**
|
135
|
+
* The Sentry instance to use for instrumenting cron jobs.
|
136
|
+
* This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
|
137
|
+
* is installed and the {@linkcode disableSentry} option is set to false.
|
138
|
+
*/
|
53
139
|
sentry?: typeof Sentry;
|
54
140
|
constructor(options?: CronTaskHandlerOptions);
|
141
|
+
/**
|
142
|
+
* Start all enabled cron jobs.
|
143
|
+
* This gets called automatically when the Client is ready.
|
144
|
+
*/
|
55
145
|
startAll(): void;
|
146
|
+
/**
|
147
|
+
* Stop all running cron jobs.
|
148
|
+
*/
|
56
149
|
stopAll(): void;
|
150
|
+
/**
|
151
|
+
* Get the cron task store.
|
152
|
+
*/
|
57
153
|
private get store();
|
58
154
|
}
|
59
155
|
|
@@ -8,18 +8,45 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
8
8
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
9
9
|
var _CronTaskHandler = class _CronTaskHandler {
|
10
10
|
constructor(options) {
|
11
|
+
/**
|
12
|
+
* The default timezone to use for all cron tasks.
|
13
|
+
* You can override this per task, using the timeZone option.
|
14
|
+
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
15
|
+
* @default 'system'
|
16
|
+
*/
|
11
17
|
__publicField(this, "defaultTimezone");
|
18
|
+
/**
|
19
|
+
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
20
|
+
* If you don't use Sentry, you can ignore this option.
|
21
|
+
* @see https://docs.sentry.io/product/crons/
|
22
|
+
* @default false
|
23
|
+
*/
|
12
24
|
__publicField(this, "disableSentry");
|
25
|
+
/**
|
26
|
+
* The Sentry instance to use for instrumenting cron jobs.
|
27
|
+
* This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
|
28
|
+
* is installed and the {@linkcode disableSentry} option is set to false.
|
29
|
+
*/
|
13
30
|
__publicField(this, "sentry");
|
14
|
-
this.defaultTimezone = options?.defaultTimezone;
|
15
|
-
this.disableSentry = options?.disableSentry;
|
31
|
+
this.defaultTimezone = options?.defaultTimezone ?? "system";
|
32
|
+
this.disableSentry = options?.disableSentry ?? false;
|
16
33
|
}
|
34
|
+
/**
|
35
|
+
* Start all enabled cron jobs.
|
36
|
+
* This gets called automatically when the Client is ready.
|
37
|
+
*/
|
17
38
|
startAll() {
|
18
39
|
this.store.startAll();
|
19
40
|
}
|
41
|
+
/**
|
42
|
+
* Stop all running cron jobs.
|
43
|
+
*/
|
20
44
|
stopAll() {
|
21
45
|
this.store.stopAll();
|
22
46
|
}
|
47
|
+
/**
|
48
|
+
* Get the cron task store.
|
49
|
+
*/
|
23
50
|
get store() {
|
24
51
|
return framework.container.stores.get("cron-tasks");
|
25
52
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":["container"],"mappings":";;;;;;;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,
|
1
|
+
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":["container"],"mappings":";;;;;;;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAwBrB,YAAY,OAAkC,EAAA;AAjBrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGN,IAAK,IAAA,CAAA,eAAA,GAAkB,SAAS,eAAmB,IAAA,QAAA,CAAA;AACnD,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,KAAA,CAAA;AAAA,GAChD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAW,GAAA;AACjB,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACrB;AAAA;AAAA;AAAA;AAAA,EAKO,OAAU,GAAA;AAChB,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACpB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAY,KAAQ,GAAA;AACnB,IAAO,OAAAA,mBAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GACzC;AACD,CAAA,CAAA;AAlD6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.cjs","sourcesContent":["import { container } from '@sapphire/framework';\nimport type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default timezone to use for all cron tasks.\n\t * You can override this per task, using the timeZone option.\n\t * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone\n\t * @default 'system'\n\t */\n\tpublic defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];\n\n\t/**\n\t * The ability to opt-out of instrumenting cron jobs with Sentry.\n\t * If you don't use Sentry, you can ignore this option.\n\t * @see https://docs.sentry.io/product/crons/\n\t * @default false\n\t */\n\tpublic disableSentry: boolean;\n\n\t/**\n\t * The Sentry instance to use for instrumenting cron jobs.\n\t * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)\n\t * is installed and the {@linkcode disableSentry} option is set to false.\n\t */\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: CronTaskHandlerOptions) {\n\t\tthis.defaultTimezone = options?.defaultTimezone ?? 'system';\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n\n\t/**\n\t * Start all enabled cron jobs.\n\t * This gets called automatically when the Client is ready.\n\t */\n\tpublic startAll() {\n\t\tthis.store.startAll();\n\t}\n\n\t/**\n\t * Stop all running cron jobs.\n\t */\n\tpublic stopAll() {\n\t\tthis.store.stopAll();\n\t}\n\n\t/**\n\t * Get the cron task store.\n\t */\n\tprivate get store() {\n\t\treturn container.stores.get('cron-tasks');\n\t}\n}\n"]}
|
@@ -8,18 +8,53 @@ var _CronTask = class _CronTask extends pieces.Piece {
|
|
8
8
|
constructor(context, options) {
|
9
9
|
super(context, options);
|
10
10
|
}
|
11
|
+
/**
|
12
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
13
|
+
* @param message The message to include after the prefix
|
14
|
+
* @param other Extra parameters to pass to the logger
|
15
|
+
* @example
|
16
|
+
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
17
|
+
*/
|
11
18
|
info(message, ...other) {
|
12
19
|
this.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);
|
13
20
|
}
|
21
|
+
/**
|
22
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
23
|
+
* @param message The message to include after the prefix
|
24
|
+
* @param other Extra parameters to pass to the logger
|
25
|
+
* @example
|
26
|
+
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
27
|
+
*/
|
14
28
|
error(message, ...other) {
|
15
29
|
this.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);
|
16
30
|
}
|
31
|
+
/**
|
32
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
33
|
+
* @param message The message to include after the prefix
|
34
|
+
* @param other Extra parameters to pass to the logger
|
35
|
+
* @example
|
36
|
+
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
37
|
+
*/
|
17
38
|
warn(message, ...other) {
|
18
39
|
this.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);
|
19
40
|
}
|
41
|
+
/**
|
42
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
43
|
+
* @param message The message to include after the prefix
|
44
|
+
* @param other Extra parameters to pass to the logger
|
45
|
+
* @example
|
46
|
+
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
47
|
+
*/
|
20
48
|
debug(message, ...other) {
|
21
49
|
this.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);
|
22
50
|
}
|
51
|
+
/**
|
52
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
53
|
+
* @param message The message to include after the prefix
|
54
|
+
* @param other Extra parameters to pass to the logger
|
55
|
+
* @example
|
56
|
+
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
57
|
+
*/
|
23
58
|
trace(message, ...other) {
|
24
59
|
this.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);
|
25
60
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":["Piece"],"mappings":";;;;;;
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":["Piece"],"mappings":";;;;;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsEA,YAA6B,CAAA;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAkB,EAAA;AACrE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAAA,GACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AACD,CAAA,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.cjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { CronJob } from 'cron';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\n\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tcronTime: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\tpublic declare job: CronJob<null, CronTask>;\n\n\tpublic constructor(context: CronTask.LoaderContext, options: Options) {\n\t\tsuper(context, options);\n\t}\n\n\tpublic abstract run(): Awaitable<unknown>;\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.info('Hello world!'); // CronTask[my-task] Hello world!\n\t */\n\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!\n\t */\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!\n\t */\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!\n\t */\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.\n\t */\n\tpublic trace(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n}\n\nexport namespace CronTask {\n\texport type Options = Piece.Options & CronJobOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'cron-tasks'>;\n}\n"]}
|
@@ -10,6 +10,11 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
10
10
|
constructor() {
|
11
11
|
super(CronTask_cjs.CronTask, { name: "cron-tasks" });
|
12
12
|
}
|
13
|
+
/**
|
14
|
+
* Loops over all tasks and starts those that are enabled.
|
15
|
+
* This gets called automatically when the Client is ready.
|
16
|
+
* @returns CronTaskStore
|
17
|
+
*/
|
13
18
|
startAll() {
|
14
19
|
for (const task of this.values()) {
|
15
20
|
if (!task.enabled) continue;
|
@@ -18,6 +23,10 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
18
23
|
pieces.Store.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);
|
19
24
|
return this;
|
20
25
|
}
|
26
|
+
/**
|
27
|
+
* Loops over all tasks and stops those that are running.
|
28
|
+
* @returns CronTaskStore
|
29
|
+
*/
|
21
30
|
stopAll() {
|
22
31
|
for (const task of this.values()) {
|
23
32
|
if (!task.job.running) continue;
|
@@ -51,6 +60,10 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
51
60
|
}
|
52
61
|
return super.delete(key);
|
53
62
|
}
|
63
|
+
/**
|
64
|
+
* Stops all running cron jobs and clears the store.
|
65
|
+
* @returns void
|
66
|
+
*/
|
54
67
|
clear() {
|
55
68
|
this.stopAll();
|
56
69
|
return super.clear();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":["Store","CronTask","CronJob"],"mappings":";;;;;;;;AAIO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,YAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAMC,qBAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA,CAAA;AAAA,GACvC;AAAA,
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":["Store","CronTask","CronJob"],"mappings":";;;;;;;;AAIO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,YAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAMC,qBAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA,CAAA;AAAA,GACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAW,GAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,KAAK,OAAS,EAAA,SAAA;AACnB,MAAA,IAAA,CAAK,IAAI,KAAM,EAAA,CAAA;AAAA,KAChB;AAEA,IAAAD,YAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAsC,oCAAA,CAAA,CAAA,CAAA;AAC3E,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,OAAU,GAAA;AAChB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,IAAK,CAAA,GAAA,CAAI,OAAS,EAAA,SAAA;AACvB,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA,CAAA;AAAA,KACf;AAEA,IAAAA,YAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAqC,mCAAA,CAAA,CAAA,CAAA;AAC1E,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA,EAEgB,GAAA,CAAI,KAAa,KAAuB,EAAA;AACvD,IAAM,MAAA,EAAE,SAAY,GAAA,KAAA,CAAA;AAEpB,IAAA,MAAM,EAAE,MAAA,EAAQ,eAAgB,EAAA,GAAI,KAAK,SAAU,CAAA,IAAA,CAAA;AACnD,IAAA,MAAM,UAAU,MAAS,GAAA,MAAA,CAAO,KAAK,cAAe,CAAAE,YAAA,EAAS,GAAG,CAAI,GAAAA,YAAA,CAAA;AAEpE,IAAI,IAAA;AACH,MAAM,KAAA,CAAA,GAAA,GAAM,QAAQ,IAAK,CAAA;AAAA,QACxB,GAAG,OAAA;AAAA,QACH,MAAA,+BAAc,KAAK,KAAA,CAAM,IAAI,IAAK,CAAA,KAAK,GAA/B,EAAA,QAAA,CAAA;AAAA,QACR,KAAO,EAAA,KAAA;AAAA,QACP,OAAS,EAAA,KAAA;AAAA,QACT,QAAA,EAAU,QAAQ,QAAY,IAAA,eAAA;AAAA,OAC9B,CAAA,CAAA;AAAA,aACO,KAAO,EAAA;AACf,MAAM,KAAA,CAAA,KAAA,CAAM,oDAAoD,KAAK,CAAA,CAAA;AACrE,MAAA,KAAK,MAAM,MAAO,EAAA,CAAA;AAAA,KACnB;AAEA,IAAO,OAAA,KAAA,CAAM,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,GAC5B;AAAA,EAEgB,OAAO,GAAa,EAAA;AACnC,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,GAAA,CAAI,GAAG,CAAA,CAAA;AACzB,IAAI,IAAA,IAAA,EAAM,IAAI,OAAS,EAAA;AACtB,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA,CAAA;AAAA,KACf;AAEA,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA,CAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AAzEiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { CronJob } from 'cron';\nimport { CronTask } from './CronTask';\n\nexport class CronTaskStore extends Store<CronTask, 'cron-tasks'> {\n\tpublic constructor() {\n\t\tsuper(CronTask, { name: 'cron-tasks' });\n\t}\n\n\t/**\n\t * Loops over all tasks and starts those that are enabled.\n\t * This gets called automatically when the Client is ready.\n\t * @returns CronTaskStore\n\t */\n\tpublic startAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled) continue;\n\t\t\ttask.job.start();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and stops those that are running.\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.job.running) continue;\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\tpublic override set(key: string, value: CronTask): this {\n\t\tconst { options } = value;\n\n\t\tconst { sentry, defaultTimezone } = this.container.cron;\n\t\tconst cronJob = sentry ? sentry.cron.instrumentCron(CronJob, key) : CronJob;\n\n\t\ttry {\n\t\t\tvalue.job = cronJob.from({\n\t\t\t\t...options,\n\t\t\t\tonTick: () => void value.run.bind(value)(),\n\t\t\t\tstart: false,\n\t\t\t\tcontext: value,\n\t\t\t\ttimeZone: options.timeZone ?? defaultTimezone\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tvalue.error('Encountered an error while creating the cron job', error);\n\t\t\tvoid value.unload();\n\t\t}\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task?.job.running) {\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Stops all running cron jobs and clears the store.\n\t * @returns void\n\t */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
|
package/dist/esm/index.d.mts
CHANGED
@@ -7,28 +7,84 @@ interface CronTaskHandlerOptions {
|
|
7
7
|
/**
|
8
8
|
* The default timezone to use for all cron tasks.
|
9
9
|
* You can override this per task, using the timeZone option.
|
10
|
-
* @see https://
|
11
|
-
* @default
|
10
|
+
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
11
|
+
* @default 'system'
|
12
12
|
*/
|
13
|
-
defaultTimezone
|
13
|
+
defaultTimezone: string;
|
14
14
|
/**
|
15
15
|
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
16
16
|
* If you don't use Sentry, you can ignore this option.
|
17
17
|
* @see https://docs.sentry.io/product/crons/
|
18
|
-
* @default
|
18
|
+
* @default false
|
19
19
|
*/
|
20
|
-
disableSentry
|
20
|
+
disableSentry: boolean;
|
21
21
|
}
|
22
22
|
type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
|
23
23
|
|
24
|
+
/**
|
25
|
+
* @example
|
26
|
+
*
|
27
|
+
* ```typescript
|
28
|
+
* // ping.ts
|
29
|
+
* import { CronTask } from '@kingsworld/plugin-cron';
|
30
|
+
*
|
31
|
+
* export class PingPong extends CronTask {
|
32
|
+
* public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
|
33
|
+
* super(context, {
|
34
|
+
* ...options,
|
35
|
+
* cronTime: '* * * * *'
|
36
|
+
* });
|
37
|
+
* }
|
38
|
+
*
|
39
|
+
* public run() {
|
40
|
+
* this.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓
|
41
|
+
* }
|
42
|
+
* }
|
43
|
+
* ```
|
44
|
+
*/
|
24
45
|
declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
|
25
46
|
job: CronJob<null, CronTask>;
|
26
47
|
constructor(context: CronTask.LoaderContext, options: Options);
|
27
48
|
abstract run(): Awaitable<unknown>;
|
49
|
+
/**
|
50
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
51
|
+
* @param message The message to include after the prefix
|
52
|
+
* @param other Extra parameters to pass to the logger
|
53
|
+
* @example
|
54
|
+
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
55
|
+
*/
|
28
56
|
info(message: string, ...other: unknown[]): void;
|
57
|
+
/**
|
58
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
59
|
+
* @param message The message to include after the prefix
|
60
|
+
* @param other Extra parameters to pass to the logger
|
61
|
+
* @example
|
62
|
+
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
63
|
+
*/
|
29
64
|
error(message: string, ...other: unknown[]): void;
|
65
|
+
/**
|
66
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
67
|
+
* @param message The message to include after the prefix
|
68
|
+
* @param other Extra parameters to pass to the logger
|
69
|
+
* @example
|
70
|
+
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
71
|
+
*/
|
30
72
|
warn(message: string, ...other: unknown[]): void;
|
73
|
+
/**
|
74
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
75
|
+
* @param message The message to include after the prefix
|
76
|
+
* @param other Extra parameters to pass to the logger
|
77
|
+
* @example
|
78
|
+
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
79
|
+
*/
|
31
80
|
debug(message: string, ...other: unknown[]): void;
|
81
|
+
/**
|
82
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
83
|
+
* @param message The message to include after the prefix
|
84
|
+
* @param other Extra parameters to pass to the logger
|
85
|
+
* @example
|
86
|
+
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
87
|
+
*/
|
32
88
|
trace(message: string, ...other: unknown[]): void;
|
33
89
|
}
|
34
90
|
declare namespace CronTask {
|
@@ -40,20 +96,60 @@ declare namespace CronTask {
|
|
40
96
|
|
41
97
|
declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
|
42
98
|
constructor();
|
99
|
+
/**
|
100
|
+
* Loops over all tasks and starts those that are enabled.
|
101
|
+
* This gets called automatically when the Client is ready.
|
102
|
+
* @returns CronTaskStore
|
103
|
+
*/
|
43
104
|
startAll(): this;
|
105
|
+
/**
|
106
|
+
* Loops over all tasks and stops those that are running.
|
107
|
+
* @returns CronTaskStore
|
108
|
+
*/
|
44
109
|
stopAll(): this;
|
45
110
|
set(key: string, value: CronTask): this;
|
46
111
|
delete(key: string): boolean;
|
112
|
+
/**
|
113
|
+
* Stops all running cron jobs and clears the store.
|
114
|
+
* @returns void
|
115
|
+
*/
|
47
116
|
clear(): void;
|
48
117
|
}
|
49
118
|
|
50
119
|
declare class CronTaskHandler {
|
51
|
-
|
52
|
-
|
120
|
+
/**
|
121
|
+
* The default timezone to use for all cron tasks.
|
122
|
+
* You can override this per task, using the timeZone option.
|
123
|
+
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
124
|
+
* @default 'system'
|
125
|
+
*/
|
126
|
+
defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];
|
127
|
+
/**
|
128
|
+
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
129
|
+
* If you don't use Sentry, you can ignore this option.
|
130
|
+
* @see https://docs.sentry.io/product/crons/
|
131
|
+
* @default false
|
132
|
+
*/
|
133
|
+
disableSentry: boolean;
|
134
|
+
/**
|
135
|
+
* The Sentry instance to use for instrumenting cron jobs.
|
136
|
+
* This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
|
137
|
+
* is installed and the {@linkcode disableSentry} option is set to false.
|
138
|
+
*/
|
53
139
|
sentry?: typeof Sentry;
|
54
140
|
constructor(options?: CronTaskHandlerOptions);
|
141
|
+
/**
|
142
|
+
* Start all enabled cron jobs.
|
143
|
+
* This gets called automatically when the Client is ready.
|
144
|
+
*/
|
55
145
|
startAll(): void;
|
146
|
+
/**
|
147
|
+
* Stop all running cron jobs.
|
148
|
+
*/
|
56
149
|
stopAll(): void;
|
150
|
+
/**
|
151
|
+
* Get the cron task store.
|
152
|
+
*/
|
57
153
|
private get store();
|
58
154
|
}
|
59
155
|
|
package/dist/esm/index.mjs
CHANGED
@@ -4,7 +4,7 @@ export * from './lib/structures/CronTask.mjs';
|
|
4
4
|
export * from './lib/structures/CronTaskStore.mjs';
|
5
5
|
export * from './lib/types/CronTaskTypes.mjs';
|
6
6
|
|
7
|
-
var version = "2.0.0-next.
|
7
|
+
var version = "2.0.0-next.d90cc7f";
|
8
8
|
|
9
9
|
export { version };
|
10
10
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcron: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcron?: CronTaskHandlerOptions;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '2.0.0-next.
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcron: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcron?: CronTaskHandlerOptions;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '2.0.0-next.d90cc7f';\n"]}
|
@@ -3,18 +3,45 @@ import { container } from '@sapphire/framework';
|
|
3
3
|
|
4
4
|
var _CronTaskHandler = class _CronTaskHandler {
|
5
5
|
constructor(options) {
|
6
|
+
/**
|
7
|
+
* The default timezone to use for all cron tasks.
|
8
|
+
* You can override this per task, using the timeZone option.
|
9
|
+
* @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
|
10
|
+
* @default 'system'
|
11
|
+
*/
|
6
12
|
__publicField(this, "defaultTimezone");
|
13
|
+
/**
|
14
|
+
* The ability to opt-out of instrumenting cron jobs with Sentry.
|
15
|
+
* If you don't use Sentry, you can ignore this option.
|
16
|
+
* @see https://docs.sentry.io/product/crons/
|
17
|
+
* @default false
|
18
|
+
*/
|
7
19
|
__publicField(this, "disableSentry");
|
20
|
+
/**
|
21
|
+
* The Sentry instance to use for instrumenting cron jobs.
|
22
|
+
* This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
|
23
|
+
* is installed and the {@linkcode disableSentry} option is set to false.
|
24
|
+
*/
|
8
25
|
__publicField(this, "sentry");
|
9
|
-
this.defaultTimezone = options?.defaultTimezone;
|
10
|
-
this.disableSentry = options?.disableSentry;
|
26
|
+
this.defaultTimezone = options?.defaultTimezone ?? "system";
|
27
|
+
this.disableSentry = options?.disableSentry ?? false;
|
11
28
|
}
|
29
|
+
/**
|
30
|
+
* Start all enabled cron jobs.
|
31
|
+
* This gets called automatically when the Client is ready.
|
32
|
+
*/
|
12
33
|
startAll() {
|
13
34
|
this.store.startAll();
|
14
35
|
}
|
36
|
+
/**
|
37
|
+
* Stop all running cron jobs.
|
38
|
+
*/
|
15
39
|
stopAll() {
|
16
40
|
this.store.stopAll();
|
17
41
|
}
|
42
|
+
/**
|
43
|
+
* Get the cron task store.
|
44
|
+
*/
|
18
45
|
get store() {
|
19
46
|
return container.stores.get("cron-tasks");
|
20
47
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,
|
1
|
+
{"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAwBrB,YAAY,OAAkC,EAAA;AAjBrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGN,IAAK,IAAA,CAAA,eAAA,GAAkB,SAAS,eAAmB,IAAA,QAAA,CAAA;AACnD,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,KAAA,CAAA;AAAA,GAChD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAW,GAAA;AACjB,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACrB;AAAA;AAAA;AAAA;AAAA,EAKO,OAAU,GAAA;AAChB,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACpB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAY,KAAQ,GAAA;AACnB,IAAO,OAAA,SAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GACzC;AACD,CAAA,CAAA;AAlD6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.mjs","sourcesContent":["import { container } from '@sapphire/framework';\nimport type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default timezone to use for all cron tasks.\n\t * You can override this per task, using the timeZone option.\n\t * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone\n\t * @default 'system'\n\t */\n\tpublic defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];\n\n\t/**\n\t * The ability to opt-out of instrumenting cron jobs with Sentry.\n\t * If you don't use Sentry, you can ignore this option.\n\t * @see https://docs.sentry.io/product/crons/\n\t * @default false\n\t */\n\tpublic disableSentry: boolean;\n\n\t/**\n\t * The Sentry instance to use for instrumenting cron jobs.\n\t * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)\n\t * is installed and the {@linkcode disableSentry} option is set to false.\n\t */\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: CronTaskHandlerOptions) {\n\t\tthis.defaultTimezone = options?.defaultTimezone ?? 'system';\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n\n\t/**\n\t * Start all enabled cron jobs.\n\t * This gets called automatically when the Client is ready.\n\t */\n\tpublic startAll() {\n\t\tthis.store.startAll();\n\t}\n\n\t/**\n\t * Stop all running cron jobs.\n\t */\n\tpublic stopAll() {\n\t\tthis.store.stopAll();\n\t}\n\n\t/**\n\t * Get the cron task store.\n\t */\n\tprivate get store() {\n\t\treturn container.stores.get('cron-tasks');\n\t}\n}\n"]}
|
@@ -5,18 +5,53 @@ var _CronTask = class _CronTask extends Piece {
|
|
5
5
|
constructor(context, options) {
|
6
6
|
super(context, options);
|
7
7
|
}
|
8
|
+
/**
|
9
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
10
|
+
* @param message The message to include after the prefix
|
11
|
+
* @param other Extra parameters to pass to the logger
|
12
|
+
* @example
|
13
|
+
* this.info('Hello world!'); // CronTask[my-task] Hello world!
|
14
|
+
*/
|
8
15
|
info(message, ...other) {
|
9
16
|
this.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);
|
10
17
|
}
|
18
|
+
/**
|
19
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
20
|
+
* @param message The message to include after the prefix
|
21
|
+
* @param other Extra parameters to pass to the logger
|
22
|
+
* @example
|
23
|
+
* this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
|
24
|
+
*/
|
11
25
|
error(message, ...other) {
|
12
26
|
this.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);
|
13
27
|
}
|
28
|
+
/**
|
29
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
30
|
+
* @param message The message to include after the prefix
|
31
|
+
* @param other Extra parameters to pass to the logger
|
32
|
+
* @example
|
33
|
+
* this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
|
34
|
+
*/
|
14
35
|
warn(message, ...other) {
|
15
36
|
this.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);
|
16
37
|
}
|
38
|
+
/**
|
39
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
40
|
+
* @param message The message to include after the prefix
|
41
|
+
* @param other Extra parameters to pass to the logger
|
42
|
+
* @example
|
43
|
+
* this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
|
44
|
+
*/
|
17
45
|
debug(message, ...other) {
|
18
46
|
this.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);
|
19
47
|
}
|
48
|
+
/**
|
49
|
+
* A helper function to log messages with the `CronTask[${name}]` prefix.
|
50
|
+
* @param message The message to include after the prefix
|
51
|
+
* @param other Extra parameters to pass to the logger
|
52
|
+
* @example
|
53
|
+
* this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
|
54
|
+
*/
|
20
55
|
trace(message, ...other) {
|
21
56
|
this.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);
|
22
57
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsE,KAA6B,CAAA;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAkB,EAAA;AACrE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAAA,GACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA,CAAA;AAAA,GAC1E;AACD,CAAA,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.mjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { CronJob } from 'cron';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\n\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tcronTime: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\tpublic declare job: CronJob<null, CronTask>;\n\n\tpublic constructor(context: CronTask.LoaderContext, options: Options) {\n\t\tsuper(context, options);\n\t}\n\n\tpublic abstract run(): Awaitable<unknown>;\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.info('Hello world!'); // CronTask[my-task] Hello world!\n\t */\n\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!\n\t */\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!\n\t */\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!\n\t */\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.\n\t */\n\tpublic trace(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n}\n\nexport namespace CronTask {\n\texport type Options = Piece.Options & CronJobOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'cron-tasks'>;\n}\n"]}
|
@@ -7,6 +7,11 @@ var _CronTaskStore = class _CronTaskStore extends Store {
|
|
7
7
|
constructor() {
|
8
8
|
super(CronTask, { name: "cron-tasks" });
|
9
9
|
}
|
10
|
+
/**
|
11
|
+
* Loops over all tasks and starts those that are enabled.
|
12
|
+
* This gets called automatically when the Client is ready.
|
13
|
+
* @returns CronTaskStore
|
14
|
+
*/
|
10
15
|
startAll() {
|
11
16
|
for (const task of this.values()) {
|
12
17
|
if (!task.enabled) continue;
|
@@ -15,6 +20,10 @@ var _CronTaskStore = class _CronTaskStore extends Store {
|
|
15
20
|
Store.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);
|
16
21
|
return this;
|
17
22
|
}
|
23
|
+
/**
|
24
|
+
* Loops over all tasks and stops those that are running.
|
25
|
+
* @returns CronTaskStore
|
26
|
+
*/
|
18
27
|
stopAll() {
|
19
28
|
for (const task of this.values()) {
|
20
29
|
if (!task.job.running) continue;
|
@@ -48,6 +57,10 @@ var _CronTaskStore = class _CronTaskStore extends Store {
|
|
48
57
|
}
|
49
58
|
return super.delete(key);
|
50
59
|
}
|
60
|
+
/**
|
61
|
+
* Stops all running cron jobs and clears the store.
|
62
|
+
* @returns void
|
63
|
+
*/
|
51
64
|
clear() {
|
52
65
|
this.stopAll();
|
53
66
|
return super.clear();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":[],"mappings":";;;;;AAIO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,KAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,QAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA,CAAA;AAAA,GACvC;AAAA,
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":[],"mappings":";;;;;AAIO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,KAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,QAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA,CAAA;AAAA,GACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAW,GAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,KAAK,OAAS,EAAA,SAAA;AACnB,MAAA,IAAA,CAAK,IAAI,KAAM,EAAA,CAAA;AAAA,KAChB;AAEA,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAsC,oCAAA,CAAA,CAAA,CAAA;AAC3E,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,OAAU,GAAA;AAChB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,IAAK,CAAA,GAAA,CAAI,OAAS,EAAA,SAAA;AACvB,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA,CAAA;AAAA,KACf;AAEA,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAqC,mCAAA,CAAA,CAAA,CAAA;AAC1E,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA,EAEgB,GAAA,CAAI,KAAa,KAAuB,EAAA;AACvD,IAAM,MAAA,EAAE,SAAY,GAAA,KAAA,CAAA;AAEpB,IAAA,MAAM,EAAE,MAAA,EAAQ,eAAgB,EAAA,GAAI,KAAK,SAAU,CAAA,IAAA,CAAA;AACnD,IAAA,MAAM,UAAU,MAAS,GAAA,MAAA,CAAO,KAAK,cAAe,CAAA,OAAA,EAAS,GAAG,CAAI,GAAA,OAAA,CAAA;AAEpE,IAAI,IAAA;AACH,MAAM,KAAA,CAAA,GAAA,GAAM,QAAQ,IAAK,CAAA;AAAA,QACxB,GAAG,OAAA;AAAA,QACH,MAAA,+BAAc,KAAK,KAAA,CAAM,IAAI,IAAK,CAAA,KAAK,GAA/B,EAAA,QAAA,CAAA;AAAA,QACR,KAAO,EAAA,KAAA;AAAA,QACP,OAAS,EAAA,KAAA;AAAA,QACT,QAAA,EAAU,QAAQ,QAAY,IAAA,eAAA;AAAA,OAC9B,CAAA,CAAA;AAAA,aACO,KAAO,EAAA;AACf,MAAM,KAAA,CAAA,KAAA,CAAM,oDAAoD,KAAK,CAAA,CAAA;AACrE,MAAA,KAAK,MAAM,MAAO,EAAA,CAAA;AAAA,KACnB;AAEA,IAAO,OAAA,KAAA,CAAM,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,GAC5B;AAAA,EAEgB,OAAO,GAAa,EAAA;AACnC,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,GAAA,CAAI,GAAG,CAAA,CAAA;AACzB,IAAI,IAAA,IAAA,EAAM,IAAI,OAAS,EAAA;AACtB,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA,CAAA;AAAA,KACf;AAEA,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA,CAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AAzEiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.mjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { CronJob } from 'cron';\nimport { CronTask } from './CronTask';\n\nexport class CronTaskStore extends Store<CronTask, 'cron-tasks'> {\n\tpublic constructor() {\n\t\tsuper(CronTask, { name: 'cron-tasks' });\n\t}\n\n\t/**\n\t * Loops over all tasks and starts those that are enabled.\n\t * This gets called automatically when the Client is ready.\n\t * @returns CronTaskStore\n\t */\n\tpublic startAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled) continue;\n\t\t\ttask.job.start();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and stops those that are running.\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.job.running) continue;\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\tpublic override set(key: string, value: CronTask): this {\n\t\tconst { options } = value;\n\n\t\tconst { sentry, defaultTimezone } = this.container.cron;\n\t\tconst cronJob = sentry ? sentry.cron.instrumentCron(CronJob, key) : CronJob;\n\n\t\ttry {\n\t\t\tvalue.job = cronJob.from({\n\t\t\t\t...options,\n\t\t\t\tonTick: () => void value.run.bind(value)(),\n\t\t\t\tstart: false,\n\t\t\t\tcontext: value,\n\t\t\t\ttimeZone: options.timeZone ?? defaultTimezone\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tvalue.error('Encountered an error while creating the cron job', error);\n\t\t\tvoid value.unload();\n\t\t}\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task?.job.running) {\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Stops all running cron jobs and clears the store.\n\t * @returns void\n\t */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kingsworld/plugin-cron",
|
3
3
|
"description": "A simple @sapphire/framework plugin that aims to make use of the cron package and allow users to make cron jobs within their Sapphire discord bot.",
|
4
|
-
"version": "2.0.0-next.
|
4
|
+
"version": "2.0.0-next.d90cc7f",
|
5
5
|
"author": "Seren_Modz 21 <seren@kings-world.net>",
|
6
6
|
"license": "MIT",
|
7
7
|
"main": "dist/cjs/index.cjs",
|
@@ -51,8 +51,8 @@
|
|
51
51
|
"devDependencies": {
|
52
52
|
"@favware/cliff-jumper": "^4.1.0",
|
53
53
|
"@favware/rollup-type-bundler": "^3.3.0",
|
54
|
-
"@sentry/node": "^
|
55
|
-
"@types/node": "^20.16.
|
54
|
+
"@sentry/node": "^8.28.0",
|
55
|
+
"@types/node": "^20.16.5",
|
56
56
|
"concurrently": "^8.2.2",
|
57
57
|
"tsup": "^8.2.4",
|
58
58
|
"tsx": "^4.19.0",
|