@kingsworld/plugin-cron 4.0.0-next.efd4ebb → 4.0.0-next.ff86fbe

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/CHANGELOG.md CHANGED
@@ -2,6 +2,52 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ # [@kingsworld/plugin-cron@3.0.6](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@3.0.5...@kingsworld/plugin-cron@3.0.6) - (2026-01-11)
6
+
7
+ ## 🏠 Refactor
8
+
9
+ - **cronTaskStore:** Remove unnecessary arrow function ([85cdd9b](https://github.com/Kings-World/sapphire-plugins/commit/85cdd9bbb88fb6beec2f1e58cd0e1d7cf3b5ccde))
10
+
11
+ ## 🐛 Bug Fixes
12
+
13
+ - **deps:** Update all non-major dependencies ([96a4029](https://github.com/Kings-World/sapphire-plugins/commit/96a402959785e1287df250413eb0f10d4d2fe8c6)) ([#122](https://github.com/Kings-World/sapphire-plugins/pull/122) by @renovate[bot])
14
+
15
+ # [@kingsworld/plugin-cron@3.0.5](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@3.0.4...@kingsworld/plugin-cron@3.0.5) - (2025-05-21)
16
+
17
+ ## 🐛 Bug Fixes
18
+
19
+ - Correct the usage of the normalizePattern() function ([2db627a](https://github.com/Kings-World/sapphire-plugins/commit/2db627a85d91f185820f0796df360b4ade3c77c5)) ([#112](https://github.com/Kings-World/sapphire-plugins/pull/112) by @SerenModz21)
20
+
21
+ # [@kingsworld/plugin-cron@3.0.4](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@3.0.3...@kingsworld/plugin-cron@3.0.4) - (2025-04-20)
22
+
23
+ ## 📝 Documentation
24
+
25
+ - Replace mentions of cron with croner ([451ffce](https://github.com/Kings-World/sapphire-plugins/commit/451ffcef074c867600efee50b89e2175dbb1d0c5)) ([#103](https://github.com/Kings-World/sapphire-plugins/pull/103) by @SerenModz21)
26
+
27
+ # [@kingsworld/plugin-cron@3.0.3](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@3.0.2...@kingsworld/plugin-cron@3.0.3) - (2025-04-07)
28
+
29
+ ## 🐛 Bug Fixes
30
+
31
+ - Correct optional methods type for protect and catch ([1a161dc](https://github.com/Kings-World/sapphire-plugins/commit/1a161dc3dd96fc1aa6a446cea3e042102d52b56c))
32
+
33
+ # [@kingsworld/plugin-cron@3.0.2](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@3.0.1...@kingsworld/plugin-cron@3.0.2) - (2025-04-07)
34
+
35
+ ## 🐛 Bug Fixes
36
+
37
+ - The protect and catch methods cannot be abstract ([9e230ac](https://github.com/Kings-World/sapphire-plugins/commit/9e230ac9a4df3d76cf50981cd64927cec9f4611e))
38
+
39
+ # [@kingsworld/plugin-cron@3.0.1](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.1.1...@kingsworld/plugin-cron@3.0.1) - (2025-04-07)
40
+
41
+ ## 🏠 Refactor
42
+
43
+ - **cron:** Replace the cron package with croner ([efd4ebb](https://github.com/Kings-World/sapphire-plugins/commit/efd4ebbd2e38f106bc322ffb962c5dcccb503c63)) ([#102](https://github.com/Kings-World/sapphire-plugins/pull/102) by @SerenModz21)
44
+ - 💥 **BREAKING CHANGE:** The `cronTime` option has been replaced with `pattern`.
45
+ - 💥 **BREAKING CHANGE:** The `timeZone` option has been replaced with `timezone`.
46
+ - 💥 **BREAKING CHANGE:** The `cron` package has been replaced with `croner`.
47
+ - 💥 **BREAKING CHANGE:** `container.cron.startAll()` and `container.cron.stopAll()` have been removed. Instead, you should pause and resume using the plugin's store.
48
+ - 💥 **BREAKING CHANGE:** References to the word `cron` have been replaced with `cronTasks` for consistency. For example, `container.cron` is now `container.cronTasks` and `ClientOptions.cron` is now `ClientOptions.cronTasks`.
49
+ - Add the override keyword to the plugin methods ([a581de3](https://github.com/Kings-World/sapphire-plugins/commit/a581de3ae477d1f5fcff5e8376fb7c60fdae7daa))
50
+
5
51
  # [@kingsworld/plugin-cron@2.1.1](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.1.0...@kingsworld/plugin-cron@2.1.1) - (2025-04-05)
6
52
 
7
53
  ## 🐛 Bug Fixes
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ## Description
14
14
 
15
- This plugin adds support for cron tasks to the Sapphire framework. It uses the [cron](ttps://www.npmjs.com/package/@kingsworld/plugin-cron) package to create and manage cron tasks.
15
+ This plugin adds support for cron tasks to the Sapphire framework. It creates and manages cron tasks using the [croner](https://www.npmjs.com/package/croner) package.
16
16
 
17
17
  ## Features
18
18
 
@@ -25,7 +25,7 @@ This plugin adds support for cron tasks to the Sapphire framework. It uses the [
25
25
 
26
26
  - [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework)
27
27
 
28
- You can use the following command to install this package along with `cron`, or replace `npm install` with your package manager of choice.
28
+ You can use the following command to install this package or replace `npm install` with your package manager.
29
29
 
30
30
  ```sh
31
31
  npm install @kingsworld/plugin-cron @sapphire/framework
@@ -63,7 +63,7 @@ const options = {
63
63
 
64
64
  - The `disableSentry` option is used to disable Sentry's cron monitoring. By default, it is set to `false`, which means Sentry cron monitoring is enabled if the `@sentry/node` package is installed and configured. This makes using Sentry an opt-in feature - you first opt in by installing `@sentry/node`. The `disableSentry` option then allows you to opt out in specific situations. You can set this to `true` to disable cron monitoring, which can be useful during development or if you haven't provided a Sentry DSN. If you don't use Sentry at all (i.e., `@sentry/node` is not installed), this option has no effect and can be safely ignored.
65
65
 
66
- In order to use the cron tasks anywhere other than a piece (commands, arguments, preconditions, etc.), you must first import the `container` property of `@sapphire/framework`. From there, you can access the store.
66
+ To use the cron tasks anywhere other than a piece (commands, arguments, preconditions, etc.), you must first import the `container` property of `@sapphire/framework`. From there, you can access the store.
67
67
 
68
68
  This is a simple example of how to pause and resume a task from a service.
69
69
 
@@ -99,7 +99,7 @@ export class MyAwesomeService {
99
99
  }
100
100
  ```
101
101
 
102
- It's important to note that the `startAll()` method is called automatically when the client is ready. Therefore, it's generally not necessary to call this method manually, unless you have a specific need to restart all cron tasks at some point after the client has been initialized.
102
+ It's important to note that the `startAll()` method is called automatically when the client is ready. Therefore, it's generally not necessary to call this method manually unless you have a specific need to restart all cron tasks at some point after the client has been initialized.
103
103
 
104
104
  ### Create a task handler
105
105
 
@@ -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 = "4.0.0-next.efd4ebb";
9
+ var version = "4.0.0-next.ff86fbe";
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\tcronTasks: 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\tcronTasks?: Partial<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 = '4.0.0-next.efd4ebb';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;AA+BO,IAAM,OAAA,GAAkB","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\tcronTasks: 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\tcronTasks?: Partial<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 = '4.0.0-next.ff86fbe';\n"]}
@@ -52,8 +52,8 @@ declare abstract class CronTask<Options extends CronTask.Options = CronTask.Opti
52
52
  job: Cron;
53
53
  constructor(context: CronTask.LoaderContext, options: Options);
54
54
  abstract run(): Awaitable<unknown>;
55
- abstract protect?(job: Cron): Awaitable<unknown>;
56
- abstract catch?(error: unknown, job: Cron): Awaitable<unknown>;
55
+ protect?(job: Cron): Awaitable<unknown>;
56
+ catch?(error: unknown, job: Cron): Awaitable<unknown>;
57
57
  /**
58
58
  * A helper function to log messages with the `CronTask[${name}]` prefix.
59
59
  * @param message The message to include after the prefix
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;;;;;;AAGO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAuBrB,YAAY,OAA2C,EAAA;AAjB9D;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAS,EAAA,eAAA;AAChC,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,KAAA;AAAA;AAEjD,CAAA;AA3B6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.cjs","sourcesContent":["import type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default IANA/TZ timezone to use for all cron jobs.\n\t * You can override this per task, using the timezone option.\n\t * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\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?: Partial<CronTaskHandlerOptions>) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;;;;;;AAGO,IAAM,gBAAA,GAAN,MAAM,gBAAA,CAAgB;AAAA,EAuBrB,YAAY,OAAA,EAA2C;AAjB9D;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,iBAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,eAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,QAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAA,EAAS,eAAA;AAChC,IAAA,IAAA,CAAK,aAAA,GAAgB,SAAS,aAAA,IAAiB,KAAA;AAAA,EAChD;AACD,CAAA;AA3B6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA;AAAtB,IAAM,eAAA,GAAN","file":"CronTaskHandler.cjs","sourcesContent":["import type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default IANA/TZ timezone to use for all cron jobs.\n\t * You can override this per task, using the timezone option.\n\t * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\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?: Partial<CronTaskHandlerOptions>) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"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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;AAAA;AAE3E,CAAA;AAnEyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.cjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { Cron } from 'croner';\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\tpattern: '* * * * *'\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\tdeclare public job: Cron;\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 abstract protect?(job: Cron): Awaitable<unknown>;\n\n\tpublic abstract catch?(error: unknown, job: Cron): 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"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":["Piece"],"mappings":";;;;;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsEA,YAAA,CAA6B;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAA,EAAkB;A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AY,IAAA,CAAK,IAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA,EAAI,GAAG,KAAK,CAAA;AAAA,EAC1E;AACD,CAAA;AAnEyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAA,GAAf","file":"CronTask.cjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { Cron } from 'croner';\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\tpattern: '* * * * *'\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\tdeclare public job: Cron;\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 protect?(job: Cron): Awaitable<unknown>;\n\n\tpublic catch?(error: unknown, job: Cron): 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"]}
@@ -88,22 +88,23 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
88
88
  timezone: timeZone,
89
89
  paused: true,
90
90
  // we start the job manually once the client is ready
91
- protect: value.protect ? (job) => void value.protect(job) : protect,
91
+ protect: value.protect?.bind(value) ?? protect,
92
92
  catch: /* @__PURE__ */ __name((error) => {
93
93
  value.error("Encountered an error while running the cron job", error);
94
- if (sentry) sentry.captureException(error);
95
- void value.catch?.(error, value.job);
94
+ sentry?.captureException(error);
95
+ value.catch?.bind(value)(error, value.job);
96
96
  }, "catch"),
97
97
  ...options
98
98
  },
99
- () => {
99
+ async () => {
100
100
  if (sentry && typeof pattern === "string" && !pattern.includes(":")) {
101
- return sentry.withMonitor(key, () => void value.run.bind(value)(), {
102
- schedule: { type: "crontab", value: pattern },
103
- timezone: timeZone ? normalizePattern_cjs.normalizePattern(timeZone) : void 0
101
+ await sentry.withMonitor(key, value.run.bind(value), {
102
+ schedule: { type: "crontab", value: normalizePattern_cjs.normalizePattern(pattern) },
103
+ timezone: timeZone
104
104
  });
105
+ } else {
106
+ await value.run.bind(value)();
105
107
  }
106
- return value.run.bind(value)();
107
108
  }
108
109
  );
109
110
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":["Store","CronTask","Cron","normalizePattern"],"mappings":";;;;;;;;;AAKO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,YAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAMC,qBAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA;AAAA;AACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAW,GAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAA,IAAI,CAAC,IAAK,CAAA,OAAA,IAAW,CAAC,IAAK,CAAA,GAAA,CAAI,WAAa,EAAA;AAC5C,MAAA,IAAA,CAAK,IAAI,KAAM,EAAA;AAAA;AAGhB,IAAAD,YAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAqC,mCAAA,CAAA,CAAA;AAC1E,IAAO,OAAA,IAAA;AAAA;AACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,SAAY,GAAA;AAClB,IAAW,KAA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A;AAAA;AAGF,UAAA,OAAO,KAAM,CAAA,GAAA,CAAI,IAAK,CAAA,KAAK,CAAE,EAAA;AAAA;AAC9B,OACD;AAAA,aACQ,KAAO,EAAA;AACf,MAAM,KAAA,CAAA,KAAA,CAAM,oDAAoD,KAAK,CAAA;AACrE,MAAA,KAAK,MAAM,MAAO,EAAA;AAAA;AAGnB,IAAO,OAAA,KAAA,CAAM,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA;AAAA;AAC5B;AAAA;AAAA;AAAA,EAKgB,OAAO,GAAa,EAAA;AACnC,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,GAAA,CAAI,GAAG,CAAA;AACzB,IAAA,IAAI,IAAQ,IAAA,CAAC,IAAK,CAAA,GAAA,CAAI,WAAa,EAAA;AAClC,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA;AAAA;AAGf,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA;AACxB;AAAA;AAAA;AAAA,EAKgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA;AAAA;AAErB,CAAA;AA3IiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Cron } from 'croner';\nimport { CronTask } from './CronTask';\nimport { normalizePattern } from '../utils/normalizePattern';\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 pauses those that are running.\n\t *\n\t * @remarks\n\t * This method will only pause tasks that:\n\t * - Are enabled\n\t * - Are currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic pauseAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || !task.job.isRunning()) continue;\n\t\t\ttask.job.pause();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [PAUSE] Paused all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and resumes those that are paused.\n\t *\n\t * @remarks\n\t * This method will only resume tasks that:\n\t * - Are enabled\n\t * - Are not currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic resumeAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isRunning() || task.job.isStopped()) continue;\n\t\t\ttask.job.resume();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [RESUME] Resumed 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 *\n\t * @remarks\n\t * This method will only stop tasks that:\n\t * - Are enabled\n\t * - Have not been permanently stopped\n\t *\n\t * ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isStopped()) 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 { pattern, timezone, protect, ...options } = value.options;\n\t\tconst { sentry, defaultTimezone } = this.container.cronTasks;\n\n\t\t// if a task with the same key already exists, stop it before creating a new one\n\t\tif (this.has(key)) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [SET] Stopping existing cronjob task before creating a new one.`);\n\t\t\tthis.get(key)?.job.stop();\n\t\t}\n\n\t\tconst timeZone = timezone ?? defaultTimezone;\n\n\t\ttry {\n\t\t\tStore.logger?.(\n\t\t\t\t`[STORE => ${this.name}] [SET] Creating cronjob for ${key} with '${pattern}' as the pattern and '${timeZone}' for the timezone`\n\t\t\t);\n\n\t\t\tvalue.job = new Cron(\n\t\t\t\tpattern,\n\t\t\t\t{\n\t\t\t\t\tname: key,\n\t\t\t\t\ttimezone: timeZone,\n\t\t\t\t\tpaused: true, // we start the job manually once the client is ready\n\t\t\t\t\tprotect: value.protect ? (job) => void value.protect!(job) : protect,\n\t\t\t\t\tcatch: (error) => {\n\t\t\t\t\t\tvalue.error('Encountered an error while running the cron job', error);\n\t\t\t\t\t\tif (sentry) sentry.captureException(error);\n\t\t\t\t\t\tvoid value.catch?.(error, value.job);\n\t\t\t\t\t},\n\t\t\t\t\t...options\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\t// we only want to monitor cron patterns and not single-use tasks that croner supports\n\t\t\t\t\tif (sentry && typeof pattern === 'string' && !pattern.includes(':')) {\n\t\t\t\t\t\treturn sentry.withMonitor(key, () => void value.run.bind(value)(), {\n\t\t\t\t\t\t\tschedule: { type: 'crontab', value: pattern },\n\t\t\t\t\t\t\ttimezone: timeZone ? normalizePattern(timeZone) : undefined\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value.run.bind(value)();\n\t\t\t\t}\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\t/**\n\t * Deletes a task from the store and stops it if it's running.\n\t */\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task && !task.job.isStopped()) {\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 */\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":["Store","CronTask","Cron","normalizePattern"],"mappings":";;;;;;;;;AAKO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,YAAA,CAA8B;A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AAA;AAAA;AAAA;AAAA,EAKgB,KAAA,GAAQ;AACvB,IAAA,IAAA,CAAK,OAAA,EAAQ;AACb,IAAA,OAAO,MAAM,KAAA,EAAM;AAAA,EACpB;AACD,CAAA;AA3IiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAA1D,IAAM,aAAA,GAAN","file":"CronTaskStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Cron } from 'croner';\nimport { CronTask } from './CronTask';\nimport { normalizePattern } from '../utils/normalizePattern';\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 pauses those that are running.\n\t *\n\t * @remarks\n\t * This method will only pause tasks that:\n\t * - Are enabled\n\t * - Are currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic pauseAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || !task.job.isRunning()) continue;\n\t\t\ttask.job.pause();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [PAUSE] Paused all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and resumes those that are paused.\n\t *\n\t * @remarks\n\t * This method will only resume tasks that:\n\t * - Are enabled\n\t * - Are not currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic resumeAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isRunning() || task.job.isStopped()) continue;\n\t\t\ttask.job.resume();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [RESUME] Resumed 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 *\n\t * @remarks\n\t * This method will only stop tasks that:\n\t * - Are enabled\n\t * - Have not been permanently stopped\n\t *\n\t * ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isStopped()) 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 { pattern, timezone, protect, ...options } = value.options;\n\t\tconst { sentry, defaultTimezone } = this.container.cronTasks;\n\n\t\t// if a task with the same key already exists, stop it before creating a new one\n\t\tif (this.has(key)) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [SET] Stopping existing cronjob task before creating a new one.`);\n\t\t\tthis.get(key)?.job.stop();\n\t\t}\n\n\t\tconst timeZone = timezone ?? defaultTimezone;\n\n\t\ttry {\n\t\t\tStore.logger?.(\n\t\t\t\t`[STORE => ${this.name}] [SET] Creating cronjob for ${key} with '${pattern}' as the pattern and '${timeZone}' for the timezone`\n\t\t\t);\n\n\t\t\tvalue.job = new Cron(\n\t\t\t\tpattern,\n\t\t\t\t{\n\t\t\t\t\tname: key,\n\t\t\t\t\ttimezone: timeZone,\n\t\t\t\t\tpaused: true, // we start the job manually once the client is ready\n\t\t\t\t\tprotect: value.protect?.bind(value) ?? protect,\n\t\t\t\t\tcatch: (error) => {\n\t\t\t\t\t\tvalue.error('Encountered an error while running the cron job', error);\n\t\t\t\t\t\tsentry?.captureException(error);\n\t\t\t\t\t\tvalue.catch?.bind(value)(error, value.job);\n\t\t\t\t\t},\n\t\t\t\t\t...options\n\t\t\t\t},\n\t\t\t\tasync () => {\n\t\t\t\t\t// we only want to monitor cron patterns and not single-use tasks that croner supports\n\t\t\t\t\tif (sentry && typeof pattern === 'string' && !pattern.includes(':')) {\n\t\t\t\t\t\tawait sentry.withMonitor(key, value.run.bind(value), {\n\t\t\t\t\t\t\tschedule: { type: 'crontab', value: normalizePattern(pattern) },\n\t\t\t\t\t\t\ttimezone: timeZone\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tawait value.run.bind(value)();\n\t\t\t\t\t}\n\t\t\t\t}\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\t/**\n\t * Deletes a task from the store and stops it if it's running.\n\t */\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task && !task.job.isStopped()) {\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 */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/normalizePattern.ts"],"names":[],"mappings":";;;;;;AAMA,IAAM,UAAa,GAAA;AAAA,EAClB,WAAa,EAAA,WAAA;AAAA,EACb,SAAW,EAAA,WAAA;AAAA,EACX,UAAY,EAAA,WAAA;AAAA,EACZ,SAAW,EAAA,WAAA;AAAA,EACX,QAAU,EAAA,WAAA;AAAA,EACV,SAAW,EAAA;AACZ,CAAA;AAEA,IAAM,UAAqC,GAAA;AAAA,EAC1C,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,EAAA;AAAA,EACL,GAAK,EAAA,EAAA;AAAA,EACL,GAAK,EAAA,EAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA;AACN,CAAA;AAEA,IAAM,WAAA,GAAc,IAAI,MAAA,CAAO,MAAO,CAAA,IAAA,CAAK,UAAU,CAAE,CAAA,IAAA,CAAK,GAAG,CAAA,EAAG,GAAG,CAAA;AAE9D,SAAS,iBAAiB,OAAyB,EAAA;AACzD,EAAI,IAAA,OAAA,CAAQ,IAAI,UAAY,EAAA,OAAO,GAAU,OAAA,OAAA,CAAQ,GAAI,CAAA,UAAA,EAAY,OAAO,CAAA;AAC5E,EAAO,OAAA,OAAA,CAAQ,OAAQ,CAAA,WAAA,EAAa,CAAC,KAAA,KAAU,MAAO,CAAA,OAAA,CAAQ,GAAI,CAAA,UAAA,EAAY,KAAK,CAAC,CAAC,CAAA;AACtF;AAHgB,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA","file":"normalizePattern.cjs","sourcesContent":["/*\n * Credits to Sapphire for this\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/constants.ts#L26-L57\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/Cron.ts#L91\n */\n\nconst predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nconst cronTokens: Record<string, number> = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nconst tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n\nexport function normalizePattern(pattern: string): string {\n\tif (Reflect.has(predefined, pattern)) return Reflect.get(predefined, pattern);\n\treturn pattern.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/utils/normalizePattern.ts"],"names":[],"mappings":";;;;;;AAMA,IAAM,UAAA,GAAa;AAAA,EAClB,WAAA,EAAa,WAAA;AAAA,EACb,SAAA,EAAW,WAAA;AAAA,EACX,UAAA,EAAY,WAAA;AAAA,EACZ,SAAA,EAAW,WAAA;AAAA,EACX,QAAA,EAAU,WAAA;AAAA,EACV,SAAA,EAAW;AACZ,CAAA;AAEA,IAAM,UAAA,GAAqC;AAAA,EAC1C,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,EAAA;AAAA,EACL,GAAA,EAAK,EAAA;AAAA,EACL,GAAA,EAAK,EAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK;AACN,CAAA;AAEA,IAAM,WAAA,GAAc,IAAI,MAAA,CAAO,MAAA,CAAO,IAAA,CAAK,UAAU,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA,EAAG,GAAG,CAAA;AAE9D,SAAS,iBAAiB,OAAA,EAAyB;AACzD,EAAA,IAAI,OAAA,CAAQ,IAAI,UAAA,EAAY,OAAO,GAAG,OAAO,OAAA,CAAQ,GAAA,CAAI,UAAA,EAAY,OAAO,CAAA;AAC5E,EAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,WAAA,EAAa,CAAC,KAAA,KAAU,MAAA,CAAO,OAAA,CAAQ,GAAA,CAAI,UAAA,EAAY,KAAK,CAAC,CAAC,CAAA;AACtF;AAHgB,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA","file":"normalizePattern.cjs","sourcesContent":["/*\n * Credits to Sapphire for this\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/constants.ts#L26-L57\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/Cron.ts#L91\n */\n\nconst predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nconst cronTokens: Record<string, number> = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nconst tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n\nexport function normalizePattern(pattern: string): string {\n\tif (Reflect.has(predefined, pattern)) return Reflect.get(predefined, pattern);\n\treturn pattern.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/register.ts"],"names":["Plugin","preGenericsInitialization","container","CronTaskHandler","postInitialization","CronTaskStore","preLogin","postLogin","SapphireClient"],"mappings":";;;;;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuBA,gBAAO,CAAA;AAAA,EAC1C,QAAwBC,mCAAyB,CAAA,CAAwB,OAAwB,EAAA;AAChG,IAAAC,mBAAA,CAAU,SAAY,GAAA,IAAIC,yBAAgB,CAAA,OAAA,CAAQ,SAAS,CAAA;AAAA;AAC5D,EAEA,QAAwBC,4BAAkB,CAAwB,GAAA;AACjE,IAAA,IAAA,CAAK,MAAO,CAAA,QAAA,CAAS,IAAIC,uBAAA,EAAe,CAAA;AAAA;AACzC,EAEA,cAA8BC,kBAAQ,CAAwB,GAAA;AAC7D,IAAI,IAAAJ,mBAAA,CAAU,UAAU,aAAe,EAAA;AACvC,IAAUA,mBAAA,CAAA,SAAA,CAAU,SAAS,MAAM,OAAO,cAAc,CAAE,CAAA,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA;AAChF,EAEA,QAAwBK,mBAAS,CAAwB,GAAA;AACxD,IAAA,IAAA,CAAK,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAE,SAAU,EAAA;AAAA;AAE1C,CAAA;AAjB2C,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApC,IAAM,cAAN,GAAA;AAmBPC,wBAAA,CAAe,OAAQ,CAAA,qCAAA,CAAsC,cAAe,CAAAP,mCAAyB,GAAG,qCAAqC,CAAA;AAE7IO,wBAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,cAAe,CAAAJ,4BAAkB,GAAG,8BAA8B,CAAA;AAExHI,wBAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,cAAe,CAAAF,kBAAQ,GAAG,oBAAoB,CAAA;AAE1FE,wBAAA,CAAe,OAAQ,CAAA,qBAAA,CAAsB,cAAe,CAAAD,mBAAS,GAAG,qBAAqB,CAAA","file":"register.cjs","sourcesContent":["import './index';\n\nimport { container, Plugin, postInitialization, postLogin, preGenericsInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { CronTaskHandler, CronTaskStore } from './index';\n\nexport class CronTaskPlugin extends Plugin {\n\tpublic static override [preGenericsInitialization](this: SapphireClient, options: ClientOptions) {\n\t\tcontainer.cronTasks = new CronTaskHandler(options.cronTasks);\n\t}\n\n\tpublic static override [postInitialization](this: SapphireClient) {\n\t\tthis.stores.register(new CronTaskStore());\n\t}\n\n\tpublic static override async [preLogin](this: SapphireClient) {\n\t\tif (container.cronTasks.disableSentry) return;\n\t\tcontainer.cronTasks.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tthis.stores.get('cron-tasks').resumeAll();\n\t}\n}\n\nSapphireClient.plugins.registerPreGenericsInitializationHook(CronTaskPlugin[preGenericsInitialization], 'Cron-Task-PreGenericsInitialization');\n\nSapphireClient.plugins.registerPostInitializationHook(CronTaskPlugin[postInitialization], 'Cron-Task-PostInitialization');\n\nSapphireClient.plugins.registerPreLoginHook(CronTaskPlugin[preLogin], 'Cron-Task-PreLogin');\n\nSapphireClient.plugins.registerPostLoginHook(CronTaskPlugin[postLogin], 'Cron-Task-PostLogin');\n"]}
1
+ {"version":3,"sources":["../../src/register.ts"],"names":["Plugin","preGenericsInitialization","container","CronTaskHandler","postInitialization","CronTaskStore","preLogin","postLogin","SapphireClient"],"mappings":";;;;;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuBA,gBAAA,CAAO;AAAA,EAC1C,QAAwBC,mCAAyB,CAAA,CAAwB,OAAA,EAAwB;AAChG,IAAAC,mBAAA,CAAU,SAAA,GAAY,IAAIC,yBAAA,CAAgB,OAAA,CAAQ,SAAS,CAAA;AAAA,EAC5D;AAAA,EAEA,QAAwBC,4BAAkB,CAAA,GAAwB;AACjE,IAAA,IAAA,CAAK,MAAA,CAAO,QAAA,CAAS,IAAIC,uBAAA,EAAe,CAAA;AAAA,EACzC;AAAA,EAEA,cAA8BC,kBAAQ,CAAA,GAAwB;AAC7D,IAAA,IAAIJ,mBAAA,CAAU,UAAU,aAAA,EAAe;AACvC,IAAAA,mBAAA,CAAU,SAAA,CAAU,SAAS,MAAM,OAAO,cAAc,CAAA,CAAE,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA,EAChF;AAAA,EAEA,QAAwBK,mBAAS,CAAA,GAAwB;AACxD,IAAA,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,CAAE,SAAA,EAAU;AAAA,EACzC;AACD,CAAA;AAjB2C,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApC,IAAM,cAAA,GAAN;AAmBPC,wBAAA,CAAe,OAAA,CAAQ,qCAAA,CAAsC,cAAA,CAAeP,mCAAyB,GAAG,qCAAqC,CAAA;AAE7IO,wBAAA,CAAe,OAAA,CAAQ,8BAAA,CAA+B,cAAA,CAAeJ,4BAAkB,GAAG,8BAA8B,CAAA;AAExHI,wBAAA,CAAe,OAAA,CAAQ,oBAAA,CAAqB,cAAA,CAAeF,kBAAQ,GAAG,oBAAoB,CAAA;AAE1FE,wBAAA,CAAe,OAAA,CAAQ,qBAAA,CAAsB,cAAA,CAAeD,mBAAS,GAAG,qBAAqB,CAAA","file":"register.cjs","sourcesContent":["import './index';\n\nimport { container, Plugin, postInitialization, postLogin, preGenericsInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { CronTaskHandler, CronTaskStore } from './index';\n\nexport class CronTaskPlugin extends Plugin {\n\tpublic static override [preGenericsInitialization](this: SapphireClient, options: ClientOptions) {\n\t\tcontainer.cronTasks = new CronTaskHandler(options.cronTasks);\n\t}\n\n\tpublic static override [postInitialization](this: SapphireClient) {\n\t\tthis.stores.register(new CronTaskStore());\n\t}\n\n\tpublic static override async [preLogin](this: SapphireClient) {\n\t\tif (container.cronTasks.disableSentry) return;\n\t\tcontainer.cronTasks.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tthis.stores.get('cron-tasks').resumeAll();\n\t}\n}\n\nSapphireClient.plugins.registerPreGenericsInitializationHook(CronTaskPlugin[preGenericsInitialization], 'Cron-Task-PreGenericsInitialization');\n\nSapphireClient.plugins.registerPostInitializationHook(CronTaskPlugin[postInitialization], 'Cron-Task-PostInitialization');\n\nSapphireClient.plugins.registerPreLoginHook(CronTaskPlugin[preLogin], 'Cron-Task-PreLogin');\n\nSapphireClient.plugins.registerPostLoginHook(CronTaskPlugin[postLogin], 'Cron-Task-PostLogin');\n"]}
@@ -52,8 +52,8 @@ declare abstract class CronTask<Options extends CronTask.Options = CronTask.Opti
52
52
  job: Cron;
53
53
  constructor(context: CronTask.LoaderContext, options: Options);
54
54
  abstract run(): Awaitable<unknown>;
55
- abstract protect?(job: Cron): Awaitable<unknown>;
56
- abstract catch?(error: unknown, job: Cron): Awaitable<unknown>;
55
+ protect?(job: Cron): Awaitable<unknown>;
56
+ catch?(error: unknown, job: Cron): Awaitable<unknown>;
57
57
  /**
58
58
  * A helper function to log messages with the `CronTask[${name}]` prefix.
59
59
  * @param message The message to include after the prefix
@@ -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 = "4.0.0-next.efd4ebb";
7
+ var version = "4.0.0-next.ff86fbe";
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\tcronTasks: 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\tcronTasks?: Partial<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 = '4.0.0-next.efd4ebb';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AA+BO,IAAM,OAAA,GAAkB","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\tcronTasks: 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\tcronTasks?: Partial<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 = '4.0.0-next.ff86fbe';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;AAGO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAuBrB,YAAY,OAA2C,EAAA;AAjB9D;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAS,EAAA,eAAA;AAChC,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,KAAA;AAAA;AAEjD,CAAA;AA3B6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.mjs","sourcesContent":["import type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default IANA/TZ timezone to use for all cron jobs.\n\t * You can override this per task, using the timezone option.\n\t * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\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?: Partial<CronTaskHandlerOptions>) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":[],"mappings":";;;AAGO,IAAM,gBAAA,GAAN,MAAM,gBAAA,CAAgB;AAAA,EAuBrB,YAAY,OAAA,EAA2C;AAjB9D;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,iBAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,eAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,QAAA,CAAA;AAGN,IAAA,IAAA,CAAK,kBAAkB,OAAA,EAAS,eAAA;AAChC,IAAA,IAAA,CAAK,aAAA,GAAgB,SAAS,aAAA,IAAiB,KAAA;AAAA,EAChD;AACD,CAAA;AA3B6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA;AAAtB,IAAM,eAAA,GAAN","file":"CronTaskHandler.mjs","sourcesContent":["import type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default IANA/TZ timezone to use for all cron jobs.\n\t * You can override this per task, using the timezone option.\n\t * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\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?: Partial<CronTaskHandlerOptions>) {\n\t\tthis.defaultTimezone = options?.defaultTimezone;\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsE,KAA6B,CAAA;AAAA,EAGjH,WAAA,CA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AAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAE3E,CAAA;AAnEyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.mjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { Cron } from 'croner';\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\tpattern: '* * * * *'\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\tdeclare public job: Cron;\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 abstract protect?(job: Cron): Awaitable<unknown>;\n\n\tpublic abstract catch?(error: unknown, job: Cron): 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"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsE,KAAA,CAA6B;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAA,EAAkB;AACrE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeO,IAAA,CAAK,YAAoB,KAAA,EAAkB;AACjD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CAAA;AAAlH,IAAe,QAAA,GAAf","file":"CronTask.mjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { Cron } from 'croner';\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\tpattern: '* * * * *'\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\tdeclare public job: Cron;\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 protect?(job: Cron): Awaitable<unknown>;\n\n\tpublic catch?(error: unknown, job: Cron): 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"]}
@@ -85,22 +85,23 @@ var _CronTaskStore = class _CronTaskStore extends Store {
85
85
  timezone: timeZone,
86
86
  paused: true,
87
87
  // we start the job manually once the client is ready
88
- protect: value.protect ? (job) => void value.protect(job) : protect,
88
+ protect: value.protect?.bind(value) ?? protect,
89
89
  catch: /* @__PURE__ */ __name((error) => {
90
90
  value.error("Encountered an error while running the cron job", error);
91
- if (sentry) sentry.captureException(error);
92
- void value.catch?.(error, value.job);
91
+ sentry?.captureException(error);
92
+ value.catch?.bind(value)(error, value.job);
93
93
  }, "catch"),
94
94
  ...options
95
95
  },
96
- () => {
96
+ async () => {
97
97
  if (sentry && typeof pattern === "string" && !pattern.includes(":")) {
98
- return sentry.withMonitor(key, () => void value.run.bind(value)(), {
99
- schedule: { type: "crontab", value: pattern },
100
- timezone: timeZone ? normalizePattern(timeZone) : void 0
98
+ await sentry.withMonitor(key, value.run.bind(value), {
99
+ schedule: { type: "crontab", value: normalizePattern(pattern) },
100
+ timezone: timeZone
101
101
  });
102
+ } else {
103
+ await value.run.bind(value)();
102
104
  }
103
- return value.run.bind(value)();
104
105
  }
105
106
  );
106
107
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":[],"mappings":";;;;;;AAKO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,KAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,QAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA;AAAA;AACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAW,GAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAA,IAAI,CAAC,IAAK,CAAA,OAAA,IAAW,CAAC,IAAK,CAAA,GAAA,CAAI,WAAa,EAAA;AAC5C,MAAA,IAAA,CAAK,IAAI,KAAM,EAAA;AAAA;AAGhB,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAqC,mCAAA,CAAA,CAAA;AAC1E,IAAO,OAAA,IAAA;AAAA;AACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,SAAY,GAAA;AAClB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,IAAK,CAAA,OAAA,IAAW,IAAK,CAAA,GAAA,CAAI,WAAe,IAAA,IAAA,CAAK,GAAI,CAAA,SAAA,EAAa,EAAA;AACnE,MAAA,IAAA,CAAK,IAAI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AAAA;AAGnB,IAAO,OAAA,KAAA,CAAM,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA;AAAA;AAC5B;AAAA;AAAA;AAAA,EAKgB,OAAO,GAAa,EAAA;AACnC,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,GAAA,CAAI,GAAG,CAAA;AACzB,IAAA,IAAI,IAAQ,IAAA,CAAC,IAAK,CAAA,GAAA,CAAI,WAAa,EAAA;AAClC,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA;AAAA;AAGf,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA;AACxB;AAAA;AAAA;AAAA,EAKgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA;AAAA;AAErB,CAAA;AA3IiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.mjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Cron } from 'croner';\nimport { CronTask } from './CronTask';\nimport { normalizePattern } from '../utils/normalizePattern';\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 pauses those that are running.\n\t *\n\t * @remarks\n\t * This method will only pause tasks that:\n\t * - Are enabled\n\t * - Are currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic pauseAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || !task.job.isRunning()) continue;\n\t\t\ttask.job.pause();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [PAUSE] Paused all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and resumes those that are paused.\n\t *\n\t * @remarks\n\t * This method will only resume tasks that:\n\t * - Are enabled\n\t * - Are not currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic resumeAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isRunning() || task.job.isStopped()) continue;\n\t\t\ttask.job.resume();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [RESUME] Resumed 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 *\n\t * @remarks\n\t * This method will only stop tasks that:\n\t * - Are enabled\n\t * - Have not been permanently stopped\n\t *\n\t * ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isStopped()) 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 { pattern, timezone, protect, ...options } = value.options;\n\t\tconst { sentry, defaultTimezone } = this.container.cronTasks;\n\n\t\t// if a task with the same key already exists, stop it before creating a new one\n\t\tif (this.has(key)) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [SET] Stopping existing cronjob task before creating a new one.`);\n\t\t\tthis.get(key)?.job.stop();\n\t\t}\n\n\t\tconst timeZone = timezone ?? defaultTimezone;\n\n\t\ttry {\n\t\t\tStore.logger?.(\n\t\t\t\t`[STORE => ${this.name}] [SET] Creating cronjob for ${key} with '${pattern}' as the pattern and '${timeZone}' for the timezone`\n\t\t\t);\n\n\t\t\tvalue.job = new Cron(\n\t\t\t\tpattern,\n\t\t\t\t{\n\t\t\t\t\tname: key,\n\t\t\t\t\ttimezone: timeZone,\n\t\t\t\t\tpaused: true, // we start the job manually once the client is ready\n\t\t\t\t\tprotect: value.protect ? (job) => void value.protect!(job) : protect,\n\t\t\t\t\tcatch: (error) => {\n\t\t\t\t\t\tvalue.error('Encountered an error while running the cron job', error);\n\t\t\t\t\t\tif (sentry) sentry.captureException(error);\n\t\t\t\t\t\tvoid value.catch?.(error, value.job);\n\t\t\t\t\t},\n\t\t\t\t\t...options\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\t// we only want to monitor cron patterns and not single-use tasks that croner supports\n\t\t\t\t\tif (sentry && typeof pattern === 'string' && !pattern.includes(':')) {\n\t\t\t\t\t\treturn sentry.withMonitor(key, () => void value.run.bind(value)(), {\n\t\t\t\t\t\t\tschedule: { type: 'crontab', value: pattern },\n\t\t\t\t\t\t\ttimezone: timeZone ? normalizePattern(timeZone) : undefined\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value.run.bind(value)();\n\t\t\t\t}\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\t/**\n\t * Deletes a task from the store and stops it if it's running.\n\t */\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task && !task.job.isStopped()) {\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 */\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":";;;;;;AAKO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,KAAA,CAA8B;AAAA,EACzD,WAAA,GAAc;AACpB,IAAA,KAAA,CAAM,QAAA,EAAU,EAAE,IAAA,EAAM,YAAA,EAAc,CAAA;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAA,GAAW;AACjB,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,C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ieces';\nimport { Cron } from 'croner';\nimport { CronTask } from './CronTask';\nimport { normalizePattern } from '../utils/normalizePattern';\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 pauses those that are running.\n\t *\n\t * @remarks\n\t * This method will only pause tasks that:\n\t * - Are enabled\n\t * - Are currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic pauseAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || !task.job.isRunning()) continue;\n\t\t\ttask.job.pause();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [PAUSE] Paused all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and resumes those that are paused.\n\t *\n\t * @remarks\n\t * This method will only resume tasks that:\n\t * - Are enabled\n\t * - Are not currently running\n\t * - Have not been permanently stopped\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic resumeAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isRunning() || task.job.isStopped()) continue;\n\t\t\ttask.job.resume();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [RESUME] Resumed 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 *\n\t * @remarks\n\t * This method will only stop tasks that:\n\t * - Are enabled\n\t * - Have not been permanently stopped\n\t *\n\t * ⚠️ Stopping jobs is **permanent** and cannot be resumed afterwards!\n\t *\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled || task.job.isStopped()) 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 { pattern, timezone, protect, ...options } = value.options;\n\t\tconst { sentry, defaultTimezone } = this.container.cronTasks;\n\n\t\t// if a task with the same key already exists, stop it before creating a new one\n\t\tif (this.has(key)) {\n\t\t\tStore.logger?.(`[STORE => ${this.name}] [SET] Stopping existing cronjob task before creating a new one.`);\n\t\t\tthis.get(key)?.job.stop();\n\t\t}\n\n\t\tconst timeZone = timezone ?? defaultTimezone;\n\n\t\ttry {\n\t\t\tStore.logger?.(\n\t\t\t\t`[STORE => ${this.name}] [SET] Creating cronjob for ${key} with '${pattern}' as the pattern and '${timeZone}' for the timezone`\n\t\t\t);\n\n\t\t\tvalue.job = new Cron(\n\t\t\t\tpattern,\n\t\t\t\t{\n\t\t\t\t\tname: key,\n\t\t\t\t\ttimezone: timeZone,\n\t\t\t\t\tpaused: true, // we start the job manually once the client is ready\n\t\t\t\t\tprotect: value.protect?.bind(value) ?? protect,\n\t\t\t\t\tcatch: (error) => {\n\t\t\t\t\t\tvalue.error('Encountered an error while running the cron job', error);\n\t\t\t\t\t\tsentry?.captureException(error);\n\t\t\t\t\t\tvalue.catch?.bind(value)(error, value.job);\n\t\t\t\t\t},\n\t\t\t\t\t...options\n\t\t\t\t},\n\t\t\t\tasync () => {\n\t\t\t\t\t// we only want to monitor cron patterns and not single-use tasks that croner supports\n\t\t\t\t\tif (sentry && typeof pattern === 'string' && !pattern.includes(':')) {\n\t\t\t\t\t\tawait sentry.withMonitor(key, value.run.bind(value), {\n\t\t\t\t\t\t\tschedule: { type: 'crontab', value: normalizePattern(pattern) },\n\t\t\t\t\t\t\ttimezone: timeZone\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tawait value.run.bind(value)();\n\t\t\t\t\t}\n\t\t\t\t}\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\t/**\n\t * Deletes a task from the store and stops it if it's running.\n\t */\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task && !task.job.isStopped()) {\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 */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/normalizePattern.ts"],"names":[],"mappings":";;;AAMA,IAAM,UAAa,GAAA;AAAA,EAClB,WAAa,EAAA,WAAA;AAAA,EACb,SAAW,EAAA,WAAA;AAAA,EACX,UAAY,EAAA,WAAA;AAAA,EACZ,SAAW,EAAA,WAAA;AAAA,EACX,QAAU,EAAA,WAAA;AAAA,EACV,SAAW,EAAA;AACZ,CAAA;AAEA,IAAM,UAAqC,GAAA;AAAA,EAC1C,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,EAAA;AAAA,EACL,GAAK,EAAA,EAAA;AAAA,EACL,GAAK,EAAA,EAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA,CAAA;AAAA,EACL,GAAK,EAAA;AACN,CAAA;AAEA,IAAM,WAAA,GAAc,IAAI,MAAA,CAAO,MAAO,CAAA,IAAA,CAAK,UAAU,CAAE,CAAA,IAAA,CAAK,GAAG,CAAA,EAAG,GAAG,CAAA;AAE9D,SAAS,iBAAiB,OAAyB,EAAA;AACzD,EAAI,IAAA,OAAA,CAAQ,IAAI,UAAY,EAAA,OAAO,GAAU,OAAA,OAAA,CAAQ,GAAI,CAAA,UAAA,EAAY,OAAO,CAAA;AAC5E,EAAO,OAAA,OAAA,CAAQ,OAAQ,CAAA,WAAA,EAAa,CAAC,KAAA,KAAU,MAAO,CAAA,OAAA,CAAQ,GAAI,CAAA,UAAA,EAAY,KAAK,CAAC,CAAC,CAAA;AACtF;AAHgB,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA","file":"normalizePattern.mjs","sourcesContent":["/*\n * Credits to Sapphire for this\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/constants.ts#L26-L57\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/Cron.ts#L91\n */\n\nconst predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nconst cronTokens: Record<string, number> = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nconst tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n\nexport function normalizePattern(pattern: string): string {\n\tif (Reflect.has(predefined, pattern)) return Reflect.get(predefined, pattern);\n\treturn pattern.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/utils/normalizePattern.ts"],"names":[],"mappings":";;;AAMA,IAAM,UAAA,GAAa;AAAA,EAClB,WAAA,EAAa,WAAA;AAAA,EAC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\n * Credits to Sapphire for this\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/constants.ts#L26-L57\n * https://github.com/sapphiredev/utilities/blob/main/packages/cron/src/lib/Cron.ts#L91\n */\n\nconst predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nconst cronTokens: Record<string, number> = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nconst tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n\nexport function normalizePattern(pattern: string): string {\n\tif (Reflect.has(predefined, pattern)) return Reflect.get(predefined, pattern);\n\treturn pattern.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuB,MAAO,CAAA;AAAA,EAC1C,QAAwB,yBAAyB,CAAA,CAAwB,OAAwB,EAAA;AAChG,IAAA,SAAA,CAAU,SAAY,GAAA,IAAI,eAAgB,CAAA,OAAA,CAAQ,SAAS,CAAA;AAAA;AAC5D,EAEA,QAAwB,kBAAkB,CAAwB,GAAA;AACjE,IAAA,IAAA,CAAK,MAAO,CAAA,QAAA,CAAS,IAAI,aAAA,EAAe,CAAA;AAAA;AACzC,EAEA,cAA8B,QAAQ,CAAwB,GAAA;AAC7D,IAAI,IAAA,SAAA,CAAU,UAAU,aAAe,EAAA;AACvC,IAAU,SAAA,CAAA,SAAA,CAAU,SAAS,MAAM,OAAO,cAAc,CAAE,CAAA,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA;AAChF,EAEA,QAAwB,SAAS,CAAwB,GAAA;AACxD,IAAA,IAAA,CAAK,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAE,SAAU,EAAA;AAAA;AAE1C,CAAA;AAjB2C,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApC,IAAM,cAAN,GAAA;AAmBP,cAAA,CAAe,OAAQ,CAAA,qCAAA,CAAsC,cAAe,CAAA,yBAAyB,GAAG,qCAAqC,CAAA;AAE7I,cAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,cAAe,CAAA,kBAAkB,GAAG,8BAA8B,CAAA;AAExH,cAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,cAAe,CAAA,QAAQ,GAAG,oBAAoB,CAAA;AAE1F,cAAA,CAAe,OAAQ,CAAA,qBAAA,CAAsB,cAAe,CAAA,SAAS,GAAG,qBAAqB,CAAA","file":"register.mjs","sourcesContent":["import './index';\n\nimport { container, Plugin, postInitialization, postLogin, preGenericsInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { CronTaskHandler, CronTaskStore } from './index';\n\nexport class CronTaskPlugin extends Plugin {\n\tpublic static override [preGenericsInitialization](this: SapphireClient, options: ClientOptions) {\n\t\tcontainer.cronTasks = new CronTaskHandler(options.cronTasks);\n\t}\n\n\tpublic static override [postInitialization](this: SapphireClient) {\n\t\tthis.stores.register(new CronTaskStore());\n\t}\n\n\tpublic static override async [preLogin](this: SapphireClient) {\n\t\tif (container.cronTasks.disableSentry) return;\n\t\tcontainer.cronTasks.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tthis.stores.get('cron-tasks').resumeAll();\n\t}\n}\n\nSapphireClient.plugins.registerPreGenericsInitializationHook(CronTaskPlugin[preGenericsInitialization], 'Cron-Task-PreGenericsInitialization');\n\nSapphireClient.plugins.registerPostInitializationHook(CronTaskPlugin[postInitialization], 'Cron-Task-PostInitialization');\n\nSapphireClient.plugins.registerPreLoginHook(CronTaskPlugin[preLogin], 'Cron-Task-PreLogin');\n\nSapphireClient.plugins.registerPostLoginHook(CronTaskPlugin[postLogin], 'Cron-Task-PostLogin');\n"]}
1
+ {"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuB,MAAA,CAAO;AAAA,EAC1C,QAAwB,yBAAyB,CAAA,CAAwB,OAAA,EAAwB;AAChG,IAAA,SAAA,CAAU,SAAA,GAAY,IAAI,eAAA,CAAgB,OAAA,CAAQ,SAAS,CAAA;AAAA,EAC5D;AAAA,EAEA,QAAwB,kBAAkB,CAAA,GAAwB;AACjE,IAAA,IAAA,CAAK,MAAA,CAAO,QAAA,CAAS,IAAI,aAAA,EAAe,CAAA;AAAA,EACzC;AAAA,EAEA,cAA8B,QAAQ,CAAA,GAAwB;AAC7D,IAAA,IAAI,SAAA,CAAU,UAAU,aAAA,EAAe;AACvC,IAAA,SAAA,CAAU,SAAA,CAAU,SAAS,MAAM,OAAO,cAAc,CAAA,CAAE,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA,EAChF;AAAA,EAEA,QAAwB,SAAS,CAAA,GAAwB;AACxD,IAAA,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,CAAE,SAAA,EAAU;AAAA,EACzC;AACD,CAAA;AAjB2C,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApC,IAAM,cAAA,GAAN;AAmBP,cAAA,CAAe,OAAA,CAAQ,qCAAA,CAAsC,cAAA,CAAe,yBAAyB,GAAG,qCAAqC,CAAA;AAE7I,cAAA,CAAe,OAAA,CAAQ,8BAAA,CAA+B,cAAA,CAAe,kBAAkB,GAAG,8BAA8B,CAAA;AAExH,cAAA,CAAe,OAAA,CAAQ,oBAAA,CAAqB,cAAA,CAAe,QAAQ,GAAG,oBAAoB,CAAA;AAE1F,cAAA,CAAe,OAAA,CAAQ,qBAAA,CAAsB,cAAA,CAAe,SAAS,GAAG,qBAAqB,CAAA","file":"register.mjs","sourcesContent":["import './index';\n\nimport { container, Plugin, postInitialization, postLogin, preGenericsInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { CronTaskHandler, CronTaskStore } from './index';\n\nexport class CronTaskPlugin extends Plugin {\n\tpublic static override [preGenericsInitialization](this: SapphireClient, options: ClientOptions) {\n\t\tcontainer.cronTasks = new CronTaskHandler(options.cronTasks);\n\t}\n\n\tpublic static override [postInitialization](this: SapphireClient) {\n\t\tthis.stores.register(new CronTaskStore());\n\t}\n\n\tpublic static override async [preLogin](this: SapphireClient) {\n\t\tif (container.cronTasks.disableSentry) return;\n\t\tcontainer.cronTasks.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tthis.stores.get('cron-tasks').resumeAll();\n\t}\n}\n\nSapphireClient.plugins.registerPreGenericsInitializationHook(CronTaskPlugin[preGenericsInitialization], 'Cron-Task-PreGenericsInitialization');\n\nSapphireClient.plugins.registerPostInitializationHook(CronTaskPlugin[postInitialization], 'Cron-Task-PostInitialization');\n\nSapphireClient.plugins.registerPreLoginHook(CronTaskPlugin[preLogin], 'Cron-Task-PreLogin');\n\nSapphireClient.plugins.registerPostLoginHook(CronTaskPlugin[postLogin], 'Cron-Task-PostLogin');\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingsworld/plugin-cron",
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": "4.0.0-next.efd4ebb",
3
+ "description": "A simple @sapphire/framework plugin that aims to make use of the croner package and allow users to make cron jobs within their Sapphire discord bot.",
4
+ "version": "4.0.0-next.ff86fbe",
5
5
  "author": "Seren_Modz 21 <seren@kings-world.net>",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.cjs",
@@ -46,17 +46,17 @@
46
46
  "check-update": "cliff-jumper --dry-run"
47
47
  },
48
48
  "dependencies": {
49
- "croner": "^9.0.0"
49
+ "croner": "^10.0.1"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@favware/cliff-jumper": "^6.0.0",
53
53
  "@favware/rollup-type-bundler": "^4.0.0",
54
- "@sentry/node": "^9.11.0",
55
- "@types/node": "^22.14.0",
56
- "concurrently": "^9.1.2",
57
- "tsup": "^8.4.0",
58
- "tsx": "^4.19.3",
59
- "typescript": "~5.4.5"
54
+ "@sentry/node": "^10.47.0",
55
+ "@types/node": "^24.12.0",
56
+ "concurrently": "^9.2.1",
57
+ "tsup": "^8.5.1",
58
+ "tsx": "^4.21.0",
59
+ "typescript": "^5.9.3"
60
60
  },
61
61
  "homepage": "https://github.com/Kings-World/sapphire-plugins",
62
62
  "repository": {
@@ -68,6 +68,7 @@
68
68
  "sapphire",
69
69
  "plugin",
70
70
  "cron",
71
+ "croner",
71
72
  "typescript",
72
73
  "ts",
73
74
  "discord",