@kingsworld/plugin-cron 2.0.0-next.d6af196 → 2.0.0-next.e9b2a4a

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 CHANGED
@@ -56,7 +56,7 @@ const options = {
56
56
  * The timezone to use for the cron tasks
57
57
  * @default 'UTC'
58
58
  */
59
- timeZone: 'Europe/London'
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
- ```ts
125
+ ```typescript
126
126
  import { CronTask } from '@kingsworld/plugin-cron';
127
127
 
128
128
  export class PingPong extends CronTask {
@@ -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.d6af196";
9
+ var version = "2.0.0-next.e9b2a4a";
10
10
 
11
11
  exports.version = version;
12
12
  Object.keys(CronTaskHandler_cjs).forEach(function (k) {
@@ -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.d6af196';\n"]}
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.e9b2a4a';\n"]}
@@ -7,28 +7,85 @@ 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://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
10
11
  * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
11
- * @default "UTC"
12
+ * @default 'UTC'
12
13
  */
13
- defaultTimezone?: string;
14
+ defaultTimezone: string;
14
15
  /**
15
16
  * The ability to opt-out of instrumenting cron jobs with Sentry.
16
17
  * If you don't use Sentry, you can ignore this option.
17
18
  * @see https://docs.sentry.io/product/crons/
18
- * @default undefined // technically false
19
+ * @default false
19
20
  */
20
- disableSentry?: boolean;
21
+ disableSentry: boolean;
21
22
  }
22
23
  type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
23
24
 
25
+ /**
26
+ * @example
27
+ *
28
+ * ```typescript
29
+ * // ping.ts
30
+ * import { CronTask } from '@kingsworld/plugin-cron';
31
+ *
32
+ * export class PingPong extends CronTask {
33
+ * public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
34
+ * super(context, {
35
+ * ...options,
36
+ * cronTime: '* * * * *'
37
+ * });
38
+ * }
39
+ *
40
+ * public run() {
41
+ * this.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓
42
+ * }
43
+ * }
44
+ * ```
45
+ */
24
46
  declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
25
47
  job: CronJob<null, CronTask>;
26
48
  constructor(context: CronTask.LoaderContext, options: Options);
27
49
  abstract run(): Awaitable<unknown>;
50
+ /**
51
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
52
+ * @param message The message to include after the prefix
53
+ * @param other Extra parameters to pass to the logger
54
+ * @example
55
+ * this.info('Hello world!'); // CronTask[my-task] Hello world!
56
+ */
28
57
  info(message: string, ...other: unknown[]): void;
58
+ /**
59
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
60
+ * @param message The message to include after the prefix
61
+ * @param other Extra parameters to pass to the logger
62
+ * @example
63
+ * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
64
+ */
29
65
  error(message: string, ...other: unknown[]): void;
66
+ /**
67
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
68
+ * @param message The message to include after the prefix
69
+ * @param other Extra parameters to pass to the logger
70
+ * @example
71
+ * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
72
+ */
30
73
  warn(message: string, ...other: unknown[]): void;
74
+ /**
75
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
76
+ * @param message The message to include after the prefix
77
+ * @param other Extra parameters to pass to the logger
78
+ * @example
79
+ * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
80
+ */
31
81
  debug(message: string, ...other: unknown[]): void;
82
+ /**
83
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
84
+ * @param message The message to include after the prefix
85
+ * @param other Extra parameters to pass to the logger
86
+ * @example
87
+ * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
88
+ */
32
89
  trace(message: string, ...other: unknown[]): void;
33
90
  }
34
91
  declare namespace CronTask {
@@ -40,20 +97,61 @@ declare namespace CronTask {
40
97
 
41
98
  declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
42
99
  constructor();
100
+ /**
101
+ * Loops over all tasks and starts those that are enabled.
102
+ * This gets called automatically when the Client is ready.
103
+ * @returns CronTaskStore
104
+ */
43
105
  startAll(): this;
106
+ /**
107
+ * Loops over all tasks and stops those that are running.
108
+ * @returns CronTaskStore
109
+ */
44
110
  stopAll(): this;
45
111
  set(key: string, value: CronTask): this;
46
112
  delete(key: string): boolean;
113
+ /**
114
+ * Stops all running cron jobs and clears the store.
115
+ * @returns void
116
+ */
47
117
  clear(): void;
48
118
  }
49
119
 
50
120
  declare class CronTaskHandler {
51
- defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];
52
- disableSentry?: boolean;
121
+ /**
122
+ * The default timezone to use for all cron tasks.
123
+ * You can override this per task, using the timeZone option.
124
+ * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
125
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
126
+ * @default 'UTC'
127
+ */
128
+ defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];
129
+ /**
130
+ * The ability to opt-out of instrumenting cron jobs with Sentry.
131
+ * If you don't use Sentry, you can ignore this option.
132
+ * @see https://docs.sentry.io/product/crons/
133
+ * @default false
134
+ */
135
+ disableSentry: boolean;
136
+ /**
137
+ * The Sentry instance to use for instrumenting cron jobs.
138
+ * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
139
+ * is installed and the {@linkcode disableSentry} option is set to false.
140
+ */
53
141
  sentry?: typeof Sentry;
54
142
  constructor(options?: CronTaskHandlerOptions);
143
+ /**
144
+ * Start all enabled cron jobs.
145
+ * This gets called automatically when the Client is ready.
146
+ */
55
147
  startAll(): void;
148
+ /**
149
+ * Stop all running cron jobs.
150
+ */
56
151
  stopAll(): void;
152
+ /**
153
+ * Get the cron task store.
154
+ */
57
155
  private get store();
58
156
  }
59
157
 
@@ -8,18 +8,46 @@ 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
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
16
+ * @default 'UTC'
17
+ */
11
18
  __publicField(this, "defaultTimezone");
19
+ /**
20
+ * The ability to opt-out of instrumenting cron jobs with Sentry.
21
+ * If you don't use Sentry, you can ignore this option.
22
+ * @see https://docs.sentry.io/product/crons/
23
+ * @default false
24
+ */
12
25
  __publicField(this, "disableSentry");
26
+ /**
27
+ * The Sentry instance to use for instrumenting cron jobs.
28
+ * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
29
+ * is installed and the {@linkcode disableSentry} option is set to false.
30
+ */
13
31
  __publicField(this, "sentry");
14
- this.defaultTimezone = options?.defaultTimezone;
15
- this.disableSentry = options?.disableSentry;
32
+ this.defaultTimezone = options?.defaultTimezone ?? "UTC";
33
+ this.disableSentry = options?.disableSentry ?? false;
16
34
  }
35
+ /**
36
+ * Start all enabled cron jobs.
37
+ * This gets called automatically when the Client is ready.
38
+ */
17
39
  startAll() {
18
40
  this.store.startAll();
19
41
  }
42
+ /**
43
+ * Stop all running cron jobs.
44
+ */
20
45
  stopAll() {
21
46
  this.store.stopAll();
22
47
  }
48
+ /**
49
+ * Get the cron task store.
50
+ */
23
51
  get store() {
24
52
  return framework.container.stores.get("cron-tasks");
25
53
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":["container"],"mappings":";;;;;;;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAKrB,YAAY,OAAkC,EAAA;AAJrD,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AACP,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AACP,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAS,EAAA,eAAA,CAAA;AAChC,IAAA,IAAA,CAAK,gBAAgB,OAAS,EAAA,aAAA,CAAA;AAAA,GAC/B;AAAA,EAEO,QAAW,GAAA;AACjB,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACrB;AAAA,EAEO,OAAU,GAAA;AAChB,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACpB;AAAA,EAEA,IAAY,KAAQ,GAAA;AACnB,IAAO,OAAAA,mBAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GACzC;AACD,CAAA,CAAA;AArB6B,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\tpublic defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];\n\tpublic disableSentry?: boolean;\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: CronTaskHandlerOptions) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry;\n\t}\n\n\tpublic startAll() {\n\t\tthis.store.startAll();\n\t}\n\n\tpublic stopAll() {\n\t\tthis.store.stopAll();\n\t}\n\n\tprivate get store() {\n\t\treturn container.stores.get('cron-tasks');\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":["container"],"mappings":";;;;;;;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAyBrB,YAAY,OAAkC,EAAA;AAjBrD;AAAA;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,KAAA,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;AAnD6B,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 * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n\t * @default 'UTC'\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 ?? 'UTC';\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":";;;;;;AAKO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsEA,Y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;AA5ByH,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\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\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\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"]}
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;AAA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,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,EAEO,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,EAEO,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,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,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AA5DiE,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\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\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\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t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Task } 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"]}
@@ -7,28 +7,85 @@ 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://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
10
11
  * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
11
- * @default "UTC"
12
+ * @default 'UTC'
12
13
  */
13
- defaultTimezone?: string;
14
+ defaultTimezone: string;
14
15
  /**
15
16
  * The ability to opt-out of instrumenting cron jobs with Sentry.
16
17
  * If you don't use Sentry, you can ignore this option.
17
18
  * @see https://docs.sentry.io/product/crons/
18
- * @default undefined // technically false
19
+ * @default false
19
20
  */
20
- disableSentry?: boolean;
21
+ disableSentry: boolean;
21
22
  }
22
23
  type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
23
24
 
25
+ /**
26
+ * @example
27
+ *
28
+ * ```typescript
29
+ * // ping.ts
30
+ * import { CronTask } from '@kingsworld/plugin-cron';
31
+ *
32
+ * export class PingPong extends CronTask {
33
+ * public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
34
+ * super(context, {
35
+ * ...options,
36
+ * cronTime: '* * * * *'
37
+ * });
38
+ * }
39
+ *
40
+ * public run() {
41
+ * this.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓
42
+ * }
43
+ * }
44
+ * ```
45
+ */
24
46
  declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
25
47
  job: CronJob<null, CronTask>;
26
48
  constructor(context: CronTask.LoaderContext, options: Options);
27
49
  abstract run(): Awaitable<unknown>;
50
+ /**
51
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
52
+ * @param message The message to include after the prefix
53
+ * @param other Extra parameters to pass to the logger
54
+ * @example
55
+ * this.info('Hello world!'); // CronTask[my-task] Hello world!
56
+ */
28
57
  info(message: string, ...other: unknown[]): void;
58
+ /**
59
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
60
+ * @param message The message to include after the prefix
61
+ * @param other Extra parameters to pass to the logger
62
+ * @example
63
+ * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
64
+ */
29
65
  error(message: string, ...other: unknown[]): void;
66
+ /**
67
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
68
+ * @param message The message to include after the prefix
69
+ * @param other Extra parameters to pass to the logger
70
+ * @example
71
+ * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
72
+ */
30
73
  warn(message: string, ...other: unknown[]): void;
74
+ /**
75
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
76
+ * @param message The message to include after the prefix
77
+ * @param other Extra parameters to pass to the logger
78
+ * @example
79
+ * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
80
+ */
31
81
  debug(message: string, ...other: unknown[]): void;
82
+ /**
83
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
84
+ * @param message The message to include after the prefix
85
+ * @param other Extra parameters to pass to the logger
86
+ * @example
87
+ * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
88
+ */
32
89
  trace(message: string, ...other: unknown[]): void;
33
90
  }
34
91
  declare namespace CronTask {
@@ -40,20 +97,61 @@ declare namespace CronTask {
40
97
 
41
98
  declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
42
99
  constructor();
100
+ /**
101
+ * Loops over all tasks and starts those that are enabled.
102
+ * This gets called automatically when the Client is ready.
103
+ * @returns CronTaskStore
104
+ */
43
105
  startAll(): this;
106
+ /**
107
+ * Loops over all tasks and stops those that are running.
108
+ * @returns CronTaskStore
109
+ */
44
110
  stopAll(): this;
45
111
  set(key: string, value: CronTask): this;
46
112
  delete(key: string): boolean;
113
+ /**
114
+ * Stops all running cron jobs and clears the store.
115
+ * @returns void
116
+ */
47
117
  clear(): void;
48
118
  }
49
119
 
50
120
  declare class CronTaskHandler {
51
- defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];
52
- disableSentry?: boolean;
121
+ /**
122
+ * The default timezone to use for all cron tasks.
123
+ * You can override this per task, using the timeZone option.
124
+ * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
125
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
126
+ * @default 'UTC'
127
+ */
128
+ defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];
129
+ /**
130
+ * The ability to opt-out of instrumenting cron jobs with Sentry.
131
+ * If you don't use Sentry, you can ignore this option.
132
+ * @see https://docs.sentry.io/product/crons/
133
+ * @default false
134
+ */
135
+ disableSentry: boolean;
136
+ /**
137
+ * The Sentry instance to use for instrumenting cron jobs.
138
+ * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
139
+ * is installed and the {@linkcode disableSentry} option is set to false.
140
+ */
53
141
  sentry?: typeof Sentry;
54
142
  constructor(options?: CronTaskHandlerOptions);
143
+ /**
144
+ * Start all enabled cron jobs.
145
+ * This gets called automatically when the Client is ready.
146
+ */
55
147
  startAll(): void;
148
+ /**
149
+ * Stop all running cron jobs.
150
+ */
56
151
  stopAll(): void;
152
+ /**
153
+ * Get the cron task store.
154
+ */
57
155
  private get store();
58
156
  }
59
157
 
@@ -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.d6af196";
7
+ var version = "2.0.0-next.e9b2a4a";
8
8
 
9
9
  export { version };
10
10
  //# sourceMappingURL=index.mjs.map
@@ -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.d6af196';\n"]}
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.e9b2a4a';\n"]}
@@ -3,18 +3,46 @@ 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
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
11
+ * @default 'UTC'
12
+ */
6
13
  __publicField(this, "defaultTimezone");
14
+ /**
15
+ * The ability to opt-out of instrumenting cron jobs with Sentry.
16
+ * If you don't use Sentry, you can ignore this option.
17
+ * @see https://docs.sentry.io/product/crons/
18
+ * @default false
19
+ */
7
20
  __publicField(this, "disableSentry");
21
+ /**
22
+ * The Sentry instance to use for instrumenting cron jobs.
23
+ * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
24
+ * is installed and the {@linkcode disableSentry} option is set to false.
25
+ */
8
26
  __publicField(this, "sentry");
9
- this.defaultTimezone = options?.defaultTimezone;
10
- this.disableSentry = options?.disableSentry;
27
+ this.defaultTimezone = options?.defaultTimezone ?? "UTC";
28
+ this.disableSentry = options?.disableSentry ?? false;
11
29
  }
30
+ /**
31
+ * Start all enabled cron jobs.
32
+ * This gets called automatically when the Client is ready.
33
+ */
12
34
  startAll() {
13
35
  this.store.startAll();
14
36
  }
37
+ /**
38
+ * Stop all running cron jobs.
39
+ */
15
40
  stopAll() {
16
41
  this.store.stopAll();
17
42
  }
43
+ /**
44
+ * Get the cron task store.
45
+ */
18
46
  get store() {
19
47
  return container.stores.get("cron-tasks");
20
48
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAKrB,YAAY,OAAkC,EAAA;AAJrD,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AACP,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AACP,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAS,EAAA,eAAA,CAAA;AAChC,IAAA,IAAA,CAAK,gBAAgB,OAAS,EAAA,aAAA,CAAA;AAAA,GAC/B;AAAA,EAEO,QAAW,GAAA;AACjB,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACrB;AAAA,EAEO,OAAU,GAAA;AAChB,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACpB;AAAA,EAEA,IAAY,KAAQ,GAAA;AACnB,IAAO,OAAA,SAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GACzC;AACD,CAAA,CAAA;AArB6B,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\tpublic defaultTimezone?: CronTaskHandlerOptions['defaultTimezone'];\n\tpublic disableSentry?: boolean;\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: CronTaskHandlerOptions) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry;\n\t}\n\n\tpublic startAll() {\n\t\tthis.store.startAll();\n\t}\n\n\tpublic stopAll() {\n\t\tthis.store.stopAll();\n\t}\n\n\tprivate get store() {\n\t\treturn container.stores.get('cron-tasks');\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAyBrB,YAAY,OAAkC,EAAA;AAjBrD;AAAA;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,KAAA,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;AAnD6B,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 * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n\t * @default 'UTC'\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 ?? 'UTC';\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":";;;AAKO,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,EAIO,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,EAEO,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,EAEO,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,EAEO,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,EAEO,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;AA5ByH,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\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\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\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"]}
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,EAEO,QAAW,GAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,KAAK,OAAS,EAAA,SA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A,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,EAEgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA,CAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AA5DiE,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\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\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\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
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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I,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.d6af196",
4
+ "version": "2.0.0-next.e9b2a4a",
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": "^7.119.0",
55
- "@types/node": "^20.16.2",
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",